summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 10:52:45 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 10:52:45 +0000
commitf37595062cde15c3229cd68d8cfe9916b98d5fbb (patch)
tree61a44b028f9d0f10b7c98b8da79a95e9ecb8d984 /net
parentf0d7fe7c2cee6e2d9aadcb8602476e4df05d7da1 (diff)
downloadchromium_src-f37595062cde15c3229cd68d8cfe9916b98d5fbb.zip
chromium_src-f37595062cde15c3229cd68d8cfe9916b98d5fbb.tar.gz
chromium_src-f37595062cde15c3229cd68d8cfe9916b98d5fbb.tar.bz2
Make the URLRequestContext constant
The URLRequestContext is basically a collection of pointers to other data structures. This CL makes sure that these pointers are not easily modified after the construction of the URLRequestContext. BUG=67597 TEST=no Review URL: http://codereview.chromium.org/7322010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92511 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/proxy/proxy_script_fetcher_impl.cc2
-rw-r--r--net/url_request/https_prober.cc3
-rw-r--r--net/url_request/https_prober.h2
-rw-r--r--net/url_request/url_request.cc6
-rw-r--r--net/url_request/url_request.h6
-rw-r--r--net/url_request/url_request_context.cc1
-rw-r--r--net/url_request/url_request_context.h7
-rw-r--r--net/url_request/url_request_ftp_job.h2
-rw-r--r--net/url_request/url_request_http_job.cc4
-rw-r--r--net/url_request/url_request_http_job.h2
-rw-r--r--net/url_request/url_request_unittest.cc5
-rw-r--r--net/url_request/view_cache_helper.cc6
-rw-r--r--net/url_request/view_cache_helper.h8
13 files changed, 29 insertions, 25 deletions
diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc
index d0b9d6a..0c4bb6f 100644
--- a/net/proxy/proxy_script_fetcher_impl.cc
+++ b/net/proxy/proxy_script_fetcher_impl.cc
@@ -293,7 +293,7 @@ void ProxyScriptFetcherImpl::FetchCompleted() {
// Hold a reference to the URLRequestContext to prevent re-entrancy from
// ~URLRequestContext.
- scoped_refptr<URLRequestContext> context(cur_request_->context());
+ scoped_refptr<const URLRequestContext> context(cur_request_->context());
ResetCurRequestState();
callback->Run(result_code);
diff --git a/net/url_request/https_prober.cc b/net/url_request/https_prober.cc
index bc7ba04..de0dc9b 100644
--- a/net/url_request/https_prober.cc
+++ b/net/url_request/https_prober.cc
@@ -23,7 +23,8 @@ bool HTTPSProber::InFlight(const std::string& host) const {
return inflight_probes_.find(host) != inflight_probes_.end();
}
-bool HTTPSProber::ProbeHost(const std::string& host, URLRequestContext* ctx,
+bool HTTPSProber::ProbeHost(const std::string& host,
+ const URLRequestContext* ctx,
HTTPSProberDelegate* delegate) {
if (HaveProbed(host) || InFlight(host)) {
return false;
diff --git a/net/url_request/https_prober.h b/net/url_request/https_prober.h
index d152e76..467a6d8 100644
--- a/net/url_request/https_prober.h
+++ b/net/url_request/https_prober.h
@@ -50,7 +50,7 @@ class HTTPSProber : public URLRequest::Delegate {
// false will be returned, and no other action is taken. Otherwise, a new
// probe is started, true is returned and the Delegate will be called with the
// results (true means a successful handshake).
- bool ProbeHost(const std::string& host, URLRequestContext* ctx,
+ bool ProbeHost(const std::string& host, const URLRequestContext* ctx,
HTTPSProberDelegate* delegate);
// Implementation of URLRequest::Delegate
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 192c419..5c30d67 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -681,12 +681,12 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) {
return OK;
}
-URLRequestContext* URLRequest::context() const {
+const URLRequestContext* URLRequest::context() const {
return context_.get();
}
-void URLRequest::set_context(URLRequestContext* context) {
- scoped_refptr<URLRequestContext> prev_context = context_;
+void URLRequest::set_context(const URLRequestContext* context) {
+ scoped_refptr<const URLRequestContext> prev_context = context_;
context_ = context;
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index cbd7bab..de4ca27 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -544,8 +544,8 @@ class NET_API URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe) {
void ContinueDespiteLastError();
// Used to specify the context (cookie store, cache) for this request.
- URLRequestContext* context() const;
- void set_context(URLRequestContext* context);
+ const URLRequestContext* context() const;
+ void set_context(const URLRequestContext* context);
const BoundNetLog& net_log() const { return net_log_; }
@@ -634,7 +634,7 @@ class NET_API URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// Contextual information used for this request (can be NULL). This contains
// most of the dependencies which are shared between requests (disk cache,
// cookie store, socket pool, etc.)
- scoped_refptr<URLRequestContext> context_;
+ scoped_refptr<const URLRequestContext> context_;
// Tracks the time spent in various load states throughout this request.
BoundNetLog net_log_;
diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc
index f34e196..608196c 100644
--- a/net/url_request/url_request_context.cc
+++ b/net/url_request/url_request_context.cc
@@ -22,6 +22,7 @@ URLRequestContext::URLRequestContext()
proxy_service_(NULL),
network_delegate_(NULL),
transport_security_state_(NULL),
+ ftp_auth_cache_(new FtpAuthCache),
http_transaction_factory_(NULL),
ftp_transaction_factory_(NULL),
job_factory_(NULL) {
diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h
index 998e3fb..4e3b9c1 100644
--- a/net/url_request/url_request_context.h
+++ b/net/url_request/url_request_context.h
@@ -12,6 +12,7 @@
#pragma once
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "net/base/net_api.h"
#include "net/base/net_log.h"
@@ -115,7 +116,7 @@ class NET_API URLRequestContext
}
// Gets the ftp transaction factory for this context.
- FtpTransactionFactory* ftp_transaction_factory() {
+ FtpTransactionFactory* ftp_transaction_factory() const {
return ftp_transaction_factory_;
}
void set_ftp_transaction_factory(FtpTransactionFactory* factory) {
@@ -141,7 +142,7 @@ class NET_API URLRequestContext
}
// Gets the FTP authentication cache for this context.
- FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; }
+ FtpAuthCache* ftp_auth_cache() const { return ftp_auth_cache_.get(); }
// Gets the value of 'Accept-Charset' header field.
const std::string& accept_charset() const { return accept_charset_; }
@@ -196,7 +197,7 @@ class NET_API URLRequestContext
NetworkDelegate* network_delegate_;
scoped_refptr<CookieStore> cookie_store_;
scoped_refptr<TransportSecurityState> transport_security_state_;
- FtpAuthCache ftp_auth_cache_;
+ scoped_ptr<FtpAuthCache> ftp_auth_cache_;
std::string accept_language_;
std::string accept_charset_;
// The charset of the referrer where this request comes from. It's not
diff --git a/net/url_request/url_request_ftp_job.h b/net/url_request/url_request_ftp_job.h
index 84c54e1..5fc5a13 100644
--- a/net/url_request/url_request_ftp_job.h
+++ b/net/url_request/url_request_ftp_job.h
@@ -72,7 +72,7 @@ class URLRequestFtpJob : public URLRequestJob {
// Keep a reference to the url request context to be sure it's not deleted
// before us.
- scoped_refptr<URLRequestContext> context_;
+ scoped_refptr<const URLRequestContext> context_;
ScopedRunnableMethodFactory<URLRequestFtpJob> method_factory_;
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index c3f354c..9a31d72 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -477,7 +477,7 @@ void URLRequestHttpJob::AddExtraHeaders() {
}
}
- URLRequestContext* context = request_->context();
+ const URLRequestContext* context = request_->context();
if (context) {
// Only add default Accept-Language and Accept-Charset if the request
// didn't have them specified.
@@ -597,7 +597,7 @@ void URLRequestHttpJob::FetchResponseCookies(
void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() {
DCHECK(response_info_);
- URLRequestContext* ctx = request_->context();
+ const URLRequestContext* ctx = request_->context();
if (!ctx || !ctx->transport_security_state())
return;
diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h
index 67632cb..c5b045d 100644
--- a/net/url_request/url_request_http_job.h
+++ b/net/url_request/url_request_http_job.h
@@ -89,7 +89,7 @@ class URLRequestHttpJob : public URLRequestJob {
// Keep a reference to the url request context to be sure it's not deleted
// before us.
- scoped_refptr<URLRequestContext> context_;
+ scoped_refptr<const URLRequestContext> context_;
HttpRequestInfo request_info_;
const HttpResponseInfo* response_info_;
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 281daaf..28ec3e1 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -2527,10 +2527,11 @@ TEST_F(URLRequestTest, DoNotOverrideReferrer) {
// content is empty.
TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) {
TestNetworkDelegate network_delegate;
+ scoped_refptr<URLRequestContext> context(new TestURLRequestContext());
+ context->set_network_delegate(&network_delegate);
TestDelegate d;
TestURLRequest req(GURL("data:,"), &d);
- req.set_context(new TestURLRequestContext());
- req.context()->set_network_delegate(&network_delegate);
+ req.set_context(context);
req.Start();
MessageLoop::current()->Run();
EXPECT_EQ("", d.data_received());
diff --git a/net/url_request/view_cache_helper.cc b/net/url_request/view_cache_helper.cc
index d6761e1..768782e 100644
--- a/net/url_request/view_cache_helper.cc
+++ b/net/url_request/view_cache_helper.cc
@@ -63,13 +63,13 @@ ViewCacheHelper::~ViewCacheHelper() {
}
int ViewCacheHelper::GetEntryInfoHTML(const std::string& key,
- URLRequestContext* context,
+ const URLRequestContext* context,
std::string* out,
CompletionCallback* callback) {
return GetInfoHTML(key, context, std::string(), out, callback);
}
-int ViewCacheHelper::GetContentsHTML(URLRequestContext* context,
+int ViewCacheHelper::GetContentsHTML(const URLRequestContext* context,
const std::string& url_prefix,
std::string* out,
CompletionCallback* callback) {
@@ -118,7 +118,7 @@ void ViewCacheHelper::HexDump(const char *buf, size_t buf_len,
//-----------------------------------------------------------------------------
int ViewCacheHelper::GetInfoHTML(const std::string& key,
- URLRequestContext* context,
+ const URLRequestContext* context,
const std::string& url_prefix,
std::string* out,
CompletionCallback* callback) {
diff --git a/net/url_request/view_cache_helper.h b/net/url_request/view_cache_helper.h
index 18979ea..4f8c2b5 100644
--- a/net/url_request/view_cache_helper.h
+++ b/net/url_request/view_cache_helper.h
@@ -31,7 +31,7 @@ class NET_API ViewCacheHelper {
// operation completes. |out| must remain valid until this operation completes
// or the object is destroyed.
int GetEntryInfoHTML(const std::string& key,
- URLRequestContext* context,
+ const URLRequestContext* context,
std::string* out,
CompletionCallback* callback);
@@ -40,7 +40,7 @@ class NET_API ViewCacheHelper {
// operation completes. |out| must remain valid until this operation completes
// or the object is destroyed. |url_prefix| will be prepended to each entry
// key as a link to the entry.
- int GetContentsHTML(URLRequestContext* context,
+ int GetContentsHTML(const URLRequestContext* context,
const std::string& url_prefix,
std::string* out,
CompletionCallback* callback);
@@ -67,7 +67,7 @@ class NET_API ViewCacheHelper {
// Implements GetEntryInfoHTML and GetContentsHTML.
int GetInfoHTML(const std::string& key,
- URLRequestContext* context,
+ const URLRequestContext* context,
const std::string& url_prefix,
std::string* out,
CompletionCallback* callback);
@@ -99,7 +99,7 @@ class NET_API ViewCacheHelper {
// Called to signal completion of asynchronous IO.
void OnIOComplete(int result);
- scoped_refptr<URLRequestContext> context_;
+ scoped_refptr<const URLRequestContext> context_;
disk_cache::Backend* disk_cache_;
disk_cache::Entry* entry_;
void* iter_;