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

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

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits and crasher on Mac Created 9 years, 11 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/profile.h" 5 #include "chrome/browser/profiles/profile.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "chrome/browser/background_contents_service.h" 16 #include "chrome/browser/background_contents_service.h"
17 #include "chrome/browser/browser_list.h" 17 #include "chrome/browser/browser_list.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_thread.h" 19 #include "chrome/browser/browser_thread.h"
20 #include "chrome/browser/chrome_blob_storage_context.h" 20 #include "chrome/browser/chrome_blob_storage_context.h"
21 #include "chrome/browser/download/download_manager.h" 21 #include "chrome/browser/download/download_manager.h"
22 #include "chrome/browser/extensions/extension_message_service.h" 22 #include "chrome/browser/extensions/extension_message_service.h"
23 #include "chrome/browser/extensions/extension_pref_store.h"
23 #include "chrome/browser/extensions/extension_process_manager.h" 24 #include "chrome/browser/extensions/extension_process_manager.h"
24 #include "chrome/browser/file_system/browser_file_system_helper.h" 25 #include "chrome/browser/file_system/browser_file_system_helper.h"
25 #include "chrome/browser/in_process_webkit/webkit_context.h" 26 #include "chrome/browser/in_process_webkit/webkit_context.h"
26 #include "chrome/browser/net/chrome_url_request_context.h" 27 #include "chrome/browser/net/chrome_url_request_context.h"
28 #include "chrome/browser/net/pref_proxy_config_service.h"
27 #include "chrome/browser/notifications/desktop_notification_service.h" 29 #include "chrome/browser/notifications/desktop_notification_service.h"
28 #include "chrome/browser/ssl/ssl_host_state.h" 30 #include "chrome/browser/ssl/ssl_host_state.h"
29 #include "chrome/browser/sync/profile_sync_service.h" 31 #include "chrome/browser/sync/profile_sync_service.h"
30 #include "chrome/browser/themes/browser_theme_provider.h" 32 #include "chrome/browser/themes/browser_theme_provider.h"
31 #include "chrome/browser/ui/find_bar/find_bar_state.h" 33 #include "chrome/browser/ui/find_bar/find_bar_state.h"
32 #include "chrome/common/chrome_constants.h" 34 #include "chrome/common/chrome_constants.h"
33 #include "chrome/common/chrome_paths.h" 35 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/json_pref_store.h" 36 #include "chrome/common/json_pref_store.h"
35 #include "chrome/common/notification_service.h" 37 #include "chrome/common/notification_service.h"
36 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile 134 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
133 // to make it suitable for the off the record mode. 135 // to make it suitable for the off the record mode.
134 // 136 //
135 //////////////////////////////////////////////////////////////////////////////// 137 ////////////////////////////////////////////////////////////////////////////////
136 class OffTheRecordProfileImpl : public Profile, 138 class OffTheRecordProfileImpl : public Profile,
137 public BrowserList::Observer { 139 public BrowserList::Observer {
138 public: 140 public:
139 explicit OffTheRecordProfileImpl(Profile* real_profile) 141 explicit OffTheRecordProfileImpl(Profile* real_profile)
140 : profile_(real_profile), 142 : profile_(real_profile),
141 start_time_(Time::Now()) { 143 start_time_(Time::Now()) {
144 prefs_.reset(profile_->GetPrefs()->CreateIncognitoPrefService(
145 new ExtensionPrefStore(profile_->GetExtensionPrefValueMap(), true)));
Mattias Nissler (ping if slow) 2011/01/21 08:53:08 Hm, what's the contract of GetExtensionPrefValueMa
battre 2011/01/24 17:47:18 I cannot move the entire lazy initialization of |e
146
142 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this); 147 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
143 extension_process_manager_.reset(ExtensionProcessManager::Create(this)); 148 extension_process_manager_.reset(ExtensionProcessManager::Create(this));
144 149
145 BrowserList::AddObserver(this); 150 BrowserList::AddObserver(this);
146 151
147 background_contents_service_.reset( 152 background_contents_service_.reset(
148 new BackgroundContentsService(this, CommandLine::ForCurrentProcess())); 153 new BackgroundContentsService(this, CommandLine::ForCurrentProcess()));
149 } 154 }
150 155
151 virtual ~OffTheRecordProfileImpl() { 156 virtual ~OffTheRecordProfileImpl() {
152 NotificationService::current()->Notify(NotificationType::PROFILE_DESTROYED, 157 NotificationService::current()->Notify(NotificationType::PROFILE_DESTROYED,
153 Source<Profile>(this), 158 Source<Profile>(this),
154 NotificationService::NoDetails()); 159 NotificationService::NoDetails());
155 CleanupRequestContext(request_context_); 160 CleanupRequestContext(request_context_);
156 CleanupRequestContext(extensions_request_context_); 161 CleanupRequestContext(extensions_request_context_);
157 162
158 // Clean up all DB files/directories 163 // Clean up all DB files/directories
159 BrowserThread::PostTask( 164 BrowserThread::PostTask(
160 BrowserThread::FILE, FROM_HERE, 165 BrowserThread::FILE, FROM_HERE,
161 NewRunnableMethod( 166 NewRunnableMethod(
162 db_tracker_.get(), 167 db_tracker_.get(),
163 &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory)); 168 &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory));
164 169
165 BrowserList::RemoveObserver(this); 170 BrowserList::RemoveObserver(this);
171
172 if (pref_proxy_config_tracker_)
173 pref_proxy_config_tracker_->DetachFromPrefService();
166 } 174 }
167 175
168 virtual ProfileId GetRuntimeId() { 176 virtual ProfileId GetRuntimeId() {
169 return reinterpret_cast<ProfileId>(this); 177 return reinterpret_cast<ProfileId>(this);
170 } 178 }
171 179
172 virtual FilePath GetPath() { return profile_->GetPath(); } 180 virtual FilePath GetPath() { return profile_->GetPath(); }
173 181
174 virtual bool IsOffTheRecord() { 182 virtual bool IsOffTheRecord() {
175 return true; 183 return true;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 315
308 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) { 316 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
309 if (sat == EXPLICIT_ACCESS) 317 if (sat == EXPLICIT_ACCESS)
310 return profile_->GetPasswordStore(sat); 318 return profile_->GetPasswordStore(sat);
311 319
312 NOTREACHED() << "This profile is OffTheRecord"; 320 NOTREACHED() << "This profile is OffTheRecord";
313 return NULL; 321 return NULL;
314 } 322 }
315 323
316 virtual PrefService* GetPrefs() { 324 virtual PrefService* GetPrefs() {
317 return profile_->GetPrefs(); 325 return prefs_.get();
318 } 326 }
319 327
320 virtual TemplateURLModel* GetTemplateURLModel() { 328 virtual TemplateURLModel* GetTemplateURLModel() {
321 return profile_->GetTemplateURLModel(); 329 return profile_->GetTemplateURLModel();
322 } 330 }
323 331
324 virtual TemplateURLFetcher* GetTemplateURLFetcher() { 332 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
325 return profile_->GetTemplateURLFetcher(); 333 return profile_->GetTemplateURLFetcher();
326 } 334 }
327 335
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return NULL; 613 return NULL;
606 } 614 }
607 615
608 #if defined(OS_CHROMEOS) 616 #if defined(OS_CHROMEOS)
609 virtual void ChangeApplicationLocale( 617 virtual void ChangeApplicationLocale(
610 const std::string& locale, bool keep_local) { 618 const std::string& locale, bool keep_local) {
611 } 619 }
612 #endif // defined(OS_CHROMEOS) 620 #endif // defined(OS_CHROMEOS)
613 621
614 virtual PrefProxyConfigTracker* GetProxyConfigTracker() { 622 virtual PrefProxyConfigTracker* GetProxyConfigTracker() {
615 return profile_->GetProxyConfigTracker(); 623 if (!pref_proxy_config_tracker_)
624 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
625
626 return pref_proxy_config_tracker_;
616 } 627 }
617 628
618 virtual PrerenderManager* GetPrerenderManager() { 629 virtual PrerenderManager* GetPrerenderManager() {
619 // We do not allow prerendering in OTR profiles at this point. 630 // We do not allow prerendering in OTR profiles at this point.
620 // TODO(tburkard): Figure out if we want to support this, and how, at some 631 // TODO(tburkard): Figure out if we want to support this, and how, at some
621 // point in the future. 632 // point in the future.
622 return NULL; 633 return NULL;
623 } 634 }
624 635
636 protected:
637 virtual ExtensionPrefValueMap* GetExtensionPrefValueMap() {
638 return profile_->GetExtensionPrefValueMap();
639 }
640
625 private: 641 private:
626 NotificationRegistrar registrar_; 642 NotificationRegistrar registrar_;
627 643
628 // The real underlying profile. 644 // The real underlying profile.
629 Profile* profile_; 645 Profile* profile_;
630 646
647 scoped_ptr<PrefService> prefs_;
648
631 scoped_ptr<ExtensionProcessManager> extension_process_manager_; 649 scoped_ptr<ExtensionProcessManager> extension_process_manager_;
632 650
633 // The context to use for requests made from this OTR session. 651 // The context to use for requests made from this OTR session.
634 scoped_refptr<ChromeURLRequestContextGetter> request_context_; 652 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
635 653
636 // The context to use for requests made by an extension while in OTR mode. 654 // The context to use for requests made by an extension while in OTR mode.
637 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_; 655 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
638 656
639 // The download manager that only stores downloaded items in memory. 657 // The download manager that only stores downloaded items in memory.
640 scoped_refptr<DownloadManager> download_manager_; 658 scoped_refptr<DownloadManager> download_manager_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 FilePath last_selected_directory_; 694 FilePath last_selected_directory_;
677 695
678 // Tracks all BackgroundContents running under this profile. 696 // Tracks all BackgroundContents running under this profile.
679 scoped_ptr<BackgroundContentsService> background_contents_service_; 697 scoped_ptr<BackgroundContentsService> background_contents_service_;
680 698
681 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; 699 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
682 700
683 // The file_system context for this profile. 701 // The file_system context for this profile.
684 scoped_refptr<fileapi::SandboxedFileSystemContext> file_system_context_; 702 scoped_refptr<fileapi::SandboxedFileSystemContext> file_system_context_;
685 703
704 scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
705
686 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); 706 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
687 }; 707 };
688 708
689 Profile* Profile::CreateOffTheRecordProfile() { 709 Profile* Profile::CreateOffTheRecordProfile() {
690 return new OffTheRecordProfileImpl(this); 710 return new OffTheRecordProfileImpl(this);
691 } 711 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698