summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 19:47:21 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 19:47:21 +0000
commit319d9e6f29cc2d27c0f72ce701d905d2402c350a (patch)
tree5d637ba43b9aeed5c925e694e50aa251230c0b92 /chrome/browser/net
parent22f21125f11953e1022f5e75e560c1af9484503e (diff)
downloadchromium_src-319d9e6f29cc2d27c0f72ce701d905d2402c350a.zip
chromium_src-319d9e6f29cc2d27c0f72ce701d905d2402c350a.tar.gz
chromium_src-319d9e6f29cc2d27c0f72ce701d905d2402c350a.tar.bz2
Reduce the amount of included header files. Vast change like in "Oh God! This revision changes half of the source files!".
Review URL: http://codereview.chromium.org/20378 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9958 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r--chrome/browser/net/dns_global.cc1
-rw-r--r--chrome/browser/net/dns_master.cc2
-rw-r--r--chrome/browser/net/sdch_dictionary_fetcher.cc2
-rw-r--r--chrome/browser/net/url_fetcher.cc113
-rw-r--r--chrome/browser/net/url_fetcher.h125
-rw-r--r--chrome/browser/net/url_fetcher_unittest.cc1
6 files changed, 139 insertions, 105 deletions
diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc
index 67e4265..4e1f1a2 100644
--- a/chrome/browser/net/dns_global.cc
+++ b/chrome/browser/net/dns_global.cc
@@ -20,7 +20,6 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
-#include "googleurl/src/gurl.h"
#include "net/base/dns_resolution_observer.h"
using base::TimeDelta;
diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc
index 34efe37..d58bb4b 100644
--- a/chrome/browser/net/dns_master.cc
+++ b/chrome/browser/net/dns_master.cc
@@ -6,7 +6,7 @@
#include "chrome/browser/net/dns_master.h"
-#include <sstream>
+#include <set>
#include "base/histogram.h"
#include "base/stats_counters.h"
diff --git a/chrome/browser/net/sdch_dictionary_fetcher.cc b/chrome/browser/net/sdch_dictionary_fetcher.cc
index 9bce5f3..3a36bde 100644
--- a/chrome/browser/net/sdch_dictionary_fetcher.cc
+++ b/chrome/browser/net/sdch_dictionary_fetcher.cc
@@ -3,7 +3,9 @@
// found in the LICENSE file.
#include "chrome/browser/net/sdch_dictionary_fetcher.h"
+
#include "chrome/browser/profile.h"
+#include "net/url_request/url_request_status.h"
void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) {
// Avoid pushing duplicate copy onto queue. We may fetch this url again later
diff --git a/chrome/browser/net/url_fetcher.cc b/chrome/browser/net/url_fetcher.cc
index 9e41f22..dcec935 100644
--- a/chrome/browser/net/url_fetcher.cc
+++ b/chrome/browser/net/url_fetcher.cc
@@ -12,9 +12,87 @@
#include "googleurl/src/gurl.h"
#include "net/base/load_flags.h"
#include "net/base/io_buffer.h"
+#include "net/http/http_response_headers.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_context.h"
static const int kBufferSize = 4096;
+class URLFetcher::Core
+ : public base::RefCountedThreadSafe<URLFetcher::Core>,
+ public URLRequest::Delegate {
+ public:
+ // For POST requests, set |content_type| to the MIME type of the content
+ // and set |content| to the data to upload. |flags| are flags to apply to
+ // the load operation--these should be one or more of the LOAD_* flags
+ // defined in url_request.h.
+ Core(URLFetcher* fetcher,
+ const GURL& original_url,
+ RequestType request_type,
+ URLFetcher::Delegate* d);
+
+ // Starts the load. It's important that this not happen in the constructor
+ // because it causes the IO thread to begin AddRef()ing and Release()ing
+ // us. If our caller hasn't had time to fully construct us and take a
+ // reference, the IO thread could interrupt things, run a task, Release()
+ // us, and destroy us, leaving the caller with an already-destroyed object
+ // when construction finishes.
+ void Start();
+
+ // Stops any in-progress load and ensures no callback will happen. It is
+ // safe to call this multiple times.
+ void Stop();
+
+ // URLRequest::Delegate implementations
+ virtual void OnReceivedRedirect(URLRequest* request,
+ const GURL& new_url) { }
+ virtual void OnResponseStarted(URLRequest* request);
+ virtual void OnReadCompleted(URLRequest* request, int bytes_read);
+
+ private:
+ // Wrapper functions that allow us to ensure actions happen on the right
+ // thread.
+ void StartURLRequest();
+ void CancelURLRequest();
+ void OnCompletedURLRequest(const URLRequestStatus& status);
+
+ URLFetcher* fetcher_; // Corresponding fetcher object
+ GURL original_url_; // The URL we were asked to fetch
+ GURL url_; // The URL we eventually wound up at
+ RequestType request_type_; // What type of request is this?
+ URLFetcher::Delegate* delegate_; // Object to notify on completion
+ MessageLoop* delegate_loop_; // Message loop of the creating thread
+ MessageLoop* io_loop_; // Message loop of the IO thread
+ URLRequest* request_; // The actual request this wraps
+ int load_flags_; // Flags for the load operation
+ int response_code_; // HTTP status code for the request
+ std::string data_; // Results of the request
+ scoped_refptr<net::IOBuffer> buffer_;
+ // Read buffer
+ scoped_refptr<URLRequestContext> request_context_;
+ // Cookie/cache info for the request
+ ResponseCookies cookies_; // Response cookies
+ std::string extra_request_headers_;// Extra headers for the request, if any
+ scoped_refptr<net::HttpResponseHeaders> response_headers_;
+
+ std::string upload_content_; // HTTP POST payload
+ std::string upload_content_type_; // MIME type of POST payload
+
+ // The overload protection entry for this URL. This is used to
+ // incrementally back off how rapidly we'll send requests to a particular
+ // URL, to avoid placing too much demand on the remote resource. We update
+ // this with the status of all requests as they return, and in turn use it
+ // to determine how long to wait before making another request.
+ URLFetcherProtectEntry* protect_entry_;
+ // |num_retries_| indicates how many times we've failed to successfully
+ // fetch this URL. Once this value exceeds the maximum number of retries
+ // specified by the protection manager, we'll give up.
+ int num_retries_;
+
+ friend class URLFetcher;
+ DISALLOW_COPY_AND_ASSIGN(Core);
+};
+
URLFetcher::URLFetcher(const GURL& url,
RequestType request_type,
Delegate* d)
@@ -184,3 +262,38 @@ void URLFetcher::Core::OnCompletedURLRequest(const URLRequestStatus& status) {
cookies_, data_);
}
}
+
+void URLFetcher::set_io_loop(MessageLoop* io_loop) {
+ core_->io_loop_ = io_loop;
+}
+
+void URLFetcher::set_upload_data(const std::string& upload_content_type,
+ const std::string& upload_content) {
+ core_->upload_content_type_ = upload_content_type;
+ core_->upload_content_ = upload_content;
+}
+
+void URLFetcher::set_load_flags(int load_flags) {
+ core_->load_flags_ = load_flags;
+}
+
+void URLFetcher::set_extra_request_headers(
+ const std::string& extra_request_headers) {
+ core_->extra_request_headers_ = extra_request_headers;
+}
+
+void URLFetcher::set_request_context(URLRequestContext* request_context) {
+ core_->request_context_ = request_context;
+}
+
+net::HttpResponseHeaders* URLFetcher::response_headers() const {
+ return core_->response_headers_;
+}
+
+void URLFetcher::Start() {
+ core_->Start();
+}
+
+const GURL& URLFetcher::url() const {
+ return core_->url_;
+}
diff --git a/chrome/browser/net/url_fetcher.h b/chrome/browser/net/url_fetcher.h
index 044e61b..5485d7f 100644
--- a/chrome/browser/net/url_fetcher.h
+++ b/chrome/browser/net/url_fetcher.h
@@ -7,15 +7,22 @@
// reading. This is useful for callers who simply want to get the data from a
// URL and don't care about all the nitty-gritty details.
-#ifndef CHROME_BROWSER_URL_FETCHER_H__
-#define CHROME_BROWSER_URL_FETCHER_H__
+#ifndef CHROME_BROWSER_URL_FETCHER_H_
+#define CHROME_BROWSER_URL_FETCHER_H_
#include "base/message_loop.h"
#include "base/ref_counted.h"
#include "chrome/browser/net/url_fetcher_protect.h"
-#include "net/url_request/url_request.h"
+class GURL;
+typedef std::vector<std::string> ResponseCookies;
+class URLFetcher;
class URLRequestContext;
+class URLRequestStatus;
+
+namespace net {
+class HttpResponseHeaders;
+}
// To use this class, create an instance with the desired URL and a pointer to
// the object to be notified when the URL has been loaded:
@@ -74,59 +81,44 @@ class URLFetcher {
// |d| the object that will receive the callback on fetch completion.
URLFetcher(const GURL& url, RequestType request_type, Delegate* d);
+ ~URLFetcher();
+
// This should only be used by unittests, where g_browser_process->io_thread()
// does not exist and we must specify an alternate loop. Unfortunately, we
// can't put it under #ifdef UNIT_TEST since some callers (which themselves
// should only be reached in unit tests) use this. See
// chrome/browser/feeds/feed_manager.cc.
- void set_io_loop(MessageLoop* io_loop) {
- core_->io_loop_ = io_loop;
- }
+ void set_io_loop(MessageLoop* io_loop);
// Sets data only needed by POSTs. All callers making POST requests should
// call this before the request is started. |upload_content_type| is the MIME
// type of the content, while |upload_content| is the data to be sent (the
// Content-Length header value will be set to the length of this data).
void set_upload_data(const std::string& upload_content_type,
- const std::string& upload_content) {
- core_->upload_content_type_ = upload_content_type;
- core_->upload_content_ = upload_content;
- }
+ const std::string& upload_content);
// Set one or more load flags as defined in net/base/load_flags.h. Must be
// called before the request is started.
- void set_load_flags(int load_flags) {
- core_->load_flags_ = load_flags;
- }
+ void set_load_flags(int load_flags);
// Set extra headers on the request. Must be called before the request
// is started.
- void set_extra_request_headers(const std::string& extra_request_headers) {
- core_->extra_request_headers_ = extra_request_headers;
- }
+ void set_extra_request_headers(const std::string& extra_request_headers);
// Set the URLRequestContext on the request. Must be called before the
// request is started.
- void set_request_context(URLRequestContext* request_context) {
- core_->request_context_ = request_context;
- }
+ void set_request_context(URLRequestContext* request_context);
// Retrieve the response headers from the request. Must only be called after
// the OnURLFetchComplete callback has run.
- net::HttpResponseHeaders* response_headers() const {
- return core_->response_headers_;
- }
+ net::HttpResponseHeaders* response_headers() const;
// Start the request. After this is called, you may not change any other
// settings.
- void Start() { core_->Start(); }
+ void Start();
// Return the URL that this fetcher is processing.
- const GURL& url() const {
- return core_->url_;
- }
-
- ~URLFetcher();
+ const GURL& url() const;
private:
// This class is the real guts of URLFetcher.
@@ -137,84 +129,11 @@ class URLFetcher {
// thread (since that class is not currently threadsafe and relies on
// underlying Microsoft APIs that we don't know to be threadsafe), while
// keeping the delegate callback on the delegate's thread.
- class Core : public base::RefCountedThreadSafe<URLFetcher::Core>,
- public URLRequest::Delegate {
- public:
- // For POST requests, set |content_type| to the MIME type of the content
- // and set |content| to the data to upload. |flags| are flags to apply to
- // the load operation--these should be one or more of the LOAD_* flags
- // defined in url_request.h.
- Core(URLFetcher* fetcher,
- const GURL& original_url,
- RequestType request_type,
- URLFetcher::Delegate* d);
-
- // Starts the load. It's important that this not happen in the constructor
- // because it causes the IO thread to begin AddRef()ing and Release()ing
- // us. If our caller hasn't had time to fully construct us and take a
- // reference, the IO thread could interrupt things, run a task, Release()
- // us, and destroy us, leaving the caller with an already-destroyed object
- // when construction finishes.
- void Start();
-
- // Stops any in-progress load and ensures no callback will happen. It is
- // safe to call this multiple times.
- void Stop();
-
- // URLRequest::Delegate implementations
- virtual void OnReceivedRedirect(URLRequest* request,
- const GURL& new_url) { }
- virtual void OnResponseStarted(URLRequest* request);
- virtual void OnReadCompleted(URLRequest* request, int bytes_read);
-
- private:
- // Wrapper functions that allow us to ensure actions happen on the right
- // thread.
- void StartURLRequest();
- void CancelURLRequest();
- void OnCompletedURLRequest(const URLRequestStatus& status);
-
- URLFetcher* fetcher_; // Corresponding fetcher object
- GURL original_url_; // The URL we were asked to fetch
- GURL url_; // The URL we eventually wound up at
- RequestType request_type_; // What type of request is this?
- URLFetcher::Delegate* delegate_; // Object to notify on completion
- MessageLoop* delegate_loop_; // Message loop of the creating thread
- MessageLoop* io_loop_; // Message loop of the IO thread
- URLRequest* request_; // The actual request this wraps
- int load_flags_; // Flags for the load operation
- int response_code_; // HTTP status code for the request
- std::string data_; // Results of the request
- scoped_refptr<net::IOBuffer> buffer_;
- // Read buffer
- scoped_refptr<URLRequestContext> request_context_;
- // Cookie/cache info for the request
- ResponseCookies cookies_; // Response cookies
- std::string extra_request_headers_;// Extra headers for the request, if any
- scoped_refptr<net::HttpResponseHeaders> response_headers_;
-
- std::string upload_content_; // HTTP POST payload
- std::string upload_content_type_; // MIME type of POST payload
-
- // The overload protection entry for this URL. This is used to
- // incrementally back off how rapidly we'll send requests to a particular
- // URL, to avoid placing too much demand on the remote resource. We update
- // this with the status of all requests as they return, and in turn use it
- // to determine how long to wait before making another request.
- URLFetcherProtectEntry* protect_entry_;
- // |num_retries_| indicates how many times we've failed to successfully
- // fetch this URL. Once this value exceeds the maximum number of retries
- // specified by the protection manager, we'll give up.
- int num_retries_;
-
- friend class URLFetcher;
- DISALLOW_EVIL_CONSTRUCTORS(Core);
- };
+ class Core;
scoped_refptr<Core> core_;
DISALLOW_EVIL_CONSTRUCTORS(URLFetcher);
};
-#endif // CHROME_BROWSER_URL_FETCHER_H__
-
+#endif // CHROME_BROWSER_URL_FETCHER_H_
diff --git a/chrome/browser/net/url_fetcher_unittest.cc b/chrome/browser/net/url_fetcher_unittest.cc
index 03b40d7..6a6e3ff 100644
--- a/chrome/browser/net/url_fetcher_unittest.cc
+++ b/chrome/browser/net/url_fetcher_unittest.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/net/url_fetcher_protect.h"
#include "chrome/common/chrome_plugin_lib.h"
#include "net/base/ssl_test_util.h"
+#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_unittest.h"
#include "testing/gtest/include/gtest/gtest.h"