| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains URLFetcher, a wrapper around net::URLRequest that handles | 5 // This file contains URLFetcher, a wrapper around net::URLRequest that handles |
| 6 // low-level details like thread safety, ref counting, and incremental buffer | 6 // low-level details like thread safety, ref counting, and incremental buffer |
| 7 // reading. This is useful for callers who simply want to get the data from a | 7 // reading. This is useful for callers who simply want to get the data from a |
| 8 // URL and don't care about all the nitty-gritty details. | 8 // URL and don't care about all the nitty-gritty details. |
| 9 // | 9 // |
| 10 // NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a | 10 // NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a |
| 11 // temporary situation. We will work on allowing support for multiple "io" | 11 // temporary situation. We will work on allowing support for multiple "io" |
| 12 // threads per process. | 12 // threads per process. |
| 13 | 13 |
| 14 #ifndef CONTENT_COMMON_URL_FETCHER_H_ | 14 #ifndef CONTENT_COMMON_URL_FETCHER_H_ |
| 15 #define CONTENT_COMMON_URL_FETCHER_H_ | 15 #define CONTENT_COMMON_URL_FETCHER_H_ |
| 16 #pragma once | 16 #pragma once |
| 17 | 17 |
| 18 #include <string> | 18 #include <string> |
| 19 #include <vector> | 19 #include <vector> |
| 20 | 20 |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
| 23 #include "base/platform_file.h" | 23 #include "base/platform_file.h" |
| 24 #include "base/time.h" | 24 #include "base/time.h" |
| 25 #include "content/common/content_export.h" |
| 25 | 26 |
| 26 class FilePath; | 27 class FilePath; |
| 27 class GURL; | 28 class GURL; |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 class MessageLoopProxy; | 31 class MessageLoopProxy; |
| 31 } // namespace base | 32 } // namespace base |
| 32 | 33 |
| 33 namespace net { | 34 namespace net { |
| 34 class HostPortPair; | 35 class HostPortPair; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 61 // before the callback happens, the fetch will be canceled and no callback | 62 // before the callback happens, the fetch will be canceled and no callback |
| 62 // will occur. | 63 // will occur. |
| 63 // | 64 // |
| 64 // You may create the URLFetcher instance on any thread; OnURLFetchComplete() | 65 // You may create the URLFetcher instance on any thread; OnURLFetchComplete() |
| 65 // will be called back on the same thread you use to create the instance. | 66 // will be called back on the same thread you use to create the instance. |
| 66 // | 67 // |
| 67 // | 68 // |
| 68 // NOTE: By default URLFetcher requests are NOT intercepted, except when | 69 // NOTE: By default URLFetcher requests are NOT intercepted, except when |
| 69 // interception is explicitly enabled in tests. | 70 // interception is explicitly enabled in tests. |
| 70 | 71 |
| 71 class URLFetcher { | 72 class CONTENT_EXPORT URLFetcher { |
| 72 public: | 73 public: |
| 73 enum RequestType { | 74 enum RequestType { |
| 74 GET, | 75 GET, |
| 75 POST, | 76 POST, |
| 76 HEAD, | 77 HEAD, |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 // Imposible http response code. Used to signal that no http response code | 80 // Imposible http response code. Used to signal that no http response code |
| 80 // was received. | 81 // was received. |
| 81 static const int kInvalidHttpResponseCode; | 82 static const int kInvalidHttpResponseCode; |
| 82 | 83 |
| 83 class Delegate { | 84 class CONTENT_EXPORT Delegate { |
| 84 public: | 85 public: |
| 85 // TODO(skerner): This will be removed in favor of the |source|-only | 86 // TODO(skerner): This will be removed in favor of the |source|-only |
| 86 // version below. Leaving this for now to make the initial code review | 87 // version below. Leaving this for now to make the initial code review |
| 87 // easy to read. | 88 // easy to read. |
| 88 virtual void OnURLFetchComplete(const URLFetcher* source, | 89 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 89 const GURL& url, | 90 const GURL& url, |
| 90 const net::URLRequestStatus& status, | 91 const net::URLRequestStatus& status, |
| 91 int response_code, | 92 int response_code, |
| 92 const net::ResponseCookies& cookies, | 93 const net::ResponseCookies& cookies, |
| 93 const std::string& data); | 94 const std::string& data); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 315 |
| 315 // Back-off time delay. 0 by default. | 316 // Back-off time delay. 0 by default. |
| 316 base::TimeDelta backoff_delay_; | 317 base::TimeDelta backoff_delay_; |
| 317 | 318 |
| 318 static bool g_interception_enabled; | 319 static bool g_interception_enabled; |
| 319 | 320 |
| 320 DISALLOW_COPY_AND_ASSIGN(URLFetcher); | 321 DISALLOW_COPY_AND_ASSIGN(URLFetcher); |
| 321 }; | 322 }; |
| 322 | 323 |
| 323 #endif // CONTENT_COMMON_URL_FETCHER_H_ | 324 #endif // CONTENT_COMMON_URL_FETCHER_H_ |
| OLD | NEW |