OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 116 matching lines...) Loading... |
127 static void CleanupRequestContext(ChromeURLRequestContext* context) { | 127 static void CleanupRequestContext(ChromeURLRequestContext* context) { |
128 if (context) { | 128 if (context) { |
129 context->CleanupOnUIThread(); | 129 context->CleanupOnUIThread(); |
130 | 130 |
131 // Clean up request context on IO thread. | 131 // Clean up request context on IO thread. |
132 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE, | 132 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE, |
133 context); | 133 context); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 static void CleanupAppCacheService(ChromeAppCacheService* service) { | 137 static void CleanupAppCacheService(ChromeAppCacheService* appcache_service) { |
138 if (service) { | 138 if (appcache_service) { |
139 MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO); | 139 // The I/O thread may be NULL during testing. |
| 140 base::Thread* io_thread = g_browser_process->io_thread(); |
140 if (io_thread) | 141 if (io_thread) |
141 io_thread->ReleaseSoon(FROM_HERE, service); | 142 io_thread->message_loop()->ReleaseSoon(FROM_HERE, appcache_service); |
142 else | 143 else |
143 service->Release(); | 144 appcache_service->Release(); |
144 } | 145 } |
145 } | 146 } |
146 | 147 |
147 // static | 148 // static |
148 void Profile::RegisterUserPrefs(PrefService* prefs) { | 149 void Profile::RegisterUserPrefs(PrefService* prefs) { |
149 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); | 150 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); |
150 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); | 151 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); |
151 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); | 152 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); |
152 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string. | 153 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string. |
153 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, | 154 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, |
(...skipping 42 matching lines...) Loading... |
196 // to make it suitable for the off the record mode. | 197 // to make it suitable for the off the record mode. |
197 // | 198 // |
198 //////////////////////////////////////////////////////////////////////////////// | 199 //////////////////////////////////////////////////////////////////////////////// |
199 class OffTheRecordProfileImpl : public Profile, | 200 class OffTheRecordProfileImpl : public Profile, |
200 public NotificationObserver { | 201 public NotificationObserver { |
201 public: | 202 public: |
202 explicit OffTheRecordProfileImpl(Profile* real_profile) | 203 explicit OffTheRecordProfileImpl(Profile* real_profile) |
203 : profile_(real_profile), | 204 : profile_(real_profile), |
204 extensions_request_context_(NULL), | 205 extensions_request_context_(NULL), |
205 start_time_(Time::Now()) { | 206 start_time_(Time::Now()) { |
206 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); | 207 // Created here but lazily inititialized later, finally released on |
| 208 // on the io thread, see CleanupAppCacheService. |
| 209 appcache_service_ = new ChromeAppCacheService(); |
| 210 appcache_service_->AddRef(); |
| 211 |
| 212 request_context_ = ChromeURLRequestContext::CreateOffTheRecord( |
| 213 this, appcache_service_); |
207 request_context_->AddRef(); | 214 request_context_->AddRef(); |
208 | 215 |
209 // Register for browser close notifications so we can detect when the last | 216 // Register for browser close notifications so we can detect when the last |
210 // off-the-record window is closed, in which case we can clean our states | 217 // off-the-record window is closed, in which case we can clean our states |
211 // (cookies, downloads...). | 218 // (cookies, downloads...). |
212 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 219 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
213 NotificationService::AllSources()); | 220 NotificationService::AllSources()); |
214 } | 221 } |
215 | 222 |
216 virtual ~OffTheRecordProfileImpl() { | 223 virtual ~OffTheRecordProfileImpl() { |
217 CleanupRequestContext(request_context_); | 224 CleanupRequestContext(request_context_); |
218 CleanupRequestContext(extensions_request_context_); | 225 CleanupRequestContext(extensions_request_context_); |
219 CleanupAppCacheService(appcache_service_.release()); | 226 CleanupAppCacheService(appcache_service_); |
220 } | 227 } |
221 | 228 |
222 virtual FilePath GetPath() { return profile_->GetPath(); } | 229 virtual FilePath GetPath() { return profile_->GetPath(); } |
223 | 230 |
224 virtual bool IsOffTheRecord() { | 231 virtual bool IsOffTheRecord() { |
225 return true; | 232 return true; |
226 } | 233 } |
227 | 234 |
228 virtual Profile* GetOffTheRecordProfile() { | 235 virtual Profile* GetOffTheRecordProfile() { |
229 return this; | 236 return this; |
230 } | 237 } |
231 | 238 |
232 virtual void DestroyOffTheRecordProfile() { | 239 virtual void DestroyOffTheRecordProfile() { |
233 // Suicide is bad! | 240 // Suicide is bad! |
234 NOTREACHED(); | 241 NOTREACHED(); |
235 } | 242 } |
236 | 243 |
237 virtual Profile* GetOriginalProfile() { | 244 virtual Profile* GetOriginalProfile() { |
238 return profile_; | 245 return profile_; |
239 } | 246 } |
240 | 247 |
241 virtual ChromeAppCacheService* GetAppCacheService() { | 248 virtual ChromeAppCacheService* GetAppCacheService() { |
242 if (!appcache_service_.get()) { | 249 DCHECK(request_context_); // should be created in ctor |
243 appcache_service_ = new ChromeAppCacheService(); | 250 if (!appcache_service_->is_initialized()) |
244 appcache_service_->InitializeOnUIThread( | 251 appcache_service_->InitializeOnUIThread(GetPath(), true); |
245 GetPath(), GetRequestContext(), true); | 252 return appcache_service_; |
246 } | |
247 return appcache_service_.get(); | |
248 } | 253 } |
249 | 254 |
250 virtual VisitedLinkMaster* GetVisitedLinkMaster() { | 255 virtual VisitedLinkMaster* GetVisitedLinkMaster() { |
251 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord | 256 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord |
252 // because we don't want to leak the sites that the user has visited before. | 257 // because we don't want to leak the sites that the user has visited before. |
253 return NULL; | 258 return NULL; |
254 } | 259 } |
255 | 260 |
256 virtual ExtensionsService* GetExtensionsService() { | 261 virtual ExtensionsService* GetExtensionsService() { |
257 return NULL; | 262 return NULL; |
(...skipping 261 matching lines...) Loading... |
519 | 524 |
520 // The real underlying profile. | 525 // The real underlying profile. |
521 Profile* profile_; | 526 Profile* profile_; |
522 | 527 |
523 // The context to use for requests made from this OTR session. | 528 // The context to use for requests made from this OTR session. |
524 ChromeURLRequestContext* request_context_; | 529 ChromeURLRequestContext* request_context_; |
525 | 530 |
526 ChromeURLRequestContext* extensions_request_context_; | 531 ChromeURLRequestContext* extensions_request_context_; |
527 | 532 |
528 // Use a seperate appcache service for OTR. | 533 // Use a seperate appcache service for OTR. |
529 scoped_refptr<ChromeAppCacheService> appcache_service_; | 534 ChromeAppCacheService* appcache_service_; |
530 | 535 |
531 // The download manager that only stores downloaded items in memory. | 536 // The download manager that only stores downloaded items in memory. |
532 scoped_refptr<DownloadManager> download_manager_; | 537 scoped_refptr<DownloadManager> download_manager_; |
533 | 538 |
534 scoped_refptr<BrowserThemeProvider> theme_provider_; | 539 scoped_refptr<BrowserThemeProvider> theme_provider_; |
535 | 540 |
536 // Use a special WebKit context for OTR browsing. | 541 // Use a special WebKit context for OTR browsing. |
537 scoped_refptr<WebKitContext> webkit_context_; | 542 scoped_refptr<WebKitContext> webkit_context_; |
538 | 543 |
539 // We don't want SSLHostState from the OTR profile to leak back to the main | 544 // We don't want SSLHostState from the OTR profile to leak back to the main |
(...skipping 32 matching lines...) Loading... |
572 "profile files to the root directory!"; | 577 "profile files to the root directory!"; |
573 create_session_service_timer_.Start( | 578 create_session_service_timer_.Start( |
574 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 579 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
575 &ProfileImpl::EnsureSessionServiceCreated); | 580 &ProfileImpl::EnsureSessionServiceCreated); |
576 | 581 |
577 if (CommandLine::ForCurrentProcess()->HasSwitch( | 582 if (CommandLine::ForCurrentProcess()->HasSwitch( |
578 switches::kEnableExtensionTimelineApi)) { | 583 switches::kEnableExtensionTimelineApi)) { |
579 extension_devtools_manager_ = new ExtensionDevToolsManager(this); | 584 extension_devtools_manager_ = new ExtensionDevToolsManager(this); |
580 } | 585 } |
581 | 586 |
| 587 // Created here but lazily inititialized later, finally released on |
| 588 // on the io thread, see CleanupAppCacheService. |
| 589 appcache_service_ = new ChromeAppCacheService(); |
| 590 appcache_service_->AddRef(); |
| 591 |
582 extension_process_manager_.reset(new ExtensionProcessManager(this)); | 592 extension_process_manager_.reset(new ExtensionProcessManager(this)); |
583 extension_message_service_ = new ExtensionMessageService(this); | 593 extension_message_service_ = new ExtensionMessageService(this); |
584 | 594 |
585 PrefService* prefs = GetPrefs(); | 595 PrefService* prefs = GetPrefs(); |
586 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this); | 596 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this); |
587 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); | 597 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); |
588 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this); | 598 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this); |
589 | 599 |
590 if (CommandLine::ForCurrentProcess()-> | 600 if (CommandLine::ForCurrentProcess()-> |
591 HasSwitch(switches::kPrivacyBlacklist)) { | 601 HasSwitch(switches::kPrivacyBlacklist)) { |
(...skipping 170 matching lines...) Loading... |
762 // We use default_request_context_ for OCSP. | 772 // We use default_request_context_ for OCSP. |
763 // Release URLRequestContext used in OCSP handlers. | 773 // Release URLRequestContext used in OCSP handlers. |
764 net::SetURLRequestContextForOCSP(NULL); | 774 net::SetURLRequestContextForOCSP(NULL); |
765 #endif | 775 #endif |
766 default_request_context_ = NULL; | 776 default_request_context_ = NULL; |
767 } | 777 } |
768 | 778 |
769 CleanupRequestContext(request_context_); | 779 CleanupRequestContext(request_context_); |
770 CleanupRequestContext(media_request_context_); | 780 CleanupRequestContext(media_request_context_); |
771 CleanupRequestContext(extensions_request_context_); | 781 CleanupRequestContext(extensions_request_context_); |
772 CleanupAppCacheService(appcache_service_.release()); | 782 CleanupAppCacheService(appcache_service_); |
773 | 783 |
774 // When the request contexts are gone, the blacklist wont be needed anymore. | 784 // When the request contexts are gone, the blacklist wont be needed anymore. |
775 delete blacklist_; | 785 delete blacklist_; |
776 blacklist_ = 0; | 786 blacklist_ = 0; |
777 | 787 |
778 // HistoryService may call into the BookmarkModel, as such we need to | 788 // HistoryService may call into the BookmarkModel, as such we need to |
779 // delete HistoryService before the BookmarkModel. The destructor for | 789 // delete HistoryService before the BookmarkModel. The destructor for |
780 // HistoryService will join with HistoryService's backend thread so that | 790 // HistoryService will join with HistoryService's backend thread so that |
781 // by the time the destructor has finished we're sure it will no longer call | 791 // by the time the destructor has finished we're sure it will no longer call |
782 // into the BookmarkModel. | 792 // into the BookmarkModel. |
(...skipping 30 matching lines...) Loading... |
813 | 823 |
814 void ProfileImpl::DestroyOffTheRecordProfile() { | 824 void ProfileImpl::DestroyOffTheRecordProfile() { |
815 off_the_record_profile_.reset(); | 825 off_the_record_profile_.reset(); |
816 } | 826 } |
817 | 827 |
818 Profile* ProfileImpl::GetOriginalProfile() { | 828 Profile* ProfileImpl::GetOriginalProfile() { |
819 return this; | 829 return this; |
820 } | 830 } |
821 | 831 |
822 ChromeAppCacheService* ProfileImpl::GetAppCacheService() { | 832 ChromeAppCacheService* ProfileImpl::GetAppCacheService() { |
823 if (!appcache_service_.get()) { | 833 if (!appcache_service_->is_initialized()) { |
824 appcache_service_ = new ChromeAppCacheService(); | 834 EnsureRequestContextCreated(); |
825 appcache_service_->InitializeOnUIThread( | 835 appcache_service_->InitializeOnUIThread(GetPath(), false); |
826 GetPath(), GetRequestContext(), false); | |
827 } | 836 } |
828 return appcache_service_.get(); | 837 return appcache_service_; |
829 } | 838 } |
830 | 839 |
831 VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { | 840 VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { |
832 if (!visited_link_master_.get()) { | 841 if (!visited_link_master_.get()) { |
833 scoped_ptr<VisitedLinkMaster> visited_links( | 842 scoped_ptr<VisitedLinkMaster> visited_links( |
834 new VisitedLinkMaster(g_browser_process->file_thread(), | 843 new VisitedLinkMaster(g_browser_process->file_thread(), |
835 visited_link_event_listener_.get(), this)); | 844 visited_link_event_listener_.get(), this)); |
836 if (!visited_links->Init()) | 845 if (!visited_links->Init()) |
837 return NULL; | 846 return NULL; |
838 visited_link_master_.swap(visited_links); | 847 visited_link_master_.swap(visited_links); |
(...skipping 80 matching lines...) Loading... |
919 URLRequestContext* ProfileImpl::GetRequestContext() { | 928 URLRequestContext* ProfileImpl::GetRequestContext() { |
920 if (!request_context_) { | 929 if (!request_context_) { |
921 FilePath cookie_path = GetPath(); | 930 FilePath cookie_path = GetPath(); |
922 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 931 cookie_path = cookie_path.Append(chrome::kCookieFilename); |
923 FilePath cache_path = base_cache_path_; | 932 FilePath cache_path = base_cache_path_; |
924 int max_size; | 933 int max_size; |
925 GetCacheParameters(kNormalContext, &cache_path, &max_size); | 934 GetCacheParameters(kNormalContext, &cache_path, &max_size); |
926 | 935 |
927 cache_path = GetCachePath(cache_path); | 936 cache_path = GetCachePath(cache_path); |
928 request_context_ = ChromeURLRequestContext::CreateOriginal( | 937 request_context_ = ChromeURLRequestContext::CreateOriginal( |
929 this, cookie_path, cache_path, max_size); | 938 this, cookie_path, cache_path, max_size, appcache_service_); |
930 request_context_->AddRef(); | 939 request_context_->AddRef(); |
931 | 940 |
932 // The first request context is always a normal (non-OTR) request context. | 941 // The first request context is always a normal (non-OTR) request context. |
933 // Even when Chromium is started in OTR mode, a normal profile is always | 942 // Even when Chromium is started in OTR mode, a normal profile is always |
934 // created first. | 943 // created first. |
935 if (!default_request_context_) { | 944 if (!default_request_context_) { |
936 default_request_context_ = request_context_; | 945 default_request_context_ = request_context_; |
937 NotificationService::current()->Notify( | 946 NotificationService::current()->Notify( |
938 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 947 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
939 NotificationService::AllSources(), NotificationService::NoDetails()); | 948 NotificationService::AllSources(), NotificationService::NoDetails()); |
(...skipping 10 matching lines...) Loading... |
950 } | 959 } |
951 | 960 |
952 URLRequestContext* ProfileImpl::GetRequestContextForMedia() { | 961 URLRequestContext* ProfileImpl::GetRequestContextForMedia() { |
953 if (!media_request_context_) { | 962 if (!media_request_context_) { |
954 FilePath cache_path = base_cache_path_; | 963 FilePath cache_path = base_cache_path_; |
955 int max_size; | 964 int max_size; |
956 GetCacheParameters(kMediaContext, &cache_path, &max_size); | 965 GetCacheParameters(kMediaContext, &cache_path, &max_size); |
957 | 966 |
958 cache_path = GetMediaCachePath(cache_path); | 967 cache_path = GetMediaCachePath(cache_path); |
959 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( | 968 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( |
960 this, cache_path, max_size); | 969 this, cache_path, max_size, appcache_service_); |
961 media_request_context_->AddRef(); | 970 media_request_context_->AddRef(); |
962 | 971 |
963 DCHECK(media_request_context_->cookie_store()); | 972 DCHECK(media_request_context_->cookie_store()); |
964 } | 973 } |
965 | 974 |
966 return media_request_context_; | 975 return media_request_context_; |
967 } | 976 } |
968 | 977 |
969 FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) { | 978 FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) { |
970 if (!favicon_service_created_) { | 979 if (!favicon_service_created_) { |
(...skipping 399 matching lines...) Loading... |
1370 #endif | 1379 #endif |
1371 return NULL; | 1380 return NULL; |
1372 } | 1381 } |
1373 | 1382 |
1374 void ProfileImpl::InitSyncService() { | 1383 void ProfileImpl::InitSyncService() { |
1375 #ifdef CHROME_PERSONALIZATION | 1384 #ifdef CHROME_PERSONALIZATION |
1376 sync_service_.reset(new ProfileSyncService(this)); | 1385 sync_service_.reset(new ProfileSyncService(this)); |
1377 sync_service_->Initialize(); | 1386 sync_service_->Initialize(); |
1378 #endif | 1387 #endif |
1379 } | 1388 } |
OLD | NEW |