OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/off_the_record_profile_impl.h" | 5 #include "chrome/browser/profiles/off_the_record_profile_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/background/background_contents_service_factory.h" | 15 #include "chrome/browser/background/background_contents_service_factory.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_plugin_service_filter.h" | 17 #include "chrome/browser/chrome_plugin_service_filter.h" |
18 #include "chrome/browser/content_settings/host_content_settings_map.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 19 #include "chrome/browser/download/download_service.h" |
| 20 #include "chrome/browser/download/download_service_factory.h" |
19 #include "chrome/browser/extensions/extension_info_map.h" | 21 #include "chrome/browser/extensions/extension_info_map.h" |
20 #include "chrome/browser/extensions/extension_message_service.h" | 22 #include "chrome/browser/extensions/extension_message_service.h" |
21 #include "chrome/browser/extensions/extension_pref_store.h" | 23 #include "chrome/browser/extensions/extension_pref_store.h" |
22 #include "chrome/browser/extensions/extension_process_manager.h" | 24 #include "chrome/browser/extensions/extension_process_manager.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 25 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 26 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
25 #include "chrome/browser/extensions/extension_webrequest_api.h" | 27 #include "chrome/browser/extensions/extension_webrequest_api.h" |
26 #include "chrome/browser/net/pref_proxy_config_service.h" | 28 #include "chrome/browser/net/pref_proxy_config_service.h" |
27 #include "chrome/browser/plugin_prefs.h" | 29 #include "chrome/browser/plugin_prefs.h" |
28 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 30 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
29 #include "chrome/browser/prefs/pref_service.h" | 31 #include "chrome/browser/prefs/pref_service.h" |
30 #include "chrome/browser/profiles/profile_dependency_manager.h" | 32 #include "chrome/browser/profiles/profile_dependency_manager.h" |
31 #include "chrome/browser/sync/profile_sync_service.h" | 33 #include "chrome/browser/sync/profile_sync_service.h" |
32 #include "chrome/browser/themes/theme_service.h" | 34 #include "chrome/browser/themes/theme_service.h" |
33 #include "chrome/browser/transport_security_persister.h" | 35 #include "chrome/browser/transport_security_persister.h" |
34 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 36 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
35 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 37 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
36 #include "chrome/browser/ui/webui/extension_icon_source.h" | 38 #include "chrome/browser/ui/webui/extension_icon_source.h" |
37 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
38 #include "chrome/common/chrome_notification_types.h" | 40 #include "chrome/common/chrome_notification_types.h" |
39 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
40 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
41 #include "chrome/common/extensions/extension.h" | 43 #include "chrome/common/extensions/extension.h" |
42 #include "chrome/common/json_pref_store.h" | 44 #include "chrome/common/json_pref_store.h" |
43 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
44 #include "chrome/common/render_messages.h" | 46 #include "chrome/common/render_messages.h" |
45 #include "content/browser/appcache/chrome_appcache_service.h" | 47 #include "content/browser/appcache/chrome_appcache_service.h" |
46 #include "content/browser/browser_thread.h" | 48 #include "content/browser/browser_thread.h" |
47 #include "content/browser/chrome_blob_storage_context.h" | 49 #include "content/browser/chrome_blob_storage_context.h" |
48 #include "content/browser/download/download_manager.h" | |
49 #include "content/browser/file_system/browser_file_system_helper.h" | 50 #include "content/browser/file_system/browser_file_system_helper.h" |
50 #include "content/browser/host_zoom_map.h" | 51 #include "content/browser/host_zoom_map.h" |
51 #include "content/browser/in_process_webkit/webkit_context.h" | 52 #include "content/browser/in_process_webkit/webkit_context.h" |
52 #include "content/browser/ssl/ssl_host_state.h" | 53 #include "content/browser/ssl/ssl_host_state.h" |
53 #include "content/browser/tab_contents/tab_contents.h" | 54 #include "content/browser/tab_contents/tab_contents.h" |
54 #include "content/common/notification_service.h" | 55 #include "content/common/notification_service.h" |
55 #include "net/base/transport_security_state.h" | 56 #include "net/base/transport_security_state.h" |
56 #include "webkit/database/database_tracker.h" | 57 #include "webkit/database/database_tracker.h" |
57 #include "webkit/quota/quota_manager.h" | 58 #include "webkit/quota/quota_manager.h" |
58 | 59 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( | 109 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( |
109 PluginPrefs::GetForProfile(this), &GetResourceContext()); | 110 PluginPrefs::GetForProfile(this), &GetResourceContext()); |
110 | 111 |
111 BrowserThread::PostTask( | 112 BrowserThread::PostTask( |
112 BrowserThread::IO, FROM_HERE, | 113 BrowserThread::IO, FROM_HERE, |
113 NewRunnableFunction( | 114 NewRunnableFunction( |
114 &NotifyOTRProfileCreatedOnIOThread, profile_, this)); | 115 &NotifyOTRProfileCreatedOnIOThread, profile_, this)); |
115 } | 116 } |
116 | 117 |
117 OffTheRecordProfileImpl::~OffTheRecordProfileImpl() { | 118 OffTheRecordProfileImpl::~OffTheRecordProfileImpl() { |
118 // Shutdown the DownloadManager here in the dtor as ProfileImpl does to | |
119 // guarantee that it happens before the last scoped_refptr<DM> is reaped. | |
120 // DownloadManager is lazily created, so check before accessing it. | |
121 if (download_manager_.get()) { | |
122 // Drop our download manager so we forget about all the downloads made | |
123 // in incognito mode. | |
124 download_manager_->Shutdown(); | |
125 download_manager_ = NULL; | |
126 } | |
127 | |
128 NotificationService::current()->Notify( | 119 NotificationService::current()->Notify( |
129 chrome::NOTIFICATION_PROFILE_DESTROYED, Source<Profile>(this), | 120 chrome::NOTIFICATION_PROFILE_DESTROYED, Source<Profile>(this), |
130 NotificationService::NoDetails()); | 121 NotificationService::NoDetails()); |
131 | 122 |
132 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( | 123 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( |
133 &GetResourceContext()); | 124 &GetResourceContext()); |
134 | 125 |
135 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 126 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); |
136 | 127 |
137 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 300 |
310 PrefService* OffTheRecordProfileImpl::GetOffTheRecordPrefs() { | 301 PrefService* OffTheRecordProfileImpl::GetOffTheRecordPrefs() { |
311 return prefs_; | 302 return prefs_; |
312 } | 303 } |
313 | 304 |
314 TemplateURLFetcher* OffTheRecordProfileImpl::GetTemplateURLFetcher() { | 305 TemplateURLFetcher* OffTheRecordProfileImpl::GetTemplateURLFetcher() { |
315 return profile_->GetTemplateURLFetcher(); | 306 return profile_->GetTemplateURLFetcher(); |
316 } | 307 } |
317 | 308 |
318 DownloadManager* OffTheRecordProfileImpl::GetDownloadManager() { | 309 DownloadManager* OffTheRecordProfileImpl::GetDownloadManager() { |
319 if (!download_manager_.get()) { | 310 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); |
320 // In case the delegate has already been set by | |
321 // SetDownloadManagerDelegate. | |
322 if (!download_manager_delegate_.get()) | |
323 download_manager_delegate_ = new ChromeDownloadManagerDelegate(this); | |
324 scoped_refptr<DownloadManager> dlm( | |
325 new DownloadManager(download_manager_delegate_, | |
326 g_browser_process->download_status_updater())); | |
327 dlm->Init(this); | |
328 download_manager_delegate_->SetDownloadManager(dlm); | |
329 download_manager_.swap(dlm); | |
330 } | |
331 return download_manager_.get(); | |
332 } | |
333 | |
334 bool OffTheRecordProfileImpl::HasCreatedDownloadManager() const { | |
335 return download_manager_.get() != NULL; | |
336 } | 311 } |
337 | 312 |
338 fileapi::FileSystemContext* OffTheRecordProfileImpl::GetFileSystemContext() { | 313 fileapi::FileSystemContext* OffTheRecordProfileImpl::GetFileSystemContext() { |
339 CreateQuotaManagerAndClients(); | 314 CreateQuotaManagerAndClients(); |
340 return file_system_context_.get(); | 315 return file_system_context_.get(); |
341 } | 316 } |
342 | 317 |
343 net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { | 318 net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { |
344 return io_data_.GetMainRequestContextGetter(); | 319 return io_data_.GetMainRequestContextGetter(); |
345 } | 320 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 const NotificationDetails& details) { | 576 const NotificationDetails& details) { |
602 if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { | 577 if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { |
603 const std::string& host = *(Details<const std::string>(details).ptr()); | 578 const std::string& host = *(Details<const std::string>(details).ptr()); |
604 if (!host.empty()) { | 579 if (!host.empty()) { |
605 double level = profile_->GetHostZoomMap()->GetZoomLevel(host); | 580 double level = profile_->GetHostZoomMap()->GetZoomLevel(host); |
606 GetHostZoomMap()->SetZoomLevel(host, level); | 581 GetHostZoomMap()->SetZoomLevel(host, level); |
607 } | 582 } |
608 } | 583 } |
609 } | 584 } |
610 | 585 |
611 void OffTheRecordProfileImpl::SetDownloadManagerDelegate( | |
612 ChromeDownloadManagerDelegate* delegate) { | |
613 download_manager_delegate_ = delegate; | |
614 } | |
615 | |
616 void OffTheRecordProfileImpl::CreateQuotaManagerAndClients() { | 586 void OffTheRecordProfileImpl::CreateQuotaManagerAndClients() { |
617 if (quota_manager_.get()) { | 587 if (quota_manager_.get()) { |
618 DCHECK(file_system_context_.get()); | 588 DCHECK(file_system_context_.get()); |
619 DCHECK(db_tracker_.get()); | 589 DCHECK(db_tracker_.get()); |
620 DCHECK(webkit_context_.get()); | 590 DCHECK(webkit_context_.get()); |
621 return; | 591 return; |
622 } | 592 } |
623 | 593 |
624 // All of the clients have to be created and registered with the | 594 // All of the clients have to be created and registered with the |
625 // QuotaManager prior to the QuotaManger being used. So we do them | 595 // QuotaManager prior to the QuotaManger being used. So we do them |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 OffTheRecordProfileImpl* profile = NULL; | 652 OffTheRecordProfileImpl* profile = NULL; |
683 #if defined(OS_CHROMEOS) | 653 #if defined(OS_CHROMEOS) |
684 if (Profile::IsGuestSession()) | 654 if (Profile::IsGuestSession()) |
685 profile = new GuestSessionProfile(this); | 655 profile = new GuestSessionProfile(this); |
686 #endif | 656 #endif |
687 if (!profile) | 657 if (!profile) |
688 profile = new OffTheRecordProfileImpl(this); | 658 profile = new OffTheRecordProfileImpl(this); |
689 profile->Init(); | 659 profile->Init(); |
690 return profile; | 660 return profile; |
691 } | 661 } |
OLD | NEW |