summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser.vcproj8
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc171
-rw-r--r--chrome/browser/net/chrome_url_request_context.h58
-rw-r--r--chrome/browser/profile.cc304
-rw-r--r--chrome/browser/profile.h5
-rw-r--r--net/url_request/url_request_context.h7
6 files changed, 268 insertions, 285 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index 61ad12a..82d35de 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -1950,6 +1950,14 @@
Name="Net"
>
<File
+ RelativePath=".\net\chrome_url_request_context.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\net\chrome_url_request_context.h"
+ >
+ </File>
+ <File
RelativePath=".\net\dns_global.cc"
>
</File>
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
new file mode 100644
index 0000000..d5ce7fb
--- /dev/null
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -0,0 +1,171 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/net/chrome_url_request_context.h"
+
+#include "base/command_line.h"
+#include "base/string_util.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "net/http/http_cache.h"
+#include "net/proxy/proxy_service.h"
+#include "webkit/glue/webkit_glue.h"
+
+// Sets up proxy info if it was specified, otherwise returns NULL. The
+// returned pointer MUST be deleted by the caller if non-NULL.
+static net::ProxyInfo* CreateProxyInfo() {
+ net::ProxyInfo* proxy_info = NULL;
+
+ CommandLine command_line;
+ if (command_line.HasSwitch(switches::kProxyServer)) {
+ proxy_info = new net::ProxyInfo();
+ const std::wstring& proxy_server =
+ command_line.GetSwitchValue(switches::kProxyServer);
+ proxy_info->UseNamedProxy(WideToASCII(proxy_server));
+ }
+
+ return proxy_info;
+}
+
+// static
+ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
+ Profile* profile, const std::wstring& cookie_store_path,
+ const std::wstring& disk_cache_path) {
+ DCHECK(!profile->IsOffTheRecord());
+ ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
+
+ scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo());
+ context->proxy_service_ = net::ProxyService::Create(proxy_info.get());
+
+ net::HttpCache* cache =
+ new net::HttpCache(context->proxy_service_, disk_cache_path, 0);
+
+ CommandLine command_line;
+ bool record_mode = chrome::kRecordModeEnabled &&
+ command_line.HasSwitch(switches::kRecordMode);
+ bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
+
+ if (record_mode || playback_mode) {
+ // Don't use existing cookies and use an in-memory store.
+ context->cookie_store_ = new net::CookieMonster();
+ cache->set_mode(
+ record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK);
+ }
+ context->http_transaction_factory_ = cache;
+
+ // setup cookie store
+ if (!context->cookie_store_) {
+ DCHECK(!cookie_store_path.empty());
+ context->cookie_db_.reset(new SQLitePersistentCookieStore(
+ cookie_store_path, g_browser_process->db_thread()->message_loop()));
+ context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get());
+ }
+
+ return context;
+}
+
+// static
+ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
+ Profile* profile) {
+ DCHECK(profile->IsOffTheRecord());
+ ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
+
+ // Share the same proxy service as the original profile. This proxy
+ // service's lifespan is dependent on the lifespan of the original profile,
+ // which we reference (see above).
+ context->proxy_service_ =
+ profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
+
+ context->http_transaction_factory_ =
+ new net::HttpCache(context->proxy_service_, 0);
+ context->cookie_store_ = new net::CookieMonster;
+
+ return context;
+}
+
+ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile)
+ : prefs_(profile->GetPrefs()),
+ is_off_the_record_(profile->IsOffTheRecord()) {
+ user_agent_ = webkit_glue::GetUserAgent();
+
+ // set up Accept-Language and Accept-Charset header values
+ // TODO(jungshik) : This may slow down http requests. Perhaps,
+ // we have to come up with a better way to set up these values.
+ accept_language_ = WideToASCII(prefs_->GetString(prefs::kAcceptLanguages));
+ accept_charset_ = WideToASCII(prefs_->GetString(prefs::kDefaultCharset));
+ accept_charset_ += ",*,utf-8";
+
+ cookie_policy_.SetType(net::CookiePolicy::FromInt(
+ prefs_->GetInteger(prefs::kCookieBehavior)));
+
+ prefs_->AddPrefObserver(prefs::kAcceptLanguages, this);
+ prefs_->AddPrefObserver(prefs::kCookieBehavior, this);
+}
+
+// NotificationObserver implementation.
+void ChromeURLRequestContext::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (NOTIFY_PREF_CHANGED == type) {
+ std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
+ PrefService* prefs = Source<PrefService>(source).ptr();
+ DCHECK(pref_name_in && prefs);
+ if (*pref_name_in == prefs::kAcceptLanguages) {
+ std::string accept_language =
+ WideToASCII(prefs->GetString(prefs::kAcceptLanguages));
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(this,
+ &ChromeURLRequestContext::OnAcceptLanguageChange,
+ accept_language));
+ } else if (*pref_name_in == prefs::kCookieBehavior) {
+ net::CookiePolicy::Type type = net::CookiePolicy::FromInt(
+ prefs_->GetInteger(prefs::kCookieBehavior));
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(this,
+ &ChromeURLRequestContext::OnCookiePolicyChange,
+ type));
+ }
+ } else {
+ NOTREACHED();
+ }
+}
+
+void ChromeURLRequestContext::CleanupOnUIThread() {
+ // Unregister for pref notifications.
+ prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this);
+ prefs_->RemovePrefObserver(prefs::kCookieBehavior, this);
+ prefs_ = NULL;
+}
+
+void ChromeURLRequestContext::OnAcceptLanguageChange(std::string accept_language) {
+ DCHECK(MessageLoop::current() ==
+ ChromeThread::GetMessageLoop(ChromeThread::IO));
+ accept_language_ = accept_language;
+}
+
+void ChromeURLRequestContext::OnCookiePolicyChange(net::CookiePolicy::Type type) {
+ DCHECK(MessageLoop::current() ==
+ ChromeThread::GetMessageLoop(ChromeThread::IO));
+ cookie_policy_.SetType(type);
+}
+
+ChromeURLRequestContext::~ChromeURLRequestContext() {
+ DCHECK(NULL == prefs_);
+
+ NotificationService::current()->Notify(NOTIFY_URL_REQUEST_CONTEXT_RELEASED,
+ Source<URLRequestContext>(this),
+ NotificationService::NoDetails());
+
+ delete cookie_store_;
+ delete http_transaction_factory_;
+
+ // Do not delete the proxy service in the case of OTR, as it is owned by the
+ // original URLRequestContext.
+ if (!is_off_the_record_)
+ delete proxy_service_;
+}
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
new file mode 100644
index 0000000..ab62e60
--- /dev/null
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/net/cookie_monster_sqlite.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/pref_service.h"
+#include "net/url_request/url_request_context.h"
+
+class Profile;
+
+// A URLRequestContext subclass used by the browser. This can be used to store
+// extra information about requests, beyond what is supported by the base
+// URLRequestContext class.
+//
+// All methods are expected to be called on the IO thread except the
+// constructor and factories (CreateOriginal, CreateOffTheRecord), which are
+// expected to be called on the UI thread.
+class ChromeURLRequestContext : public URLRequestContext,
+ public NotificationObserver {
+ public:
+ // Create an instance for use with an 'original' (non-OTR) profile. This is
+ // expected to get called on the UI thread.
+ static ChromeURLRequestContext* CreateOriginal(
+ Profile* profile, const std::wstring& cookie_store_path,
+ const std::wstring& disk_cache_path);
+
+ // Create an instance for use with an OTR profile. This is expected to get
+ // called on the UI thread.
+ static ChromeURLRequestContext* CreateOffTheRecord(Profile* profile);
+
+ // Clean up UI thread resources. This is expected to get called on the UI
+ // thread before the instance is deleted on the IO thread.
+ void CleanupOnUIThread();
+
+ private:
+ // Private constructor, use the static factory methods instead. This is
+ // expected to be called on the UI thread.
+ ChromeURLRequestContext(Profile* profile);
+
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // Callback for when the accept language changes.
+ void OnAcceptLanguageChange(std::string accept_language);
+
+ // Callback for when the cookie policy changes.
+ void OnCookiePolicyChange(net::CookiePolicy::Type type);
+
+ // Destructor.
+ virtual ~ChromeURLRequestContext();
+
+ scoped_ptr<SQLitePersistentCookieStore> cookie_db_;
+ PrefService* prefs_;
+ bool is_off_the_record_;
+};
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index d8f2f64..9014424 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/greasemonkey_master.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/navigation_controller.h"
+#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/browser/render_process_host.h"
#include "chrome/browser/sessions/session_service.h"
@@ -76,272 +77,6 @@ URLRequestContext* Profile::GetDefaultRequestContext() {
}
-// Sets up proxy info if it was specified, otherwise returns NULL. The
-// returned pointer MUST be deleted by the caller if non-NULL.
-static net::ProxyInfo* CreateProxyInfo(const CommandLine& command_line) {
- net::ProxyInfo* proxy_info = NULL;
-
- if (command_line.HasSwitch(switches::kProxyServer)) {
- proxy_info = new net::ProxyInfo();
- const std::wstring& proxy_server =
- command_line.GetSwitchValue(switches::kProxyServer);
- proxy_info->UseNamedProxy(WideToASCII(proxy_server));
- }
-
- return proxy_info;
-}
-
-// Releases the URLRequestContext and sends out a notification about it.
-// Note: runs on IO thread.
-static void ReleaseURLRequestContext(URLRequestContext* context) {
- NotificationService::current()->Notify(NOTIFY_URL_REQUEST_CONTEXT_RELEASED,
- Source<URLRequestContext>(context),
- NotificationService::NoDetails());
- context->Release();
-}
-
-// A context for URLRequests issued relative to this profile.
-class ProfileImpl::RequestContext : public URLRequestContext,
- public NotificationObserver {
- public:
- // |cookie_store_path| is the local disk path at which the cookie store
- // is persisted.
- RequestContext(const std::wstring& cookie_store_path,
- const std::wstring& disk_cache_path,
- PrefService* prefs)
- : prefs_(prefs) {
- cookie_store_ = NULL;
-
- // setup user agent
- user_agent_ = webkit_glue::GetUserAgent();
- // set up Accept-Language and Accept-Charset header values
- // TODO(jungshik) : This may slow down http requests. Perhaps,
- // we have to come up with a better way to set up these values.
- accept_language_ = WideToASCII(prefs_->GetString(prefs::kAcceptLanguages));
- accept_charset_ = WideToASCII(prefs_->GetString(prefs::kDefaultCharset));
- accept_charset_ += ",*,utf-8";
-
- CommandLine command_line;
-
- scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line));
- proxy_service_ = net::ProxyService::Create(proxy_info.get());
-
- net::HttpCache* cache =
- new net::HttpCache(proxy_service_, disk_cache_path, 0);
-
- bool record_mode = chrome::kRecordModeEnabled &&
- CommandLine().HasSwitch(switches::kRecordMode);
- bool playback_mode = CommandLine().HasSwitch(switches::kPlaybackMode);
-
- if (record_mode || playback_mode) {
- // Don't use existing cookies and use an in-memory store.
- cookie_store_ = new net::CookieMonster();
- cache->set_mode(
- record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK);
- }
- http_transaction_factory_ = cache;
-
- // setup cookie store
- if (!cookie_store_) {
- DCHECK(!cookie_store_path.empty());
- cookie_db_.reset(new SQLitePersistentCookieStore(
- cookie_store_path, g_browser_process->db_thread()->message_loop()));
- cookie_store_ = new net::CookieMonster(cookie_db_.get());
- }
-
- cookie_policy_.SetType(net::CookiePolicy::FromInt(
- prefs_->GetInteger(prefs::kCookieBehavior)));
-
- // The first request context to be created is the one for the default
- // profile - at least until we support multiple profiles.
- if (!default_request_context_)
- default_request_context_ = this;
- NotificationService::current()->Notify(
- NOTIFY_DEFAULT_REQUEST_CONTEXT_AVAILABLE,
- NotificationService::AllSources(), NotificationService::NoDetails());
-
- // Register for notifications about prefs.
- prefs_->AddPrefObserver(prefs::kAcceptLanguages, this);
- prefs_->AddPrefObserver(prefs::kCookieBehavior, this);
- }
-
- // NotificationObserver implementation.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (NOTIFY_PREF_CHANGED == type) {
- std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
- PrefService* prefs = Source<PrefService>(source).ptr();
- DCHECK(pref_name_in && prefs);
- if (*pref_name_in == prefs::kAcceptLanguages) {
- std::string accept_language =
- WideToASCII(prefs->GetString(prefs::kAcceptLanguages));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this,
- &RequestContext::OnAcceptLanguageChange,
- accept_language));
- } else if (*pref_name_in == prefs::kCookieBehavior) {
- net::CookiePolicy::Type type = net::CookiePolicy::FromInt(
- prefs_->GetInteger(prefs::kCookieBehavior));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this,
- &RequestContext::OnCookiePolicyChange,
- type));
- }
- }
- }
-
- // Since ProfileImpl::RequestContext will be destroyed on IO thread, but all
- // PrefService observers are needed to clear in before destroying ProfileImpl.
- // So we use to CleanupBeforeDestroy to do this thing. This function need to
- // be called on destructor of ProfileImpl.
- void CleanupBeforeDestroy() {
- // Unregister for pref notifications.
- prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this);
- prefs_->RemovePrefObserver(prefs::kCookieBehavior, this);
- prefs_ = NULL;
- }
-
- void OnAcceptLanguageChange(std::string accept_language) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
- accept_language_ = accept_language;
- }
-
- void OnCookiePolicyChange(net::CookiePolicy::Type type) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
- cookie_policy_.SetType(type);
- }
-
- virtual ~RequestContext() {
- DCHECK(NULL == prefs_);
- delete cookie_store_;
- delete http_transaction_factory_;
- delete proxy_service_;
-
- if (default_request_context_ == this)
- default_request_context_ = NULL;
- }
-
- private:
- scoped_ptr<SQLitePersistentCookieStore> cookie_db_;
- PrefService* prefs_;
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// An URLRequestContext proxy for OffTheRecord. This request context is
-// really a proxy to the original profile's request context but set
-// is_off_the_record_ to true.
-//
-// TODO(ACW). Do we need to share the FtpAuthCache with the real request context
-// see bug 974328
-//
-// TODO(jackson): http://b/issue?id=1197350 Remove duplicated code from above.
-//
-////////////////////////////////////////////////////////////////////////////////
-class OffTheRecordRequestContext : public URLRequestContext,
- public NotificationObserver {
- public:
- explicit OffTheRecordRequestContext(Profile* profile) {
- DCHECK(!profile->IsOffTheRecord());
- prefs_ = profile->GetPrefs();
- DCHECK(prefs_);
-
- // The OffTheRecordRequestContext is owned by the OffTheRecordProfileImpl
- // which is itself owned by the original profile. We reference the original
- // context to make sure it doesn't go away when we delete the object graph.
- original_context_ = profile->GetRequestContext();
-
- // Share the same proxy service as the original profile. This proxy
- // service's lifespan is dependent on the lifespan of the original profile,
- // which we reference (see above).
- proxy_service_ = original_context_->proxy_service();
-
- http_transaction_factory_ = new net::HttpCache(proxy_service_, 0);
- cookie_store_ = new net::CookieMonster;
- cookie_policy_.SetType(net::CookiePolicy::FromInt(
- prefs_->GetInteger(prefs::kCookieBehavior)));
- user_agent_ = original_context_->user_agent();
- accept_language_ = original_context_->accept_language();
- accept_charset_ = original_context_->accept_charset();
- is_off_the_record_ = true;
-
- // Register for notifications about prefs.
- prefs_->AddPrefObserver(prefs::kAcceptLanguages, this);
- prefs_->AddPrefObserver(prefs::kCookieBehavior, this);
- }
-
- // Since OffTheRecordProfileImpl maybe be destroyed after destroying
- // PrefService, but all PrefService observers are needed to clear in
- // before destroying PrefService. So we use to CleanupBeforeDestroy
- // to do this thing. This function need to be called on destructor
- // of ProfileImpl.
- void CleanupBeforeDestroy() {
- // Unregister for pref notifications.
- prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this);
- prefs_->RemovePrefObserver(prefs::kCookieBehavior, this);
- prefs_ = NULL;
- }
-
- // NotificationObserver implementation.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (NOTIFY_PREF_CHANGED == type) {
- std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
- PrefService* prefs = Source<PrefService>(source).ptr();
- DCHECK(pref_name_in && prefs);
- if (*pref_name_in == prefs::kAcceptLanguages) {
- std::string accept_language =
- WideToASCII(prefs->GetString(prefs::kAcceptLanguages));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(
- this,
- &OffTheRecordRequestContext::OnAcceptLanguageChange,
- accept_language));
- } else if (*pref_name_in == prefs::kCookieBehavior) {
- net::CookiePolicy::Type type = net::CookiePolicy::FromInt(
- prefs_->GetInteger(prefs::kCookieBehavior));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this,
- &OffTheRecordRequestContext::OnCookiePolicyChange,
- type));
- }
- }
- }
-
- void OnAcceptLanguageChange(std::string accept_language) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
- accept_language_ = accept_language;
- }
-
- void OnCookiePolicyChange(net::CookiePolicy::Type type) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
- cookie_policy_.SetType(type);
- }
-
- virtual ~OffTheRecordRequestContext() {
- DCHECK(NULL == prefs_);
- delete cookie_store_;
- delete http_transaction_factory_;
- // NOTE: do not delete |proxy_service_| as is owned by the original profile.
-
- // The OffTheRecordRequestContext simply act as a proxy to the real context.
- // There is nothing else to delete.
- }
-
- private:
- // The original (non off the record) URLRequestContext.
- scoped_refptr<URLRequestContext> original_context_;
- PrefService* prefs_;
-
- DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordRequestContext);
-};
-
////////////////////////////////////////////////////////////////////////////////
//
// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
@@ -354,7 +89,7 @@ class OffTheRecordProfileImpl : public Profile,
explicit OffTheRecordProfileImpl(Profile* real_profile)
: profile_(real_profile),
start_time_(Time::Now()) {
- request_context_ = new OffTheRecordRequestContext(real_profile);
+ request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this);
request_context_->AddRef();
// Register for browser close notifications so we can detect when the last
// off-the-record window is closed, in which case we can clean our states
@@ -365,10 +100,12 @@ class OffTheRecordProfileImpl : public Profile,
virtual ~OffTheRecordProfileImpl() {
if (request_context_) {
- request_context_->CleanupBeforeDestroy();
+ request_context_->CleanupOnUIThread();
+
// Clean up request context on IO thread.
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(&ReleaseURLRequestContext, request_context_));
+ NewRunnableMethod(request_context_,
+ &base::RefCountedThreadSafe<URLRequestContext>::Release));
request_context_ = NULL;
}
NotificationService::current()->RemoveObserver(
@@ -545,8 +282,8 @@ class OffTheRecordProfileImpl : public Profile,
// The real underlying profile.
Profile* profile_;
- // A proxy to the real request context.
- OffTheRecordRequestContext* request_context_;
+ // The context to use for requests made from this OTR session.
+ ChromeURLRequestContext* request_context_;
// The download manager that only stores downloaded items in memory.
scoped_refptr<DownloadManager> download_manager_;
@@ -628,10 +365,15 @@ ProfileImpl::~ProfileImpl() {
}
if (request_context_) {
- request_context_->CleanupBeforeDestroy();
+ request_context_->CleanupOnUIThread();
+
+ if (default_request_context_ == request_context_)
+ default_request_context_ = NULL;
+
// Clean up request context on IO thread.
- io_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(&ReleaseURLRequestContext, request_context_));
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(request_context_,
+ &base::RefCountedThreadSafe<URLRequestContext>::Release));
request_context_ = NULL;
}
@@ -753,10 +495,20 @@ URLRequestContext* ProfileImpl::GetRequestContext() {
file_util::AppendToPath(&cookie_path, chrome::kCookieFilename);
std::wstring cache_path = GetPath();
file_util::AppendToPath(&cache_path, chrome::kCacheDirname);
- request_context_ =
- new ProfileImpl::RequestContext(cookie_path, cache_path, GetPrefs());
+ request_context_ = ChromeURLRequestContext::CreateOriginal(
+ this, cookie_path, cache_path);
request_context_->AddRef();
+ // The first request context is always a normal (non-OTR) request context.
+ // Even when Chromium is started in OTR mode, a normal profile is always
+ // created first.
+ if (!default_request_context_) {
+ default_request_context_ = request_context_;
+ NotificationService::current()->Notify(
+ NOTIFY_DEFAULT_REQUEST_CONTEXT_AVAILABLE,
+ NotificationService::AllSources(), NotificationService::NoDetails());
+ }
+
DCHECK(request_context_->cookie_store());
}
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index c2b88a89..16455c1 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -23,6 +23,7 @@
#include "chrome/common/pref_service.h"
class BookmarkModel;
+class ChromeURLRequestContext;
class DownloadManager;
class ExtensionsService;
class GreasemonkeyMaster;
@@ -294,8 +295,6 @@ class ProfileImpl : public Profile,
const NotificationDetails& details);
private:
- class RequestContext;
-
friend class Profile;
explicit ProfileImpl(const std::wstring& path);
@@ -332,7 +331,7 @@ class ProfileImpl : public Profile,
scoped_ptr<ProfilePersonalization> personalization_;
#endif
- RequestContext* request_context_;
+ ChromeURLRequestContext* request_context_;
scoped_refptr<DownloadManager> download_manager_;
scoped_refptr<HistoryService> history_service_;
diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h
index 5ea25db..ee05c9d 100644
--- a/net/url_request/url_request_context.h
+++ b/net/url_request/url_request_context.h
@@ -31,8 +31,7 @@ class URLRequestContext :
URLRequestContext()
: proxy_service_(NULL),
http_transaction_factory_(NULL),
- cookie_store_(NULL),
- is_off_the_record_(false) {
+ cookie_store_(NULL) {
}
// Get the proxy service for this context.
@@ -63,9 +62,6 @@ class URLRequestContext :
// Gets the value of 'Accept-Language' header field.
const std::string& accept_language() const { return accept_language_; }
- // Returns true if this context is off the record.
- bool is_off_the_record() { return is_off_the_record_; }
-
// Do not call this directly. TODO(darin): extending from RefCounted* should
// not require a public destructor!
virtual ~URLRequestContext() {}
@@ -79,7 +75,6 @@ class URLRequestContext :
net::CookiePolicy cookie_policy_;
net::AuthCache ftp_auth_cache_;
std::string user_agent_;
- bool is_off_the_record_;
std::string accept_language_;
std::string accept_charset_;