summaryrefslogtreecommitdiffstats
path: root/content/common
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-26 23:39:59 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-26 23:39:59 +0000
commitbeba03b3790fd1645b301818034d357a0e99032d (patch)
treecd973eb9325b2fc21a777f003037aeb96d6b8681 /content/common
parentd8e942a682fccb8f96300efa6120f25abc55a52e (diff)
downloadchromium_src-beba03b3790fd1645b301818034d357a0e99032d.zip
chromium_src-beba03b3790fd1645b301818034d357a0e99032d.tar.gz
chromium_src-beba03b3790fd1645b301818034d357a0e99032d.tar.bz2
Make test URLFetcher implementations not derive from the URLFetcher implementation, since we want to hide that from chrome completely.
SetBackoffDelayForTesting moves from content::UrlFetcher to TestURLFetcher, now that the test objects derive from it. BUG=98716 Review URL: http://codereview.chromium.org/8395038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common')
-rw-r--r--content/common/net/url_fetcher.cc42
-rw-r--r--content/common/net/url_fetcher.h38
2 files changed, 20 insertions, 60 deletions
diff --git a/content/common/net/url_fetcher.cc b/content/common/net/url_fetcher.cc
index e46ee23..237f648 100644
--- a/content/common/net/url_fetcher.cc
+++ b/content/common/net/url_fetcher.cc
@@ -19,6 +19,7 @@
#include "base/string_util.h"
#include "base/threading/thread.h"
#include "content/public/common/url_fetcher_delegate.h"
+#include "content/public/common/url_fetcher_factory.h"
#include "googleurl/src/gurl.h"
#include "net/base/host_port_pair.h"
#include "net/base/io_buffer.h"
@@ -462,10 +463,7 @@ void URLFetcher::Core::TempFileWriter::RemoveTempFile() {
}
}
-// static
-URLFetcher::Factory* URLFetcher::factory_ = NULL;
-
-// static
+static content::URLFetcherFactory* g_factory = NULL;
static bool g_interception_enabled = false;
// static
@@ -482,7 +480,8 @@ content::URLFetcher* content::URLFetcher::Create(
const GURL& url,
RequestType request_type,
content::URLFetcherDelegate* d) {
- return ::URLFetcher::Create(id, url, request_type, d);
+ return g_factory ? g_factory->CreateURLFetcher(id, url, request_type, d) :
+ new ::URLFetcher(url, request_type, d);
}
// static
@@ -507,14 +506,6 @@ URLFetcher::~URLFetcher() {
core_->Stop();
}
-// static
-URLFetcher* URLFetcher::Create(int id, const GURL& url,
- RequestType request_type,
- content::URLFetcherDelegate* d) {
- return factory_ ? factory_->CreateURLFetcher(id, url, request_type, d) :
- new URLFetcher(url, request_type, d);
-}
-
URLFetcher::Core::Core(URLFetcher* fetcher,
const GURL& original_url,
RequestType request_type,
@@ -989,11 +980,6 @@ base::TimeDelta URLFetcher::GetBackoffDelay() const {
return core_->backoff_delay_;
}
-void URLFetcher::SetBackoffDelayForTesting(
- base::TimeDelta backoff_delay) {
- core_->backoff_delay_ = backoff_delay;
-}
-
void URLFetcher::SaveResponseToTemporaryFile(
scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) {
core_->file_message_loop_proxy_ = file_message_loop_proxy;
@@ -1082,16 +1068,6 @@ bool URLFetcher::GetResponseAsString(std::string* out_response_string) const {
return true;
}
-void URLFetcher::SetResponseDestinationForTesting(
- ResponseDestinationType value) {
- core_->response_destination_ = value;
-}
-
-URLFetcher::ResponseDestinationType
-URLFetcher::GetResponseDestinationForTesting() const {
- return core_->response_destination_;
-}
-
bool URLFetcher::GetResponseAsFilePath(bool take_ownership,
FilePath* out_response_path) const {
DCHECK(core_->delegate_loop_proxy_->BelongsToCurrentThread());
@@ -1121,3 +1097,13 @@ int URLFetcher::GetNumFetcherCores() {
content::URLFetcherDelegate* URLFetcher::delegate() const {
return core_->delegate();
}
+
+// static
+content::URLFetcherFactory* URLFetcher::factory() {
+ return g_factory;
+}
+
+// static
+void URLFetcher::set_factory(content::URLFetcherFactory* factory) {
+ g_factory = factory;
+}
diff --git a/content/common/net/url_fetcher.h b/content/common/net/url_fetcher.h
index e1122d8..3c48cba 100644
--- a/content/common/net/url_fetcher.h
+++ b/content/common/net/url_fetcher.h
@@ -16,26 +16,16 @@
#pragma once
#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
#include "base/time.h"
#include "content/public/common/url_fetcher.h"
+namespace content {
+class URLFetcherFactory;
+}
+
class CONTENT_EXPORT URLFetcher : public content::URLFetcher{
public:
- // URLFetcher::Create uses the currently registered Factory to create the
- // URLFetcher. Factory is intended for testing.
- class Factory {
- public:
- virtual URLFetcher* CreateURLFetcher(int id,
- const GURL& url,
- RequestType request_type,
- content::URLFetcherDelegate* d) = 0;
-
- protected:
- virtual ~Factory() {}
- };
-
// |url| is the URL to send the request to.
// |request_type| is the type of request to make.
// |d| the object that will receive the callback on fetch completion.
@@ -44,13 +34,6 @@ class CONTENT_EXPORT URLFetcher : public content::URLFetcher{
content::URLFetcherDelegate* d);
virtual ~URLFetcher();
- // Creates a URLFetcher, ownership returns to the caller. If there is no
- // Factory (the default) this creates and returns a new URLFetcher. See the
- // constructor for a description of the args. |id| may be used during testing
- // to identify who is creating the URLFetcher.
- static URLFetcher* Create(int id, const GURL& url, RequestType request_type,
- content::URLFetcherDelegate* d);
-
// content::URLFetcher implementation:
virtual void SetUploadData(const std::string& upload_content_type,
const std::string& upload_content) OVERRIDE;
@@ -71,8 +54,6 @@ class CONTENT_EXPORT URLFetcher : public content::URLFetcher{
virtual void SetMaxRetries(int max_retries) OVERRIDE;
virtual int GetMaxRetries() const OVERRIDE;
virtual base::TimeDelta GetBackoffDelay() const OVERRIDE;
- virtual void SetBackoffDelayForTesting(
- base::TimeDelta backoff_delay) OVERRIDE;
virtual void SaveResponseToTemporaryFile(
scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE;
virtual net::HttpResponseHeaders* GetResponseHeaders() const OVERRIDE;
@@ -116,9 +97,6 @@ class CONTENT_EXPORT URLFetcher : public content::URLFetcher{
// Used by tests.
void set_response_headers(scoped_refptr<net::HttpResponseHeaders> headers);
- virtual void SetResponseDestinationForTesting(ResponseDestinationType);
- virtual ResponseDestinationType GetResponseDestinationForTesting() const;
-
private:
friend class ScopedURLFetcherFactory;
friend class TestURLFetcher;
@@ -128,22 +106,18 @@ class CONTENT_EXPORT URLFetcher : public content::URLFetcher{
// actively running.
static int GetNumFetcherCores();
- static Factory* factory() { return factory_; }
+ static content::URLFetcherFactory* factory();
// Sets the factory used by the static method Create to create a URLFetcher.
// URLFetcher does not take ownership of |factory|. A value of NULL results
// in a URLFetcher being created directly.
//
// NOTE: for safety, this should only be used through ScopedURLFetcherFactory!
- static void set_factory(Factory* factory) {
- factory_ = factory;
- }
+ static void set_factory(content::URLFetcherFactory* factory);
class Core;
scoped_refptr<Core> core_;
- static Factory* factory_;
-
DISALLOW_COPY_AND_ASSIGN(URLFetcher);
};