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

Side by Side Diff: chrome/browser/profiles/off_the_record_profile_impl.cc

Issue 8135017: Refactor downloads into a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated latest rounds of comments from John. Created 9 years, 2 months 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
OLDNEW
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
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
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 const NotificationDetails& details) { 569 const NotificationDetails& details) {
595 if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { 570 if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) {
596 const std::string& host = *(Details<const std::string>(details).ptr()); 571 const std::string& host = *(Details<const std::string>(details).ptr());
597 if (!host.empty()) { 572 if (!host.empty()) {
598 double level = profile_->GetHostZoomMap()->GetZoomLevel(host); 573 double level = profile_->GetHostZoomMap()->GetZoomLevel(host);
599 GetHostZoomMap()->SetZoomLevel(host, level); 574 GetHostZoomMap()->SetZoomLevel(host, level);
600 } 575 }
601 } 576 }
602 } 577 }
603 578
604 void OffTheRecordProfileImpl::SetDownloadManagerDelegate(
605 ChromeDownloadManagerDelegate* delegate) {
606 download_manager_delegate_ = delegate;
607 }
608
609 void OffTheRecordProfileImpl::CreateQuotaManagerAndClients() { 579 void OffTheRecordProfileImpl::CreateQuotaManagerAndClients() {
610 if (quota_manager_.get()) { 580 if (quota_manager_.get()) {
611 DCHECK(file_system_context_.get()); 581 DCHECK(file_system_context_.get());
612 DCHECK(db_tracker_.get()); 582 DCHECK(db_tracker_.get());
613 DCHECK(webkit_context_.get()); 583 DCHECK(webkit_context_.get());
614 return; 584 return;
615 } 585 }
616 586
617 // All of the clients have to be created and registered with the 587 // All of the clients have to be created and registered with the
618 // QuotaManager prior to the QuotaManger being used. So we do them 588 // QuotaManager prior to the QuotaManger being used. So we do them
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 OffTheRecordProfileImpl* profile = NULL; 645 OffTheRecordProfileImpl* profile = NULL;
676 #if defined(OS_CHROMEOS) 646 #if defined(OS_CHROMEOS)
677 if (Profile::IsGuestSession()) 647 if (Profile::IsGuestSession())
678 profile = new GuestSessionProfile(this); 648 profile = new GuestSessionProfile(this);
679 #endif 649 #endif
680 if (!profile) 650 if (!profile)
681 profile = new OffTheRecordProfileImpl(this); 651 profile = new OffTheRecordProfileImpl(this);
682 profile->Init(); 652 profile->Init();
683 return profile; 653 return profile;
684 } 654 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/off_the_record_profile_impl.h ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698