| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ | 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ |
| 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ | 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <list> | 10 #include <list> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| 19 #include "net/url_request/url_fetcher_delegate.h" | 20 #include "net/url_request/url_fetcher_delegate.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 class PrecacheFetcher::Fetcher : public net::URLFetcherDelegate { | 165 class PrecacheFetcher::Fetcher : public net::URLFetcherDelegate { |
| 165 public: | 166 public: |
| 166 // Construct a new Fetcher. This will create and start a new URLFetcher for | 167 // Construct a new Fetcher. This will create and start a new URLFetcher for |
| 167 // the specified URL using the specified request context. | 168 // the specified URL using the specified request context. |
| 168 Fetcher(net::URLRequestContextGetter* request_context, | 169 Fetcher(net::URLRequestContextGetter* request_context, |
| 169 const GURL& url, | 170 const GURL& url, |
| 170 const base::Callback<void(const net::URLFetcher&)>& callback, | 171 const base::Callback<void(const net::URLFetcher&)>& callback, |
| 171 bool is_resource_request); | 172 bool is_resource_request); |
| 172 ~Fetcher() override; | 173 ~Fetcher() override; |
| 173 void OnURLFetchComplete(const net::URLFetcher* source) override; | 174 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 174 int64 response_bytes() const { return response_bytes_; } | 175 int64_t response_bytes() const { return response_bytes_; } |
| 175 int64 network_response_bytes() const { return network_response_bytes_; } | 176 int64_t network_response_bytes() const { return network_response_bytes_; } |
| 176 | 177 |
| 177 private: | 178 private: |
| 178 enum class FetchStage { CACHE, NETWORK }; | 179 enum class FetchStage { CACHE, NETWORK }; |
| 179 | 180 |
| 180 void LoadFromCache(); | 181 void LoadFromCache(); |
| 181 void LoadFromNetwork(); | 182 void LoadFromNetwork(); |
| 182 | 183 |
| 183 net::URLRequestContextGetter* const request_context_; | 184 net::URLRequestContextGetter* const request_context_; |
| 184 const GURL url_; | 185 const GURL url_; |
| 185 const base::Callback<void(const net::URLFetcher&)> callback_; | 186 const base::Callback<void(const net::URLFetcher&)> callback_; |
| 186 const bool is_resource_request_; | 187 const bool is_resource_request_; |
| 187 | 188 |
| 188 FetchStage fetch_stage_; | 189 FetchStage fetch_stage_; |
| 189 // The url_fetcher_cache_ is kept alive until Fetcher destruction for testing. | 190 // The url_fetcher_cache_ is kept alive until Fetcher destruction for testing. |
| 190 scoped_ptr<net::URLFetcher> url_fetcher_cache_; | 191 scoped_ptr<net::URLFetcher> url_fetcher_cache_; |
| 191 scoped_ptr<net::URLFetcher> url_fetcher_network_; | 192 scoped_ptr<net::URLFetcher> url_fetcher_network_; |
| 192 int64 response_bytes_; | 193 int64_t response_bytes_; |
| 193 int64 network_response_bytes_; | 194 int64_t network_response_bytes_; |
| 194 | 195 |
| 195 DISALLOW_COPY_AND_ASSIGN(Fetcher); | 196 DISALLOW_COPY_AND_ASSIGN(Fetcher); |
| 196 }; | 197 }; |
| 197 | 198 |
| 198 } // namespace precache | 199 } // namespace precache |
| 199 | 200 |
| 200 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ | 201 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_FETCHER_H_ |
| OLD | NEW |