~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/http/public/counting_url_async_fetcher.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: jmarantz@google.com (Joshua Marantz)
18
 
//
19
 
// Wraps an asynchronous fetcher, but keeps track of success/failure count.
20
 
 
21
 
#ifndef NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_
22
 
#define NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_
23
 
 
24
 
#include "net/instaweb/http/public/url_async_fetcher.h"
25
 
#include "net/instaweb/util/public/basictypes.h"
26
 
#include "net/instaweb/util/public/platform.h"
27
 
#include "net/instaweb/util/public/scoped_ptr.h"
28
 
#include "net/instaweb/util/public/string.h"
29
 
#include "net/instaweb/util/public/thread_system.h"
30
 
 
31
 
namespace net_instaweb {
32
 
 
33
 
class AsyncFetch;
34
 
class MessageHandler;
35
 
 
36
 
class CountingUrlAsyncFetcher : public UrlAsyncFetcher {
37
 
 public:
38
 
  // TODO(hujie): We should pass in the mutex at all call-sites instead of
39
 
  //     creating a new mutex here.
40
 
  explicit CountingUrlAsyncFetcher(UrlAsyncFetcher* fetcher)
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
 
 
56
 
  // number of completed fetches.
57
 
  int fetch_count() const {
58
 
    ScopedMutex lock(mutex_.get());
59
 
    return fetch_count_;
60
 
  }
61
 
 
62
 
  // number of started fetches
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_;  // Thread system for mutex.
93
 
  scoped_ptr<AbstractMutex> mutex_;         // Mutex Protect.
94
 
 
95
 
  DISALLOW_COPY_AND_ASSIGN(CountingUrlAsyncFetcher);
96
 
};
97
 
 
98
 
}  // namespace net_instaweb
99
 
 
100
 
#endif  // NET_INSTAWEB_HTTP_PUBLIC_COUNTING_URL_ASYNC_FETCHER_H_