Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: chrome/browser/profile.cc

Issue 332006: Remove the restriction that ChromeURLRequestContextGetter needs to be release... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to latest changes Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profile.h ('k') | chrome/browser/sync/glue/http_bridge.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/profile.h" 5 #include "chrome/browser/profile.h"
6 6
7 #include "app/theme_provider.h" 7 #include "app/theme_provider.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 file_util::PathExists(GetMediaCachePath(dir)); 122 file_util::PathExists(GetMediaCachePath(dir));
123 } 123 }
124 124
125 } // namespace 125 } // namespace
126 126
127 // A pointer to the request context for the default profile. See comments on 127 // A pointer to the request context for the default profile. See comments on
128 // Profile::GetDefaultRequestContext. 128 // Profile::GetDefaultRequestContext.
129 URLRequestContextGetter* Profile::default_request_context_; 129 URLRequestContextGetter* Profile::default_request_context_;
130 130
131 static void CleanupRequestContext(ChromeURLRequestContextGetter* context) { 131 static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
132 if (context) { 132 if (context)
133 context->CleanupOnUIThread(); 133 context->CleanupOnUIThread();
134
135 // Clean up request context on IO thread.
136 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, context);
137 }
138 } 134 }
139 135
140 // static 136 // static
141 const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0); 137 const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
142 138
143 // static 139 // static
144 void Profile::RegisterUserPrefs(PrefService* prefs) { 140 void Profile::RegisterUserPrefs(PrefService* prefs) {
145 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); 141 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
146 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); 142 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
147 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); 143 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // 189 //
194 //////////////////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////////////////
195 class OffTheRecordProfileImpl : public Profile, 191 class OffTheRecordProfileImpl : public Profile,
196 public NotificationObserver { 192 public NotificationObserver {
197 public: 193 public:
198 explicit OffTheRecordProfileImpl(Profile* real_profile) 194 explicit OffTheRecordProfileImpl(Profile* real_profile)
199 : profile_(real_profile), 195 : profile_(real_profile),
200 extensions_request_context_(NULL), 196 extensions_request_context_(NULL),
201 start_time_(Time::Now()) { 197 start_time_(Time::Now()) {
202 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this); 198 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
203 request_context_->AddRef();
204 199
205 // Register for browser close notifications so we can detect when the last 200 // Register for browser close notifications so we can detect when the last
206 // off-the-record window is closed, in which case we can clean our states 201 // off-the-record window is closed, in which case we can clean our states
207 // (cookies, downloads...). 202 // (cookies, downloads...).
208 registrar_.Add(this, NotificationType::BROWSER_CLOSED, 203 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
209 NotificationService::AllSources()); 204 NotificationService::AllSources());
210 } 205 }
211 206
212 virtual ~OffTheRecordProfileImpl() { 207 virtual ~OffTheRecordProfileImpl() {
213 CleanupRequestContext(request_context_); 208 CleanupRequestContext(request_context_);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 388
394 virtual URLRequestContextGetter* GetRequestContextForMedia() { 389 virtual URLRequestContextGetter* GetRequestContextForMedia() {
395 // In OTR mode, media request context is the same as the original one. 390 // In OTR mode, media request context is the same as the original one.
396 return request_context_; 391 return request_context_;
397 } 392 }
398 393
399 URLRequestContextGetter* GetRequestContextForExtensions() { 394 URLRequestContextGetter* GetRequestContextForExtensions() {
400 if (!extensions_request_context_) { 395 if (!extensions_request_context_) {
401 extensions_request_context_ = 396 extensions_request_context_ =
402 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this); 397 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
403 extensions_request_context_->AddRef();
404 } 398 }
405 399
406 return extensions_request_context_; 400 return extensions_request_context_;
407 } 401 }
408 402
409 virtual net::SSLConfigService* GetSSLConfigService() { 403 virtual net::SSLConfigService* GetSSLConfigService() {
410 return GetOriginalProfile()->GetSSLConfigService(); 404 return GetOriginalProfile()->GetSSLConfigService();
411 } 405 }
412 406
413 virtual Blacklist* GetBlacklist() { 407 virtual Blacklist* GetBlacklist() {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 ExitedOffTheRecordMode(); 536 ExitedOffTheRecordMode();
543 } 537 }
544 538
545 private: 539 private:
546 NotificationRegistrar registrar_; 540 NotificationRegistrar registrar_;
547 541
548 // The real underlying profile. 542 // The real underlying profile.
549 Profile* profile_; 543 Profile* profile_;
550 544
551 // The context to use for requests made from this OTR session. 545 // The context to use for requests made from this OTR session.
552 ChromeURLRequestContextGetter* request_context_; 546 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
553 547
554 ChromeURLRequestContextGetter* extensions_request_context_; 548 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
555 549
556 // The download manager that only stores downloaded items in memory. 550 // The download manager that only stores downloaded items in memory.
557 scoped_refptr<DownloadManager> download_manager_; 551 scoped_refptr<DownloadManager> download_manager_;
558 552
559 // Use a special WebKit context for OTR browsing. 553 // Use a special WebKit context for OTR browsing.
560 scoped_refptr<WebKitContext> webkit_context_; 554 scoped_refptr<WebKitContext> webkit_context_;
561 555
562 // We don't want SSLHostState from the OTR profile to leak back to the main 556 // We don't want SSLHostState from the OTR profile to leak back to the main
563 // profile because then the main profile would learn some of the host names 557 // profile because then the main profile would learn some of the host names
564 // the user visited while OTR. 558 // the user visited while OTR.
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 if (!request_context_) { 925 if (!request_context_) {
932 FilePath cookie_path = GetPath(); 926 FilePath cookie_path = GetPath();
933 cookie_path = cookie_path.Append(chrome::kCookieFilename); 927 cookie_path = cookie_path.Append(chrome::kCookieFilename);
934 FilePath cache_path = base_cache_path_; 928 FilePath cache_path = base_cache_path_;
935 int max_size; 929 int max_size;
936 GetCacheParameters(kNormalContext, &cache_path, &max_size); 930 GetCacheParameters(kNormalContext, &cache_path, &max_size);
937 931
938 cache_path = GetCachePath(cache_path); 932 cache_path = GetCachePath(cache_path);
939 request_context_ = ChromeURLRequestContextGetter::CreateOriginal( 933 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
940 this, cookie_path, cache_path, max_size); 934 this, cookie_path, cache_path, max_size);
941 request_context_->AddRef();
942 935
943 // The first request context is always a normal (non-OTR) request context. 936 // The first request context is always a normal (non-OTR) request context.
944 // Even when Chromium is started in OTR mode, a normal profile is always 937 // Even when Chromium is started in OTR mode, a normal profile is always
945 // created first. 938 // created first.
946 if (!default_request_context_) { 939 if (!default_request_context_) {
947 default_request_context_ = request_context_; 940 default_request_context_ = request_context_;
948 // TODO(eroman): this isn't terribly useful anymore now that the 941 // TODO(eroman): this isn't terribly useful anymore now that the
949 // URLRequestContext is constructed by the IO thread... 942 // URLRequestContext is constructed by the IO thread...
950 NotificationService::current()->Notify( 943 NotificationService::current()->Notify(
951 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, 944 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
952 NotificationService::AllSources(), NotificationService::NoDetails()); 945 NotificationService::AllSources(), NotificationService::NoDetails());
953 } 946 }
954 } 947 }
955 948
956 return request_context_; 949 return request_context_;
957 } 950 }
958 951
959 URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() { 952 URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
960 if (!media_request_context_) { 953 if (!media_request_context_) {
961 FilePath cache_path = base_cache_path_; 954 FilePath cache_path = base_cache_path_;
962 int max_size; 955 int max_size;
963 GetCacheParameters(kMediaContext, &cache_path, &max_size); 956 GetCacheParameters(kMediaContext, &cache_path, &max_size);
964 957
965 cache_path = GetMediaCachePath(cache_path); 958 cache_path = GetMediaCachePath(cache_path);
966 media_request_context_ = 959 media_request_context_ =
967 ChromeURLRequestContextGetter::CreateOriginalForMedia( 960 ChromeURLRequestContextGetter::CreateOriginalForMedia(
968 this, cache_path, max_size); 961 this, cache_path, max_size);
969 media_request_context_->AddRef();
970 } 962 }
971 963
972 return media_request_context_; 964 return media_request_context_;
973 } 965 }
974 966
975 FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) { 967 FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
976 if (!favicon_service_created_) { 968 if (!favicon_service_created_) {
977 favicon_service_created_ = true; 969 favicon_service_created_ = true;
978 scoped_refptr<FaviconService> service(new FaviconService(this)); 970 scoped_refptr<FaviconService> service(new FaviconService(this));
979 favicon_service_.swap(service); 971 favicon_service_.swap(service);
980 } 972 }
981 return favicon_service_.get(); 973 return favicon_service_.get();
982 } 974 }
983 975
984 URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() { 976 URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
985 if (!extensions_request_context_) { 977 if (!extensions_request_context_) {
986 FilePath cookie_path = GetPath(); 978 FilePath cookie_path = GetPath();
987 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename); 979 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
988 980
989 extensions_request_context_ = 981 extensions_request_context_ =
990 ChromeURLRequestContextGetter::CreateOriginalForExtensions( 982 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
991 this, cookie_path); 983 this, cookie_path);
992 extensions_request_context_->AddRef();
993 } 984 }
994 985
995 return extensions_request_context_; 986 return extensions_request_context_;
996 } 987 }
997 988
998 net::SSLConfigService* ProfileImpl::GetSSLConfigService() { 989 net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
999 return ssl_config_service_manager_->Get(); 990 return ssl_config_service_manager_->Get();
1000 } 991 }
1001 992
1002 Blacklist* ProfileImpl::GetBlacklist() { 993 Blacklist* ProfileImpl::GetBlacklist() {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1432 }
1442 if (!sync_service_.get()) 1433 if (!sync_service_.get())
1443 InitSyncService(); 1434 InitSyncService();
1444 return sync_service_.get(); 1435 return sync_service_.get();
1445 } 1436 }
1446 1437
1447 void ProfileImpl::InitSyncService() { 1438 void ProfileImpl::InitSyncService() {
1448 sync_service_.reset(new ProfileSyncService(this)); 1439 sync_service_.reset(new ProfileSyncService(this));
1449 sync_service_->Initialize(); 1440 sync_service_->Initialize();
1450 } 1441 }
OLDNEW
« no previous file with comments | « chrome/browser/profile.h ('k') | chrome/browser/sync/glue/http_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698