Chromium Code Reviews| 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/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/browser/background_contents_service.h" | 14 #include "chrome/browser/background_contents_service.h" |
| 15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browser_thread.h" | 17 #include "chrome/browser/browser_thread.h" |
| 18 #include "chrome/browser/chrome_blob_storage_context.h" | 18 #include "chrome/browser/chrome_blob_storage_context.h" |
| 19 #include "chrome/browser/download/download_manager.h" | 19 #include "chrome/browser/download/download_manager.h" |
| 20 #include "chrome/browser/extensions/extension_message_service.h" | 20 #include "chrome/browser/extensions/extension_message_service.h" |
| 21 #include "chrome/browser/extensions/extension_pref_store.h" | |
| 21 #include "chrome/browser/extensions/extension_process_manager.h" | 22 #include "chrome/browser/extensions/extension_process_manager.h" |
| 22 #include "chrome/browser/file_system/browser_file_system_helper.h" | 23 #include "chrome/browser/file_system/browser_file_system_helper.h" |
| 23 #include "chrome/browser/in_process_webkit/webkit_context.h" | 24 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 24 #include "chrome/browser/net/chrome_url_request_context.h" | 25 #include "chrome/browser/net/chrome_url_request_context.h" |
| 26 #include "chrome/browser/net/pref_proxy_config_service.h" | |
| 25 #include "chrome/browser/notifications/desktop_notification_service.h" | 27 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 26 #include "chrome/browser/ssl/ssl_host_state.h" | 28 #include "chrome/browser/ssl/ssl_host_state.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 29 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/themes/browser_theme_provider.h" | 30 #include "chrome/browser/themes/browser_theme_provider.h" |
| 29 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 31 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 30 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 32 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/json_pref_store.h" | 35 #include "chrome/common/json_pref_store.h" |
| 34 #include "chrome/common/notification_service.h" | 36 #include "chrome/common/notification_service.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile | 130 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile |
| 129 // to make it suitable for the off the record mode. | 131 // to make it suitable for the off the record mode. |
| 130 // | 132 // |
| 131 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
| 132 class OffTheRecordProfileImpl : public Profile, | 134 class OffTheRecordProfileImpl : public Profile, |
| 133 public BrowserList::Observer { | 135 public BrowserList::Observer { |
| 134 public: | 136 public: |
| 135 explicit OffTheRecordProfileImpl(Profile* real_profile) | 137 explicit OffTheRecordProfileImpl(Profile* real_profile) |
| 136 : profile_(real_profile), | 138 : profile_(real_profile), |
| 137 start_time_(Time::Now()) { | 139 start_time_(Time::Now()) { |
| 140 prefs_.reset(profile_->GetPrefs()->CreateIncognitoPrefService( | |
| 141 new ExtensionPrefStore(profile_->GetExtensionPrefValueMap(), true))); | |
| 142 | |
| 138 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this); | 143 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this); |
| 139 extension_process_manager_.reset(ExtensionProcessManager::Create(this)); | 144 extension_process_manager_.reset(ExtensionProcessManager::Create(this)); |
| 140 | 145 |
| 141 BrowserList::AddObserver(this); | 146 BrowserList::AddObserver(this); |
| 142 | 147 |
| 143 background_contents_service_.reset( | 148 background_contents_service_.reset( |
| 144 new BackgroundContentsService(this, CommandLine::ForCurrentProcess())); | 149 new BackgroundContentsService(this, CommandLine::ForCurrentProcess())); |
| 145 } | 150 } |
| 146 | 151 |
| 147 virtual ~OffTheRecordProfileImpl() { | 152 virtual ~OffTheRecordProfileImpl() { |
| 148 NotificationService::current()->Notify(NotificationType::PROFILE_DESTROYED, | 153 NotificationService::current()->Notify(NotificationType::PROFILE_DESTROYED, |
| 149 Source<Profile>(this), | 154 Source<Profile>(this), |
| 150 NotificationService::NoDetails()); | 155 NotificationService::NoDetails()); |
| 151 CleanupRequestContext(request_context_); | 156 CleanupRequestContext(request_context_); |
| 152 CleanupRequestContext(extensions_request_context_); | 157 CleanupRequestContext(extensions_request_context_); |
| 153 | 158 |
| 154 // Clean up all DB files/directories | 159 // Clean up all DB files/directories |
| 155 BrowserThread::PostTask( | 160 BrowserThread::PostTask( |
| 156 BrowserThread::FILE, FROM_HERE, | 161 BrowserThread::FILE, FROM_HERE, |
| 157 NewRunnableMethod( | 162 NewRunnableMethod( |
| 158 db_tracker_.get(), | 163 db_tracker_.get(), |
| 159 &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory)); | 164 &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory)); |
| 160 | 165 |
| 161 BrowserList::RemoveObserver(this); | 166 BrowserList::RemoveObserver(this); |
| 167 | |
| 168 if (pref_proxy_config_tracker_) | |
| 169 pref_proxy_config_tracker_->DetachFromPrefService(); | |
| 162 } | 170 } |
| 163 | 171 |
| 164 virtual ProfileId GetRuntimeId() { | 172 virtual ProfileId GetRuntimeId() { |
| 165 return reinterpret_cast<ProfileId>(this); | 173 return reinterpret_cast<ProfileId>(this); |
| 166 } | 174 } |
| 167 | 175 |
| 168 virtual FilePath GetPath() { return profile_->GetPath(); } | 176 virtual FilePath GetPath() { return profile_->GetPath(); } |
| 169 | 177 |
| 170 virtual bool IsOffTheRecord() { | 178 virtual bool IsOffTheRecord() { |
| 171 return true; | 179 return true; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 311 |
| 304 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) { | 312 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) { |
| 305 if (sat == EXPLICIT_ACCESS) | 313 if (sat == EXPLICIT_ACCESS) |
| 306 return profile_->GetPasswordStore(sat); | 314 return profile_->GetPasswordStore(sat); |
| 307 | 315 |
| 308 NOTREACHED() << "This profile is OffTheRecord"; | 316 NOTREACHED() << "This profile is OffTheRecord"; |
| 309 return NULL; | 317 return NULL; |
| 310 } | 318 } |
| 311 | 319 |
| 312 virtual PrefService* GetPrefs() { | 320 virtual PrefService* GetPrefs() { |
| 313 return profile_->GetPrefs(); | 321 return prefs_.get(); |
| 314 } | 322 } |
| 315 | 323 |
| 316 virtual TemplateURLModel* GetTemplateURLModel() { | 324 virtual TemplateURLModel* GetTemplateURLModel() { |
| 317 return profile_->GetTemplateURLModel(); | 325 return profile_->GetTemplateURLModel(); |
| 318 } | 326 } |
| 319 | 327 |
| 320 virtual TemplateURLFetcher* GetTemplateURLFetcher() { | 328 virtual TemplateURLFetcher* GetTemplateURLFetcher() { |
| 321 return profile_->GetTemplateURLFetcher(); | 329 return profile_->GetTemplateURLFetcher(); |
| 322 } | 330 } |
| 323 | 331 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 | 603 |
| 596 virtual policy::ProfilePolicyContext* GetPolicyContext() { | 604 virtual policy::ProfilePolicyContext* GetPolicyContext() { |
| 597 return NULL; | 605 return NULL; |
| 598 } | 606 } |
| 599 | 607 |
| 600 virtual PromoCounter* GetInstantPromoCounter() { | 608 virtual PromoCounter* GetInstantPromoCounter() { |
| 601 return NULL; | 609 return NULL; |
| 602 } | 610 } |
| 603 | 611 |
| 604 virtual PrefProxyConfigTracker* GetProxyConfigTracker() { | 612 virtual PrefProxyConfigTracker* GetProxyConfigTracker() { |
| 605 return profile_->GetProxyConfigTracker(); | 613 if (!pref_proxy_config_tracker_) |
| 614 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs()); | |
| 615 | |
| 616 return pref_proxy_config_tracker_; | |
| 606 } | 617 } |
| 607 | 618 |
| 608 virtual PrerenderManager* GetPrerenderManager() { | 619 virtual PrerenderManager* GetPrerenderManager() { |
| 609 // We do not allow prerendering in OTR profiles at this point. | 620 // We do not allow prerendering in OTR profiles at this point. |
| 610 // TODO(tburkard): Figure out if we want to support this, and how, at some | 621 // TODO(tburkard): Figure out if we want to support this, and how, at some |
| 611 // point in the future. | 622 // point in the future. |
| 612 return NULL; | 623 return NULL; |
| 613 } | 624 } |
| 614 | 625 |
| 626 protected: | |
| 627 ExtensionPrefValueMap* GetExtensionPrefValueMap() { | |
|
danno
2011/01/14 13:05:09
should it be virtual, maybe private :-)
battre
2011/01/20 17:59:29
Made virtual, not private.
| |
| 628 return profile_->GetExtensionPrefValueMap(); | |
| 629 } | |
| 630 | |
| 615 private: | 631 private: |
| 616 NotificationRegistrar registrar_; | 632 NotificationRegistrar registrar_; |
| 617 | 633 |
| 618 // The real underlying profile. | 634 // The real underlying profile. |
| 619 Profile* profile_; | 635 Profile* profile_; |
| 620 | 636 |
| 637 scoped_ptr<PrefService> prefs_; | |
| 638 | |
| 621 scoped_ptr<ExtensionProcessManager> extension_process_manager_; | 639 scoped_ptr<ExtensionProcessManager> extension_process_manager_; |
| 622 | 640 |
| 623 // The context to use for requests made from this OTR session. | 641 // The context to use for requests made from this OTR session. |
| 624 scoped_refptr<ChromeURLRequestContextGetter> request_context_; | 642 scoped_refptr<ChromeURLRequestContextGetter> request_context_; |
| 625 | 643 |
| 626 // The context to use for requests made by an extension while in OTR mode. | 644 // The context to use for requests made by an extension while in OTR mode. |
| 627 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_; | 645 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_; |
| 628 | 646 |
| 629 // The download manager that only stores downloaded items in memory. | 647 // The download manager that only stores downloaded items in memory. |
| 630 scoped_refptr<DownloadManager> download_manager_; | 648 scoped_refptr<DownloadManager> download_manager_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 FilePath last_selected_directory_; | 684 FilePath last_selected_directory_; |
| 667 | 685 |
| 668 // Tracks all BackgroundContents running under this profile. | 686 // Tracks all BackgroundContents running under this profile. |
| 669 scoped_ptr<BackgroundContentsService> background_contents_service_; | 687 scoped_ptr<BackgroundContentsService> background_contents_service_; |
| 670 | 688 |
| 671 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 689 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 672 | 690 |
| 673 // The file_system context for this profile. | 691 // The file_system context for this profile. |
| 674 scoped_refptr<fileapi::SandboxedFileSystemContext> file_system_context_; | 692 scoped_refptr<fileapi::SandboxedFileSystemContext> file_system_context_; |
| 675 | 693 |
| 694 scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; | |
| 695 | |
| 676 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); | 696 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); |
| 677 }; | 697 }; |
| 678 | 698 |
| 679 Profile* Profile::CreateOffTheRecordProfile() { | 699 Profile* Profile::CreateOffTheRecordProfile() { |
| 680 return new OffTheRecordProfileImpl(this); | 700 return new OffTheRecordProfileImpl(this); |
| 681 } | 701 } |
| OLD | NEW |