| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 URLRequest that handles | 5 // This file contains URLFetcher, a wrapper around 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 #ifndef CHROME_BROWSER_URL_FETCHER_H_ | 10 #ifndef CHROME_BROWSER_URL_FETCHER_H_ |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // resulting status and (if applicable) HTTP response code. From that point | 41 // resulting status and (if applicable) HTTP response code. From that point |
| 42 // until the original URLFetcher instance is destroyed, you may examine the | 42 // until the original URLFetcher instance is destroyed, you may examine the |
| 43 // provided status and data for the URL. (You should copy these objects if you | 43 // provided status and data for the URL. (You should copy these objects if you |
| 44 // need them to live longer than the URLFetcher instance.) If the URLFetcher | 44 // need them to live longer than the URLFetcher instance.) If the URLFetcher |
| 45 // instance is destroyed before the callback happens, the fetch will be | 45 // instance is destroyed before the callback happens, the fetch will be |
| 46 // canceled and no callback will occur. | 46 // canceled and no callback will occur. |
| 47 // | 47 // |
| 48 // You may create the URLFetcher instance on any thread; OnURLFetchComplete() | 48 // You may create the URLFetcher instance on any thread; OnURLFetchComplete() |
| 49 // will be called back on the same thread you use to create the instance. | 49 // will be called back on the same thread you use to create the instance. |
| 50 // | 50 // |
| 51 // NOTE: Take extra care when using URLFetcher in services that live on the | |
| 52 // BrowserProcess; all URLFetcher instances need to be destroyed before | |
| 53 // the IO thread goes away, since the URLFetcher destructor requests an | |
| 54 // InvokeLater operation on that thread. | |
| 55 // | 51 // |
| 56 // NOTE: By default URLFetcher requests are NOT intercepted, except when | 52 // NOTE: By default URLFetcher requests are NOT intercepted, except when |
| 57 // interception is explicitly enabled in tests. | 53 // interception is explicitly enabled in tests. |
| 58 | 54 |
| 59 class URLFetcher { | 55 class URLFetcher { |
| 60 public: | 56 public: |
| 61 enum RequestType { | 57 enum RequestType { |
| 62 GET, | 58 GET, |
| 63 POST, | 59 POST, |
| 64 HEAD, | 60 HEAD, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 g_interception_enabled = enabled; | 105 g_interception_enabled = enabled; |
| 110 } | 106 } |
| 111 | 107 |
| 112 // Creates a URLFetcher, ownership returns to the caller. If there is no | 108 // Creates a URLFetcher, ownership returns to the caller. If there is no |
| 113 // Factory (the default) this creates and returns a new URLFetcher. See the | 109 // Factory (the default) this creates and returns a new URLFetcher. See the |
| 114 // constructor for a description of the args. |id| may be used during testing | 110 // constructor for a description of the args. |id| may be used during testing |
| 115 // to identify who is creating the URLFetcher. | 111 // to identify who is creating the URLFetcher. |
| 116 static URLFetcher* Create(int id, const GURL& url, RequestType request_type, | 112 static URLFetcher* Create(int id, const GURL& url, RequestType request_type, |
| 117 Delegate* d); | 113 Delegate* d); |
| 118 | 114 |
| 119 // This should only be used by unittests, where g_browser_process->io_thread() | |
| 120 // does not exist and we must specify an alternate loop. Unfortunately, we | |
| 121 // can't put it under #ifdef UNIT_TEST since some callers (which themselves | |
| 122 // should only be reached in unit tests) use this. See | |
| 123 // chrome/browser/feeds/feed_manager.cc. | |
| 124 void set_io_loop(MessageLoop* io_loop); | |
| 125 | |
| 126 // Sets data only needed by POSTs. All callers making POST requests should | 115 // Sets data only needed by POSTs. All callers making POST requests should |
| 127 // call this before the request is started. |upload_content_type| is the MIME | 116 // call this before the request is started. |upload_content_type| is the MIME |
| 128 // type of the content, while |upload_content| is the data to be sent (the | 117 // type of the content, while |upload_content| is the data to be sent (the |
| 129 // Content-Length header value will be set to the length of this data). | 118 // Content-Length header value will be set to the length of this data). |
| 130 void set_upload_data(const std::string& upload_content_type, | 119 void set_upload_data(const std::string& upload_content_type, |
| 131 const std::string& upload_content); | 120 const std::string& upload_content); |
| 132 | 121 |
| 133 // Set one or more load flags as defined in net/base/load_flags.h. Must be | 122 // Set one or more load flags as defined in net/base/load_flags.h. Must be |
| 134 // called before the request is started. | 123 // called before the request is started. |
| 135 void set_load_flags(int load_flags); | 124 void set_load_flags(int load_flags); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 154 virtual void Start(); | 143 virtual void Start(); |
| 155 | 144 |
| 156 // Return the URL that this fetcher is processing. | 145 // Return the URL that this fetcher is processing. |
| 157 const GURL& url() const; | 146 const GURL& url() const; |
| 158 | 147 |
| 159 protected: | 148 protected: |
| 160 // Returns the delegate. | 149 // Returns the delegate. |
| 161 Delegate* delegate() const; | 150 Delegate* delegate() const; |
| 162 | 151 |
| 163 private: | 152 private: |
| 164 // This class is the real guts of URLFetcher. | |
| 165 // | |
| 166 // When created, delegate_loop_ is set to the message loop of the current | |
| 167 // thread, while io_loop_ is set to the message loop of the IO thread. These | |
| 168 // are used to ensure that all handling of URLRequests happens on the IO | |
| 169 // thread (since that class is not currently threadsafe and relies on | |
| 170 // underlying Microsoft APIs that we don't know to be threadsafe), while | |
| 171 // keeping the delegate callback on the delegate's thread. | |
| 172 class Core; | 153 class Core; |
| 173 | 154 |
| 174 scoped_refptr<Core> core_; | 155 scoped_refptr<Core> core_; |
| 175 | 156 |
| 176 static Factory* factory_; | 157 static Factory* factory_; |
| 177 | 158 |
| 178 base::LeakTracker<URLFetcher> leak_tracker_; | 159 base::LeakTracker<URLFetcher> leak_tracker_; |
| 179 | 160 |
| 180 static bool g_interception_enabled; | 161 static bool g_interception_enabled; |
| 181 | 162 |
| 182 DISALLOW_EVIL_CONSTRUCTORS(URLFetcher); | 163 DISALLOW_EVIL_CONSTRUCTORS(URLFetcher); |
| 183 }; | 164 }; |
| 184 | 165 |
| 185 #endif // CHROME_BROWSER_URL_FETCHER_H_ | 166 #endif // CHROME_BROWSER_URL_FETCHER_H_ |
| OLD | NEW |