Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
counting_url_async_fetcher.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
20 
21 #ifndef NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_
22 #define NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_
23 
29 #include "pagespeed/kernel/util/platform.h"
30 
31 namespace net_instaweb {
32 
33 class AsyncFetch;
34 class MessageHandler;
35 
37  public:
41  : fetcher_(fetcher),
42  thread_system_(Platform::CreateThreadSystem()),
43  mutex_(thread_system_->NewMutex()) {
44  Clear();
45  }
46  virtual ~CountingUrlAsyncFetcher();
47 
48  void set_fetcher(UrlAsyncFetcher* fetcher) { fetcher_ = fetcher; }
49 
50  virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); }
51 
52  virtual void Fetch(const GoogleString& url,
53  MessageHandler* message_handler,
54  AsyncFetch* fetch);
55 
57  int fetch_count() const {
58  ScopedMutex lock(mutex_.get());
59  return fetch_count_;
60  }
61 
63  int fetch_start_count() const {
64  ScopedMutex lock(mutex_.get());
65  return fetch_start_count_;
66  }
67  int byte_count() const {
68  ScopedMutex lock(mutex_.get());
69  return byte_count_;
70  }
71  int failure_count() const {
72  ScopedMutex lock(mutex_.get());
73  return failure_count_;
74  }
75  GoogleString most_recent_fetched_url() const {
76  ScopedMutex lock(mutex_.get());
77  return most_recent_fetched_url_;
78  }
79 
80  void Clear();
81 
82  class CountingFetch;
83  friend class CountingFetch;
84 
85  private:
86  UrlAsyncFetcher* fetcher_;
87  int fetch_count_;
88  int fetch_start_count_;
89  int byte_count_;
90  int failure_count_;
91  GoogleString most_recent_fetched_url_;
92  scoped_ptr<ThreadSystem> thread_system_;
93  scoped_ptr<AbstractMutex> mutex_;
94 
95 
96 };
97 
98 }
99 
100 #endif
Definition: counting_url_async_fetcher.h:36
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
int fetch_count() const
number of completed fetches.
Definition: counting_url_async_fetcher.h:57
#define ScopedMutex(x)
Definition: abstract_mutex.h:69
Helper class for lexically scoped mutexing.
Definition: abstract_mutex.h:46
Definition: async_fetch.h:53
int fetch_start_count() const
number of started fetches
Definition: counting_url_async_fetcher.h:63
virtual void Fetch(const GoogleString &url, MessageHandler *message_handler, AsyncFetch *fetch)
Definition: platform.h:27
Definition: message_handler.h:39
UrlAsyncFetcher()
Definition: url_async_fetcher.h:78
virtual bool SupportsHttps() const
Definition: url_async_fetcher.h:54
virtual bool SupportsHttps() const
Definition: counting_url_async_fetcher.h:50
CountingUrlAsyncFetcher(UrlAsyncFetcher *fetcher)
Definition: counting_url_async_fetcher.h:40
Definition: url_async_fetcher.h:33