Page Speed Optimization Libraries  1.6.29.3
net/instaweb/http/public/counting_url_async_fetcher.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00020 
00021 #ifndef NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_
00022 #define NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_
00023 
00024 #include "net/instaweb/http/public/url_async_fetcher.h"
00025 #include "net/instaweb/util/public/basictypes.h"
00026 #include "net/instaweb/util/public/platform.h"
00027 #include "net/instaweb/util/public/scoped_ptr.h"
00028 #include "net/instaweb/util/public/string.h"
00029 #include "net/instaweb/util/public/thread_system.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class AsyncFetch;
00034 class MessageHandler;
00035 
00036 class CountingUrlAsyncFetcher : public UrlAsyncFetcher {
00037  public:
00040   explicit CountingUrlAsyncFetcher(UrlAsyncFetcher* fetcher)
00041       : fetcher_(fetcher),
00042         thread_system_(Platform::CreateThreadSystem()),
00043         mutex_(thread_system_->NewMutex()) {
00044     Clear();
00045   }
00046   virtual ~CountingUrlAsyncFetcher();
00047 
00048   void set_fetcher(UrlAsyncFetcher* fetcher) { fetcher_ = fetcher; }
00049 
00050   virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); }
00051 
00052   virtual void Fetch(const GoogleString& url,
00053                      MessageHandler* message_handler,
00054                      AsyncFetch* fetch);
00055 
00057   int fetch_count() const {
00058     ScopedMutex lock(mutex_.get());
00059     return fetch_count_;
00060   }
00061 
00063   int fetch_start_count() const {
00064     ScopedMutex lock(mutex_.get());
00065     return fetch_start_count_;
00066   }
00067   int byte_count() const {
00068     ScopedMutex lock(mutex_.get());
00069     return byte_count_;
00070   }
00071   int failure_count() const {
00072     ScopedMutex lock(mutex_.get());
00073     return failure_count_;
00074   }
00075   GoogleString most_recent_fetched_url() const {
00076     ScopedMutex lock(mutex_.get());
00077     return most_recent_fetched_url_;
00078   }
00079 
00080   void Clear();
00081 
00082   class CountingFetch;
00083   friend class CountingFetch;
00084 
00085  private:
00086   UrlAsyncFetcher* fetcher_;
00087   int fetch_count_;
00088   int fetch_start_count_;
00089   int byte_count_;
00090   int failure_count_;
00091   GoogleString most_recent_fetched_url_;
00092   scoped_ptr<ThreadSystem> thread_system_; 
00093   scoped_ptr<AbstractMutex> mutex_; 
00094 
00095   DISALLOW_COPY_AND_ASSIGN(CountingUrlAsyncFetcher);
00096 };
00097 
00098 }  
00099 
00100 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines