OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_COMMON_NET_URL_FETCHER_CORE_H_ | 5 #ifndef CONTENT_COMMON_NET_URL_FETCHER_CORE_H_ |
6 #define CONTENT_COMMON_NET_URL_FETCHER_CORE_H_ | 6 #define CONTENT_COMMON_NET_URL_FETCHER_CORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
28 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
29 | 29 |
30 namespace base { | 30 namespace base { |
31 class MessageLoopProxy; | 31 class MessageLoopProxy; |
32 } // namespace base | 32 } // namespace base |
33 | 33 |
34 namespace net { | 34 namespace net { |
35 class HttpResponseHeaders; | 35 class HttpResponseHeaders; |
36 class IOBuffer; | 36 class IOBuffer; |
| 37 class URLFetcherDelegate; |
37 class URLRequestContextGetter; | 38 class URLRequestContextGetter; |
38 class URLRequestThrottlerEntryInterface; | 39 class URLRequestThrottlerEntryInterface; |
39 } // namespace net | 40 } // namespace net |
40 | 41 |
41 namespace content { | 42 namespace content { |
42 | 43 |
43 class URLFetcherDelegate; | |
44 | |
45 class URLFetcherCore | 44 class URLFetcherCore |
46 : public base::RefCountedThreadSafe<URLFetcherCore>, | 45 : public base::RefCountedThreadSafe<URLFetcherCore>, |
47 public net::URLRequest::Delegate { | 46 public net::URLRequest::Delegate { |
48 public: | 47 public: |
49 URLFetcherCore(URLFetcher* fetcher, | 48 URLFetcherCore(URLFetcher* fetcher, |
50 const GURL& original_url, | 49 const GURL& original_url, |
51 URLFetcher::RequestType request_type, | 50 URLFetcher::RequestType request_type, |
52 URLFetcherDelegate* d); | 51 net::URLFetcherDelegate* d); |
53 | 52 |
54 // Starts the load. It's important that this not happen in the constructor | 53 // Starts the load. It's important that this not happen in the constructor |
55 // because it causes the IO thread to begin AddRef()ing and Release()ing | 54 // because it causes the IO thread to begin AddRef()ing and Release()ing |
56 // us. If our caller hasn't had time to fully construct us and take a | 55 // us. If our caller hasn't had time to fully construct us and take a |
57 // reference, the IO thread could interrupt things, run a task, Release() | 56 // reference, the IO thread could interrupt things, run a task, Release() |
58 // us, and destroy us, leaving the caller with an already-destroyed object | 57 // us, and destroy us, leaving the caller with an already-destroyed object |
59 // when construction finishes. | 58 // when construction finishes. |
60 void Start(); | 59 void Start(); |
61 | 60 |
62 // Stops any in-progress load and ensures no callback will happen. It is | 61 // Stops any in-progress load and ensures no callback will happen. It is |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 bool GetResponseAsString(std::string* out_response_string) const; | 117 bool GetResponseAsString(std::string* out_response_string) const; |
119 bool GetResponseAsFilePath(bool take_ownership, | 118 bool GetResponseAsFilePath(bool take_ownership, |
120 FilePath* out_response_path); | 119 FilePath* out_response_path); |
121 | 120 |
122 // Overridden from net::URLRequest::Delegate: | 121 // Overridden from net::URLRequest::Delegate: |
123 virtual void OnResponseStarted( | 122 virtual void OnResponseStarted( |
124 net::URLRequest* request) OVERRIDE; | 123 net::URLRequest* request) OVERRIDE; |
125 virtual void OnReadCompleted( | 124 virtual void OnReadCompleted( |
126 net::URLRequest* request, int bytes_read) OVERRIDE; | 125 net::URLRequest* request, int bytes_read) OVERRIDE; |
127 | 126 |
128 URLFetcherDelegate* delegate() const { return delegate_; } | 127 net::URLFetcherDelegate* delegate() const { return delegate_; } |
129 static void CancelAll(); | 128 static void CancelAll(); |
130 static int GetNumFetcherCores(); | 129 static int GetNumFetcherCores(); |
131 static void SetEnableInterceptionForTests(bool enabled); | 130 static void SetEnableInterceptionForTests(bool enabled); |
132 | 131 |
133 private: | 132 private: |
134 friend class base::RefCountedThreadSafe<URLFetcherCore>; | 133 friend class base::RefCountedThreadSafe<URLFetcherCore>; |
135 | 134 |
136 // How should the response be stored? | 135 // How should the response be stored? |
137 enum ResponseDestinationType { | 136 enum ResponseDestinationType { |
138 STRING, // Default: In a std::string | 137 STRING, // Default: In a std::string |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 int64 total); | 292 int64 total); |
294 void InformDelegateDownloadDataIfNecessary(int bytes_read); | 293 void InformDelegateDownloadDataIfNecessary(int bytes_read); |
295 void InformDelegateDownloadDataInDelegateThread( | 294 void InformDelegateDownloadDataInDelegateThread( |
296 scoped_ptr<std::string> download_data); | 295 scoped_ptr<std::string> download_data); |
297 | 296 |
298 URLFetcher* fetcher_; // Corresponding fetcher object | 297 URLFetcher* fetcher_; // Corresponding fetcher object |
299 GURL original_url_; // The URL we were asked to fetch | 298 GURL original_url_; // The URL we were asked to fetch |
300 GURL url_; // The URL we eventually wound up at | 299 GURL url_; // The URL we eventually wound up at |
301 URLFetcher::RequestType request_type_; // What type of request is this? | 300 URLFetcher::RequestType request_type_; // What type of request is this? |
302 net::URLRequestStatus status_; // Status of the request | 301 net::URLRequestStatus status_; // Status of the request |
303 URLFetcherDelegate* delegate_; // Object to notify on completion | 302 net::URLFetcherDelegate* delegate_; // Object to notify on completion |
304 scoped_refptr<base::MessageLoopProxy> delegate_loop_proxy_; | 303 scoped_refptr<base::MessageLoopProxy> delegate_loop_proxy_; |
305 // Message loop proxy of the creating | 304 // Message loop proxy of the creating |
306 // thread. | 305 // thread. |
307 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 306 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
308 // The message loop proxy for the thread | 307 // The message loop proxy for the thread |
309 // on which the request IO happens. | 308 // on which the request IO happens. |
310 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; | 309 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; |
311 // The message loop proxy for the thread | 310 // The message loop proxy for the thread |
312 // on which file access happens. | 311 // on which file access happens. |
313 scoped_ptr<net::URLRequest> request_; // The actual request this wraps | 312 scoped_ptr<net::URLRequest> request_; // The actual request this wraps |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 base::debug::StackTrace stack_trace_; | 395 base::debug::StackTrace stack_trace_; |
397 | 396 |
398 static base::LazyInstance<Registry> g_registry; | 397 static base::LazyInstance<Registry> g_registry; |
399 | 398 |
400 DISALLOW_COPY_AND_ASSIGN(URLFetcherCore); | 399 DISALLOW_COPY_AND_ASSIGN(URLFetcherCore); |
401 }; | 400 }; |
402 | 401 |
403 } // namespace content | 402 } // namespace content |
404 | 403 |
405 #endif // CONTENT_COMMON_NET_URL_FETCHER_CORE_H_ | 404 #endif // CONTENT_COMMON_NET_URL_FETCHER_CORE_H_ |
OLD | NEW |