summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles
diff options
context:
space:
mode:
authoryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 16:01:46 +0000
committeryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 16:01:46 +0000
commitd407cc0d24e3b55a68bbe8098da26bde8ad666b6 (patch)
treeb3f3857d9d4d1be7cca44b969b9a1d078b3b96fa /chrome/browser/profiles
parentd2a53042edaec224127d158be00b3d3356b87653 (diff)
downloadchromium_src-d407cc0d24e3b55a68bbe8098da26bde8ad666b6.zip
chromium_src-d407cc0d24e3b55a68bbe8098da26bde8ad666b6.tar.gz
chromium_src-d407cc0d24e3b55a68bbe8098da26bde8ad666b6.tar.bz2
Summary of changes
== chrome/browser/profiles/off_the_record_profile.cc == == chrome/browser/profiles/off_the_record_profile.h == * Change GetHostZoomMap for populating from parent's host zoom map. * Install observer in off the record profile to observe original HZM changes * Move object initialization code to Init method for two phase initialization. == content/browser/host_zoom_map.* == * Populating newly created HostZoomMap(HZM) for off the record profile with zoom level settings from original profile. == content/browser/renderer_host/render_view_host.cc == Propagate zoom level change to related hosts to update page rendering. BUG=88355 TEST=Manual test on Linux/Mac/Win and unit test Review URL: http://codereview.chromium.org/7624013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100920 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc977
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h211
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl_unittest.cc167
3 files changed, 844 insertions, 511 deletions
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 1185b74..c227cef 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/profiles/profile.h"
-
-#include <string>
+#include "chrome/browser/profiles/off_the_record_profile_impl.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
@@ -18,7 +16,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_plugin_service_filter.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extension_pref_store.h"
@@ -30,12 +27,10 @@
#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/off_the_record_profile_io_data.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/transport_security_persister.h"
-#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/find_bar/find_bar_state.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/extension_icon_source.h"
@@ -65,9 +60,6 @@
#include "chrome/browser/chromeos/preferences.h"
#endif
-using base::Time;
-using base::TimeDelta;
-
namespace {
void NotifyOTRProfileCreatedOnIOThread(void* original_profile,
@@ -84,628 +76,589 @@ void NotifyOTRProfileDestroyedOnIOThread(void* original_profile,
} // namespace
-////////////////////////////////////////////////////////////////////////////////
-//
-// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
-// to make it suitable for the incognito mode.
-//
-////////////////////////////////////////////////////////////////////////////////
-class OffTheRecordProfileImpl : public Profile,
- public BrowserList::Observer {
- public:
- explicit OffTheRecordProfileImpl(Profile* real_profile)
- : profile_(real_profile),
- prefs_(real_profile->GetOffTheRecordPrefs()),
- ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
- start_time_(Time::Now()) {
- extension_process_manager_.reset(ExtensionProcessManager::Create(this));
+OffTheRecordProfileImpl::OffTheRecordProfileImpl(Profile* real_profile)
+ : profile_(real_profile),
+ prefs_(real_profile->GetOffTheRecordPrefs()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
+ start_time_(Time::Now()) {
+}
- BrowserList::AddObserver(this);
+void OffTheRecordProfileImpl::Init() {
+ extension_process_manager_.reset(ExtensionProcessManager::Create(this));
- ProfileDependencyManager::GetInstance()->CreateProfileServices(this, false);
+ BrowserList::AddObserver(this);
- DCHECK_NE(IncognitoModePrefs::DISABLED,
- IncognitoModePrefs::GetAvailability(real_profile->GetPrefs()));
+ ProfileDependencyManager::GetInstance()->CreateProfileServices(this, false);
- // TODO(oshima): Remove the need to eagerly initialize the request context
- // getter. chromeos::OnlineAttempt is illegally trying to access this
- // Profile member from a thread other than the UI thread, so we need to
- // prevent a race.
+ DCHECK_NE(IncognitoModePrefs::DISABLED,
+ IncognitoModePrefs::GetAvailability(profile_->GetPrefs()));
+
+ // TODO(oshima): Remove the need to eagerly initialize the request context
+ // getter. chromeos::OnlineAttempt is illegally trying to access this
+ // Profile member from a thread other than the UI thread, so we need to
+ // prevent a race.
#if defined(OS_CHROMEOS)
- GetRequestContext();
+ GetRequestContext();
#endif // defined(OS_CHROMEOS)
- // Make the chrome//extension-icon/ resource available.
- ExtensionIconSource* icon_source = new ExtensionIconSource(real_profile);
- GetChromeURLDataManager()->AddDataSource(icon_source);
-
- ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
- PluginPrefs::GetForProfile(this), &GetResourceContext());
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- &NotifyOTRProfileCreatedOnIOThread, profile_, this));
- }
+ // Make the chrome//extension-icon/ resource available.
+ ExtensionIconSource* icon_source = new ExtensionIconSource(profile_);
+ GetChromeURLDataManager()->AddDataSource(icon_source);
- virtual ~OffTheRecordProfileImpl() {
- NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_DESTROYED, Source<Profile>(this),
- NotificationService::NoDetails());
+ ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
+ PluginPrefs::GetForProfile(this), &GetResourceContext());
- // There shouldn't be any browser window associated with this profile.
- CHECK(!BrowserList::FindBrowserWithProfile(this));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(
+ &NotifyOTRProfileCreatedOnIOThread, profile_, this));
+}
- ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
- &GetResourceContext());
+OffTheRecordProfileImpl::~OffTheRecordProfileImpl() {
+ NotificationService::current()->Notify(
+ chrome::NOTIFICATION_PROFILE_DESTROYED, Source<Profile>(this),
+ NotificationService::NoDetails());
- ProfileDependencyManager::GetInstance()->DestroyProfileServices(this);
+ // There shouldn't be any browser window associated with this profile.
+ CHECK(!BrowserList::FindBrowserWithProfile(this));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- &NotifyOTRProfileDestroyedOnIOThread, profile_, this));
-
- // Clean up all DB files/directories
- if (db_tracker_) {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- db_tracker_.get(),
- &webkit_database::DatabaseTracker::Shutdown));
- }
+ ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
+ &GetResourceContext());
- BrowserList::RemoveObserver(this);
+ ProfileDependencyManager::GetInstance()->DestroyProfileServices(this);
- if (host_content_settings_map_)
- host_content_settings_map_->ShutdownOnUIThread();
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(&NotifyOTRProfileDestroyedOnIOThread, profile_,
+ this));
- if (pref_proxy_config_tracker_)
- pref_proxy_config_tracker_->DetachFromPrefService();
-
- ExtensionService* extension_service = GetExtensionService();
- if (extension_service) {
- ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
- extension_prefs->ClearIncognitoSessionOnlyContentSettings();
- }
- }
-
- virtual std::string GetProfileName() {
- // Incognito profile should not return the profile name.
- return std::string();
+ // Clean up all DB files/directories
+ if (db_tracker_) {
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(db_tracker_.get(),
+ &webkit_database::DatabaseTracker::Shutdown));
}
- virtual FilePath GetPath() { return profile_->GetPath(); }
+ BrowserList::RemoveObserver(this);
- virtual bool IsOffTheRecord() {
- return true;
- }
+ if (host_content_settings_map_)
+ host_content_settings_map_->ShutdownOnUIThread();
- virtual Profile* GetOffTheRecordProfile() {
- return this;
- }
+ if (pref_proxy_config_tracker_)
+ pref_proxy_config_tracker_->DetachFromPrefService();
- virtual void DestroyOffTheRecordProfile() {
- // Suicide is bad!
- NOTREACHED();
- }
-
- virtual bool HasOffTheRecordProfile() {
- return true;
+ ExtensionService* extension_service = GetExtensionService();
+ if (extension_service) {
+ ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
+ extension_prefs->ClearIncognitoSessionOnlyContentSettings();
}
+}
- virtual Profile* GetOriginalProfile() {
- return profile_;
- }
+std::string OffTheRecordProfileImpl::GetProfileName() {
+ // Incognito profile should not return the profile name.
+ return std::string();
+}
- virtual ChromeAppCacheService* GetAppCacheService() {
- CreateQuotaManagerAndClients();
- return appcache_service_;
- }
+FilePath OffTheRecordProfileImpl::GetPath() {
+ return profile_->GetPath();
+}
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
- CreateQuotaManagerAndClients();
- return db_tracker_;
- }
+bool OffTheRecordProfileImpl::IsOffTheRecord() {
+ return true;
+}
- virtual VisitedLinkMaster* GetVisitedLinkMaster() {
- // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
- // because we don't want to leak the sites that the user has visited before.
- return NULL;
- }
+Profile* OffTheRecordProfileImpl::GetOffTheRecordProfile() {
+ return this;
+}
- virtual ExtensionService* GetExtensionService() {
- return GetOriginalProfile()->GetExtensionService();
- }
+void OffTheRecordProfileImpl::DestroyOffTheRecordProfile() {
+ // Suicide is bad!
+ NOTREACHED();
+}
- virtual UserScriptMaster* GetUserScriptMaster() {
- return GetOriginalProfile()->GetUserScriptMaster();
- }
+bool OffTheRecordProfileImpl::HasOffTheRecordProfile() {
+ return true;
+}
- virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
- // TODO(mpcomplete): figure out whether we should return the original
- // profile's version.
- return NULL;
- }
+Profile* OffTheRecordProfileImpl::GetOriginalProfile() {
+ return profile_;
+}
- virtual ExtensionProcessManager* GetExtensionProcessManager() {
- return extension_process_manager_.get();
- }
+ChromeAppCacheService* OffTheRecordProfileImpl::GetAppCacheService() {
+ CreateQuotaManagerAndClients();
+ return appcache_service_;
+}
- virtual ExtensionMessageService* GetExtensionMessageService() {
- return GetOriginalProfile()->GetExtensionMessageService();
- }
+webkit_database::DatabaseTracker*
+ OffTheRecordProfileImpl::GetDatabaseTracker() {
+ CreateQuotaManagerAndClients();
+ return db_tracker_;
+}
- virtual ExtensionEventRouter* GetExtensionEventRouter() {
- return GetOriginalProfile()->GetExtensionEventRouter();
- }
+VisitedLinkMaster* OffTheRecordProfileImpl::GetVisitedLinkMaster() {
+ // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
+ // because we don't want to leak the sites that the user has visited before.
+ return NULL;
+}
- virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() {
- return GetOriginalProfile()->GetExtensionSpecialStoragePolicy();
- }
+ExtensionService* OffTheRecordProfileImpl::GetExtensionService() {
+ return GetOriginalProfile()->GetExtensionService();
+}
- virtual SSLHostState* GetSSLHostState() {
- if (!ssl_host_state_.get())
- ssl_host_state_.reset(new SSLHostState());
+UserScriptMaster* OffTheRecordProfileImpl::GetUserScriptMaster() {
+ return GetOriginalProfile()->GetUserScriptMaster();
+}
- DCHECK(ssl_host_state_->CalledOnValidThread());
- return ssl_host_state_.get();
- }
+ExtensionDevToolsManager*
+ OffTheRecordProfileImpl::GetExtensionDevToolsManager() {
+ // TODO(mpcomplete): figure out whether we should return the original
+ // profile's version.
+ return NULL;
+}
- virtual net::TransportSecurityState* GetTransportSecurityState() {
- if (!transport_security_state_.get()) {
- transport_security_state_ = new net::TransportSecurityState(
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kHstsHosts));
- transport_security_loader_ =
- new TransportSecurityPersister(transport_security_state_.get(),
- GetPath(),
- true /* readonly */);
- transport_security_loader_->Init();
- }
+ExtensionProcessManager*
+ OffTheRecordProfileImpl::GetExtensionProcessManager() {
+ return extension_process_manager_.get();
+}
- return transport_security_state_.get();
- }
+ExtensionMessageService*
+ OffTheRecordProfileImpl::GetExtensionMessageService() {
+ return GetOriginalProfile()->GetExtensionMessageService();
+}
- virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
- if (sat == EXPLICIT_ACCESS)
- return profile_->GetHistoryService(sat);
+ExtensionEventRouter* OffTheRecordProfileImpl::GetExtensionEventRouter() {
+ return GetOriginalProfile()->GetExtensionEventRouter();
+}
- NOTREACHED() << "This profile is OffTheRecord";
- return NULL;
- }
+ExtensionSpecialStoragePolicy*
+ OffTheRecordProfileImpl::GetExtensionSpecialStoragePolicy() {
+ return GetOriginalProfile()->GetExtensionSpecialStoragePolicy();
+}
- virtual HistoryService* GetHistoryServiceWithoutCreating() {
- return profile_->GetHistoryServiceWithoutCreating();
- }
+SSLHostState* OffTheRecordProfileImpl::GetSSLHostState() {
+ if (!ssl_host_state_.get())
+ ssl_host_state_.reset(new SSLHostState());
- virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
- if (sat == EXPLICIT_ACCESS)
- return profile_->GetFaviconService(sat);
+ DCHECK(ssl_host_state_->CalledOnValidThread());
+ return ssl_host_state_.get();
+}
- NOTREACHED() << "This profile is OffTheRecord";
- return NULL;
+net::TransportSecurityState*
+ OffTheRecordProfileImpl::GetTransportSecurityState() {
+ if (!transport_security_state_.get()) {
+ transport_security_state_ = new net::TransportSecurityState(
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kHstsHosts));
+ transport_security_loader_ =
+ new TransportSecurityPersister(transport_security_state_.get(),
+ GetPath(),
+ true /* readonly */);
+ transport_security_loader_->Init();
}
- virtual AutocompleteClassifier* GetAutocompleteClassifier() {
- return profile_->GetAutocompleteClassifier();
- }
+ return transport_security_state_.get();
+}
- virtual history::ShortcutsBackend* GetShortcutsBackend() {
- return NULL;
- }
+HistoryService* OffTheRecordProfileImpl::GetHistoryService(
+ ServiceAccessType sat) {
+ if (sat == EXPLICIT_ACCESS)
+ return profile_->GetHistoryService(sat);
- virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
- if (sat == EXPLICIT_ACCESS)
- return profile_->GetWebDataService(sat);
+ NOTREACHED() << "This profile is OffTheRecord";
+ return NULL;
+}
- NOTREACHED() << "This profile is OffTheRecord";
- return NULL;
- }
+HistoryService* OffTheRecordProfileImpl::GetHistoryServiceWithoutCreating() {
+ return profile_->GetHistoryServiceWithoutCreating();
+}
- virtual WebDataService* GetWebDataServiceWithoutCreating() {
- return profile_->GetWebDataServiceWithoutCreating();
- }
+FaviconService* OffTheRecordProfileImpl::GetFaviconService(
+ ServiceAccessType sat) {
+ if (sat == EXPLICIT_ACCESS)
+ return profile_->GetFaviconService(sat);
- virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
- if (sat == EXPLICIT_ACCESS)
- return profile_->GetPasswordStore(sat);
+ NOTREACHED() << "This profile is OffTheRecord";
+ return NULL;
+}
- NOTREACHED() << "This profile is OffTheRecord";
- return NULL;
- }
+AutocompleteClassifier* OffTheRecordProfileImpl::GetAutocompleteClassifier() {
+ return profile_->GetAutocompleteClassifier();
+}
- virtual PrefService* GetPrefs() {
- return prefs_;
- }
+history::ShortcutsBackend* OffTheRecordProfileImpl::GetShortcutsBackend() {
+ return NULL;
+}
- virtual PrefService* GetOffTheRecordPrefs() {
- return prefs_;
- }
+WebDataService* OffTheRecordProfileImpl::GetWebDataService(
+ ServiceAccessType sat) {
+ if (sat == EXPLICIT_ACCESS)
+ return profile_->GetWebDataService(sat);
- virtual TemplateURLFetcher* GetTemplateURLFetcher() {
- return profile_->GetTemplateURLFetcher();
- }
+ NOTREACHED() << "This profile is OffTheRecord";
+ return NULL;
+}
- virtual DownloadManager* GetDownloadManager() {
- if (!download_manager_.get()) {
- download_manager_delegate_ = new ChromeDownloadManagerDelegate(this);
- scoped_refptr<DownloadManager> dlm(
- new DownloadManager(download_manager_delegate_,
- g_browser_process->download_status_updater()));
- dlm->Init(this);
- download_manager_delegate_->SetDownloadManager(dlm);
- download_manager_.swap(dlm);
- }
- return download_manager_.get();
- }
+WebDataService* OffTheRecordProfileImpl::GetWebDataServiceWithoutCreating() {
+ return profile_->GetWebDataServiceWithoutCreating();
+}
- virtual bool HasCreatedDownloadManager() const {
- return (download_manager_.get() != NULL);
- }
+PasswordStore* OffTheRecordProfileImpl::GetPasswordStore(
+ ServiceAccessType sat) {
+ if (sat == EXPLICIT_ACCESS)
+ return profile_->GetPasswordStore(sat);
- virtual PersonalDataManager* GetPersonalDataManager() {
- return NULL;
- }
+ NOTREACHED() << "This profile is OffTheRecord";
+ return NULL;
+}
- virtual fileapi::FileSystemContext* GetFileSystemContext() {
- CreateQuotaManagerAndClients();
- return file_system_context_.get();
- }
+PrefService* OffTheRecordProfileImpl::GetPrefs() {
+ return prefs_;
+}
- virtual net::URLRequestContextGetter* GetRequestContext() {
- return io_data_.GetMainRequestContextGetter();
- }
+PrefService* OffTheRecordProfileImpl::GetOffTheRecordPrefs() {
+ return prefs_;
+}
- virtual quota::QuotaManager* GetQuotaManager() {
- CreateQuotaManagerAndClients();
- return quota_manager_.get();
- }
+TemplateURLFetcher* OffTheRecordProfileImpl::GetTemplateURLFetcher() {
+ return profile_->GetTemplateURLFetcher();
+}
- virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
- int renderer_child_id) {
- if (GetExtensionService()) {
- const Extension* installed_app = GetExtensionService()->
- GetInstalledAppForRenderer(renderer_child_id);
- if (installed_app != NULL && installed_app->is_storage_isolated() &&
- installed_app->HasAPIPermission(
- ExtensionAPIPermission::kExperimental)) {
- return GetRequestContextForIsolatedApp(installed_app->id());
- }
- }
- return GetRequestContext();
- }
+DownloadManager* OffTheRecordProfileImpl::GetDownloadManager() {
+ if (!download_manager_.get()) {
+ download_manager_delegate_ = new ChromeDownloadManagerDelegate(this);
+ scoped_refptr<DownloadManager> dlm(
+ new DownloadManager(download_manager_delegate_,
+ g_browser_process->download_status_updater()));
+ dlm->Init(this);
+ download_manager_delegate_->SetDownloadManager(dlm);
+ download_manager_.swap(dlm);
+ }
+ return download_manager_.get();
+}
- virtual net::URLRequestContextGetter* GetRequestContextForMedia() {
- // In OTR mode, media request context is the same as the original one.
- return io_data_.GetMainRequestContextGetter();
- }
+bool OffTheRecordProfileImpl::HasCreatedDownloadManager() const {
+ return download_manager_.get() != NULL;
+}
- virtual net::URLRequestContextGetter* GetRequestContextForExtensions() {
- return io_data_.GetExtensionsRequestContextGetter();
- }
+PersonalDataManager* OffTheRecordProfileImpl::GetPersonalDataManager() {
+ return NULL;
+}
- virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp(
- const std::string& app_id) {
- return io_data_.GetIsolatedAppRequestContextGetter(app_id);
- }
+fileapi::FileSystemContext* OffTheRecordProfileImpl::GetFileSystemContext() {
+ CreateQuotaManagerAndClients();
+ return file_system_context_.get();
+}
- virtual const content::ResourceContext& GetResourceContext() {
- return io_data_.GetResourceContext();
- }
+net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() {
+ return io_data_.GetMainRequestContextGetter();
+}
- virtual net::SSLConfigService* GetSSLConfigService() {
- return profile_->GetSSLConfigService();
- }
+quota::QuotaManager* OffTheRecordProfileImpl::GetQuotaManager() {
+ CreateQuotaManagerAndClients();
+ return quota_manager_.get();
+}
- virtual HostContentSettingsMap* GetHostContentSettingsMap() {
- // Retrieve the host content settings map of the parent profile in order to
- // ensure the preferences have been migrated.
- profile_->GetHostContentSettingsMap();
- if (!host_content_settings_map_.get()) {
- host_content_settings_map_ = new HostContentSettingsMap(
- GetPrefs(), GetExtensionService(), true);
+net::URLRequestContextGetter*
+ OffTheRecordProfileImpl::GetRequestContextForRenderProcess(
+ int renderer_child_id) {
+ if (GetExtensionService()) {
+ const Extension* installed_app = GetExtensionService()->
+ GetInstalledAppForRenderer(renderer_child_id);
+ if (installed_app != NULL && installed_app->is_storage_isolated() &&
+ installed_app->HasAPIPermission(
+ ExtensionAPIPermission::kExperimental)) {
+ return GetRequestContextForIsolatedApp(installed_app->id());
}
- return host_content_settings_map_.get();
- }
-
- virtual HostZoomMap* GetHostZoomMap() {
- if (!host_zoom_map_)
- host_zoom_map_ = new HostZoomMap();
- return host_zoom_map_.get();
- }
-
- virtual GeolocationPermissionContext* GetGeolocationPermissionContext() {
- return profile_->GetGeolocationPermissionContext();
- }
-
- virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
- return profile_->GetUserStyleSheetWatcher();
}
+ return GetRequestContext();
+}
- virtual FindBarState* GetFindBarState() {
- if (!find_bar_state_.get())
- find_bar_state_.reset(new FindBarState());
- return find_bar_state_.get();
- }
+net::URLRequestContextGetter*
+ OffTheRecordProfileImpl::GetRequestContextForMedia() {
+ // In OTR mode, media request context is the same as the original one.
+ return io_data_.GetMainRequestContextGetter();
+}
- virtual bool HasProfileSyncService() const {
- // We never have a profile sync service.
- return false;
- }
+net::URLRequestContextGetter*
+ OffTheRecordProfileImpl::GetRequestContextForExtensions() {
+ return io_data_.GetExtensionsRequestContextGetter();
+}
- virtual bool DidLastSessionExitCleanly() {
- return profile_->DidLastSessionExitCleanly();
- }
+net::URLRequestContextGetter*
+ OffTheRecordProfileImpl::GetRequestContextForIsolatedApp(
+ const std::string& app_id) {
+ return io_data_.GetIsolatedAppRequestContextGetter(app_id);
+}
- virtual BookmarkModel* GetBookmarkModel() {
- return profile_->GetBookmarkModel();
- }
+const content::ResourceContext&
+ OffTheRecordProfileImpl::GetResourceContext() {
+ return io_data_.GetResourceContext();
+}
- virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() {
- return profile_->GetProtocolHandlerRegistry();
- }
+net::SSLConfigService* OffTheRecordProfileImpl::GetSSLConfigService() {
+ return profile_->GetSSLConfigService();
+}
- virtual TokenService* GetTokenService() {
- return NULL;
+HostContentSettingsMap* OffTheRecordProfileImpl::GetHostContentSettingsMap() {
+ // Retrieve the host content settings map of the parent profile in order to
+ // ensure the preferences have been migrated.
+ profile_->GetHostContentSettingsMap();
+ if (!host_content_settings_map_.get()) {
+ host_content_settings_map_ = new HostContentSettingsMap(
+ GetPrefs(), GetExtensionService(), true);
}
+ return host_content_settings_map_.get();
+}
- virtual ProfileSyncService* GetProfileSyncService() {
- return NULL;
+HostZoomMap* OffTheRecordProfileImpl::GetHostZoomMap() {
+ // Create new host zoom map and copy zoom levels from parent.
+ if (!host_zoom_map_) {
+ host_zoom_map_ = new HostZoomMap(profile_->GetHostZoomMap());
+ // Observe parent's HZM change for propagating change of parent's
+ // change to this HZM.
+ registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ Source<HostZoomMap>(profile_->GetHostZoomMap()));
}
+ return host_zoom_map_.get();
+}
- virtual ProfileSyncService* GetProfileSyncService(
- const std::string& cros_user) {
- return NULL;
- }
+GeolocationPermissionContext*
+ OffTheRecordProfileImpl::GetGeolocationPermissionContext() {
+ return profile_->GetGeolocationPermissionContext();
+}
- virtual bool IsSameProfile(Profile* profile) {
- return (profile == this) || (profile == profile_);
- }
+UserStyleSheetWatcher* OffTheRecordProfileImpl::GetUserStyleSheetWatcher() {
+ return profile_->GetUserStyleSheetWatcher();
+}
- virtual Time GetStartTime() const {
- return start_time_;
- }
+FindBarState* OffTheRecordProfileImpl::GetFindBarState() {
+ if (!find_bar_state_.get())
+ find_bar_state_.reset(new FindBarState());
+ return find_bar_state_.get();
+}
- virtual SpellCheckHost* GetSpellCheckHost() {
- return profile_->GetSpellCheckHost();
- }
+bool OffTheRecordProfileImpl::HasProfileSyncService() const {
+ // We never have a profile sync service.
+ return false;
+}
- virtual void ReinitializeSpellCheckHost(bool force) {
- profile_->ReinitializeSpellCheckHost(force);
- }
+bool OffTheRecordProfileImpl::DidLastSessionExitCleanly() {
+ return profile_->DidLastSessionExitCleanly();
+}
- virtual WebKitContext* GetWebKitContext() {
- CreateQuotaManagerAndClients();
- return webkit_context_.get();
- }
+BookmarkModel* OffTheRecordProfileImpl::GetBookmarkModel() {
+ return profile_->GetBookmarkModel();
+}
- virtual history::TopSites* GetTopSitesWithoutCreating() {
- return NULL;
- }
+ProtocolHandlerRegistry* OffTheRecordProfileImpl::GetProtocolHandlerRegistry() {
+ return profile_->GetProtocolHandlerRegistry();
+}
- virtual history::TopSites* GetTopSites() {
- return NULL;
- }
+TokenService* OffTheRecordProfileImpl::GetTokenService() {
+ return NULL;
+}
- virtual void MarkAsCleanShutdown() {
- }
+ProfileSyncService* OffTheRecordProfileImpl::GetProfileSyncService() {
+ return NULL;
+}
- virtual void InitExtensions(bool extensions_enabled) {
- NOTREACHED();
- }
+ProfileSyncService* OffTheRecordProfileImpl::GetProfileSyncService(
+ const std::string& cros_user) {
+ return NULL;
+}
- virtual void InitPromoResources() {
- NOTREACHED();
- }
+bool OffTheRecordProfileImpl::IsSameProfile(Profile* profile) {
+ return (profile == this) || (profile == profile_);
+}
- virtual void InitRegisteredProtocolHandlers() {
- NOTREACHED();
- }
+Time OffTheRecordProfileImpl::GetStartTime() const {
+ return start_time_;
+}
- virtual FilePath last_selected_directory() {
- const FilePath& directory = last_selected_directory_;
- if (directory.empty()) {
- return profile_->last_selected_directory();
- }
- return directory;
- }
+SpellCheckHost* OffTheRecordProfileImpl::GetSpellCheckHost() {
+ return profile_->GetSpellCheckHost();
+}
- virtual void set_last_selected_directory(const FilePath& path) {
- last_selected_directory_ = path;
- }
+void OffTheRecordProfileImpl::ReinitializeSpellCheckHost(bool force) {
+ profile_->ReinitializeSpellCheckHost(force);
+}
-#if defined(OS_CHROMEOS)
- virtual void SetupChromeOSEnterpriseExtensionObserver() {
- profile_->SetupChromeOSEnterpriseExtensionObserver();
- }
+WebKitContext* OffTheRecordProfileImpl::GetWebKitContext() {
+ CreateQuotaManagerAndClients();
+ return webkit_context_.get();
+}
- virtual void InitChromeOSPreferences() {
- // The incognito profile shouldn't have Chrome OS's preferences.
- // The preferences are associated with the regular user profile.
- }
-#endif // defined(OS_CHROMEOS)
+history::TopSites* OffTheRecordProfileImpl::GetTopSitesWithoutCreating() {
+ return NULL;
+}
- virtual void ExitedOffTheRecordMode() {
- // DownloadManager is lazily created, so check before accessing it.
- if (download_manager_.get()) {
- // Drop our download manager so we forget about all the downloads made
- // in incognito mode.
- download_manager_->Shutdown();
- download_manager_ = NULL;
- }
- }
+history::TopSites* OffTheRecordProfileImpl::GetTopSites() {
+ return NULL;
+}
- virtual void OnBrowserAdded(const Browser* browser) {
- }
+void OffTheRecordProfileImpl::MarkAsCleanShutdown() {
+}
- virtual void OnBrowserRemoved(const Browser* browser) {
- if (BrowserList::GetBrowserCount(this) == 0)
- ExitedOffTheRecordMode();
- }
+void OffTheRecordProfileImpl::InitExtensions(bool extensions_enabled) {
+ NOTREACHED();
+}
- virtual ChromeBlobStorageContext* GetBlobStorageContext() {
- if (!blob_storage_context_) {
- blob_storage_context_ = new ChromeBlobStorageContext();
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- blob_storage_context_.get(),
- &ChromeBlobStorageContext::InitializeOnIOThread));
- }
- return blob_storage_context_;
- }
+void OffTheRecordProfileImpl::InitPromoResources() {
+ NOTREACHED();
+}
- virtual ExtensionInfoMap* GetExtensionInfoMap() {
- return profile_->GetExtensionInfoMap();
- }
+void OffTheRecordProfileImpl::InitRegisteredProtocolHandlers() {
+ NOTREACHED();
+}
- virtual ChromeURLDataManager* GetChromeURLDataManager() {
- if (!chrome_url_data_manager_.get())
- chrome_url_data_manager_.reset(new ChromeURLDataManager(
- io_data_.GetChromeURLDataManagerBackendGetter()));
- return chrome_url_data_manager_.get();
+FilePath OffTheRecordProfileImpl::last_selected_directory() {
+ const FilePath& directory = last_selected_directory_;
+ if (directory.empty()) {
+ return profile_->last_selected_directory();
}
+ return directory;
+}
- virtual PromoCounter* GetInstantPromoCounter() {
- return NULL;
- }
+void OffTheRecordProfileImpl::set_last_selected_directory(
+ const FilePath& path) {
+ last_selected_directory_ = path;
+}
#if defined(OS_CHROMEOS)
- virtual void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) {
- }
- virtual void OnLogin() {
- }
-#endif // defined(OS_CHROMEOS)
+void OffTheRecordProfileImpl::SetupChromeOSEnterpriseExtensionObserver() {
+ profile_->SetupChromeOSEnterpriseExtensionObserver();
+}
- virtual PrefProxyConfigTracker* GetProxyConfigTracker() {
- if (!pref_proxy_config_tracker_)
- pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
+void OffTheRecordProfileImpl::InitChromeOSPreferences() {
+ // The incognito profile shouldn't have Chrome OS's preferences.
+ // The preferences are associated with the regular user profile.
+}
+#endif // defined(OS_CHROMEOS)
- return pref_proxy_config_tracker_;
+void OffTheRecordProfileImpl::ExitedOffTheRecordMode() {
+ // DownloadManager is lazily created, so check before accessing it.
+ if (download_manager_.get()) {
+ // Drop our download manager so we forget about all the downloads made
+ // in incognito mode.
+ download_manager_->Shutdown();
+ download_manager_ = NULL;
}
+}
- virtual prerender::PrerenderManager* GetPrerenderManager() {
- // We do not allow prerendering in OTR profiles at this point.
- // TODO(tburkard): Figure out if we want to support this, and how, at some
- // point in the future.
- return NULL;
- }
+void OffTheRecordProfileImpl::OnBrowserAdded(const Browser* browser) {
+}
- private:
- void CreateQuotaManagerAndClients() {
- if (quota_manager_.get()) {
- DCHECK(file_system_context_.get());
- DCHECK(db_tracker_.get());
- DCHECK(webkit_context_.get());
- return;
- }
+void OffTheRecordProfileImpl::OnBrowserRemoved(const Browser* browser) {
+ if (BrowserList::GetBrowserCount(this) == 0)
+ ExitedOffTheRecordMode();
+}
- // All of the clients have to be created and registered with the
- // QuotaManager prior to the QuotaManger being used. So we do them
- // all together here prior to handing out a reference to anything
- // that utlizes the QuotaManager.
- quota_manager_ = new quota::QuotaManager(
- IsOffTheRecord(),
- GetPath(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
- GetExtensionSpecialStoragePolicy());
-
- // Each consumer is responsible for registering its QuotaClient during
- // its construction.
- file_system_context_ = CreateFileSystemContext(
- GetPath(), IsOffTheRecord(),
- GetExtensionSpecialStoragePolicy(),
- quota_manager_->proxy());
- db_tracker_ = new webkit_database::DatabaseTracker(
- GetPath(), IsOffTheRecord(), false, GetExtensionSpecialStoragePolicy(),
- quota_manager_->proxy(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
- webkit_context_ = new WebKitContext(
- IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
- false, quota_manager_->proxy(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT));
- appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
+ChromeBlobStorageContext* OffTheRecordProfileImpl::GetBlobStorageContext() {
+ if (!blob_storage_context_) {
+ blob_storage_context_ = new ChromeBlobStorageContext();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- appcache_service_.get(),
- &ChromeAppCacheService::InitializeOnIOThread,
- IsOffTheRecord()
- ? FilePath() : GetPath().Append(chrome::kAppCacheDirname),
- &GetResourceContext(),
- make_scoped_refptr(GetExtensionSpecialStoragePolicy())));
+ blob_storage_context_.get(),
+ &ChromeBlobStorageContext::InitializeOnIOThread));
}
+ return blob_storage_context_;
+}
- NotificationRegistrar registrar_;
-
- // The real underlying profile.
- Profile* profile_;
-
- // Weak pointer owned by |profile_|.
- PrefService* prefs_;
-
- scoped_ptr<ExtensionProcessManager> extension_process_manager_;
-
- OffTheRecordProfileIOData::Handle io_data_;
-
- // Used so that Chrome code can influence how content module's DownloadManager
- // functions.
- scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_;
-
- // The download manager that only stores downloaded items in memory.
- scoped_refptr<DownloadManager> download_manager_;
-
- // We use a non-persistent content settings map for OTR.
- scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
-
- // Use a separate zoom map for OTR.
- scoped_refptr<HostZoomMap> host_zoom_map_;
-
- // Use a special WebKit context for OTR browsing.
- scoped_refptr<WebKitContext> webkit_context_;
-
- // We don't want SSLHostState from the OTR profile to leak back to the main
- // profile because then the main profile would learn some of the host names
- // the user visited while OTR.
- scoped_ptr<SSLHostState> ssl_host_state_;
-
- // Use a separate FindBarState so search terms do not leak back to the main
- // profile.
- scoped_ptr<FindBarState> find_bar_state_;
-
- // The TransportSecurityState that only stores enabled sites in memory.
- scoped_refptr<net::TransportSecurityState>
- transport_security_state_;
-
- // Time we were started.
- Time start_time_;
-
- scoped_refptr<ChromeAppCacheService> appcache_service_;
-
- // The main database tracker for this profile.
- // Should be used only on the file thread.
- scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
+ExtensionInfoMap* OffTheRecordProfileImpl::GetExtensionInfoMap() {
+ return profile_->GetExtensionInfoMap();
+}
- FilePath last_selected_directory_;
+ChromeURLDataManager* OffTheRecordProfileImpl::GetChromeURLDataManager() {
+ if (!chrome_url_data_manager_.get())
+ chrome_url_data_manager_.reset(new ChromeURLDataManager(
+ io_data_.GetChromeURLDataManagerBackendGetter()));
+ return chrome_url_data_manager_.get();
+}
- scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
+PromoCounter* OffTheRecordProfileImpl::GetInstantPromoCounter() {
+ return NULL;
+}
- // The file_system context for this profile.
- scoped_refptr<fileapi::FileSystemContext> file_system_context_;
+#if defined(OS_CHROMEOS)
+void OffTheRecordProfileImpl::ChangeAppLocale(const std::string& locale,
+ AppLocaleChangedVia) {
+}
- scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
+void OffTheRecordProfileImpl::OnLogin() {
+}
+#endif // defined(OS_CHROMEOS)
- scoped_ptr<ChromeURLDataManager> chrome_url_data_manager_;
+PrefProxyConfigTracker* OffTheRecordProfileImpl::GetProxyConfigTracker() {
+ if (!pref_proxy_config_tracker_)
+ pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
+ return pref_proxy_config_tracker_;
+}
- scoped_refptr<quota::QuotaManager> quota_manager_;
+prerender::PrerenderManager* OffTheRecordProfileImpl::GetPrerenderManager() {
+ // We do not allow prerendering in OTR profiles at this point.
+ // TODO(tburkard): Figure out if we want to support this, and how, at some
+ // point in the future.
+ return NULL;
+}
- // Used read-only.
- scoped_refptr<TransportSecurityPersister> transport_security_loader_;
+void OffTheRecordProfileImpl::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) {
+ const std::string& host = *(Details<const std::string>(details).ptr());
+ if (!host.empty()) {
+ double level = profile_->GetHostZoomMap()->GetZoomLevel(host);
+ GetHostZoomMap()->SetZoomLevel(host, level);
+ }
+ }
+}
- DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
-};
+void OffTheRecordProfileImpl::CreateQuotaManagerAndClients() {
+ if (quota_manager_.get()) {
+ DCHECK(file_system_context_.get());
+ DCHECK(db_tracker_.get());
+ DCHECK(webkit_context_.get());
+ return;
+ }
+
+ // All of the clients have to be created and registered with the
+ // QuotaManager prior to the QuotaManger being used. So we do them
+ // all together here prior to handing out a reference to anything
+ // that utlizes the QuotaManager.
+ quota_manager_ = new quota::QuotaManager(
+ IsOffTheRecord(),
+ GetPath(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
+ GetExtensionSpecialStoragePolicy());
+
+ // Each consumer is responsible for registering its QuotaClient during
+ // its construction.
+ file_system_context_ = CreateFileSystemContext(
+ GetPath(), IsOffTheRecord(),
+ GetExtensionSpecialStoragePolicy(),
+ quota_manager_->proxy());
+ db_tracker_ = new webkit_database::DatabaseTracker(
+ GetPath(), IsOffTheRecord(), false, GetExtensionSpecialStoragePolicy(),
+ quota_manager_->proxy(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
+ webkit_context_ = new WebKitContext(
+ IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
+ false, quota_manager_->proxy(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT));
+ appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ appcache_service_.get(),
+ &ChromeAppCacheService::InitializeOnIOThread,
+ IsOffTheRecord()
+ ? FilePath() : GetPath().Append(chrome::kAppCacheDirname),
+ &GetResourceContext(),
+ make_scoped_refptr(GetExtensionSpecialStoragePolicy())));
+}
#if defined(OS_CHROMEOS)
// Special case of the OffTheRecordProfileImpl which is used while Guest
@@ -736,5 +689,7 @@ Profile* Profile::CreateOffTheRecordProfile() {
if (Profile::IsGuestSession())
return new GuestSessionProfile(this);
#endif
- return new OffTheRecordProfileImpl(this);
+ OffTheRecordProfileImpl* profile = new OffTheRecordProfileImpl(this);
+ profile->Init();
+ return profile;
}
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
new file mode 100644
index 0000000..fbef5ab
--- /dev/null
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -0,0 +1,211 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_
+#define CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/download/chrome_download_manager_delegate.h"
+#include "chrome/browser/profiles/off_the_record_profile_io_data.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "content/common/notification_observer.h"
+
+using base::Time;
+using base::TimeDelta;
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
+// to make it suitable for the incognito mode.
+//
+// Note: This class is a leaf class and is not intended for subclassing.
+// Providing this header file is for unit testing.
+//
+////////////////////////////////////////////////////////////////////////////////
+class OffTheRecordProfileImpl : public Profile,
+ public BrowserList::Observer,
+ public NotificationObserver {
+ public:
+ explicit OffTheRecordProfileImpl(Profile* real_profile);
+ virtual ~OffTheRecordProfileImpl();
+ void Init();
+
+ // Profile implementation.
+ virtual std::string GetProfileName() OVERRIDE;
+ virtual FilePath GetPath() OVERRIDE;
+ virtual bool IsOffTheRecord() OVERRIDE;
+ virtual Profile* GetOffTheRecordProfile() OVERRIDE;
+ virtual void DestroyOffTheRecordProfile() OVERRIDE;
+ virtual bool HasOffTheRecordProfile() OVERRIDE;
+ virtual Profile* GetOriginalProfile() OVERRIDE;
+ virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
+ virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
+ virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE;
+ virtual ExtensionService* GetExtensionService() OVERRIDE;
+ virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE;
+ virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() OVERRIDE;
+ virtual ExtensionProcessManager* GetExtensionProcessManager() OVERRIDE;
+ virtual ExtensionMessageService* GetExtensionMessageService() OVERRIDE;
+ virtual ExtensionEventRouter* GetExtensionEventRouter() OVERRIDE;
+ virtual ExtensionSpecialStoragePolicy*
+ GetExtensionSpecialStoragePolicy() OVERRIDE;
+ virtual SSLHostState* GetSSLHostState() OVERRIDE;
+ virtual net::TransportSecurityState* GetTransportSecurityState() OVERRIDE;
+ virtual HistoryService* GetHistoryService(ServiceAccessType sat) OVERRIDE;
+ virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE;
+ virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE;
+ virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE;
+ virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE;
+ virtual WebDataService* GetWebDataService(ServiceAccessType sat) OVERRIDE;
+ virtual WebDataService* GetWebDataServiceWithoutCreating() OVERRIDE;
+ virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) OVERRIDE;
+ virtual PrefService* GetPrefs() OVERRIDE;
+ virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
+ virtual TemplateURLFetcher* GetTemplateURLFetcher() OVERRIDE;
+ virtual DownloadManager* GetDownloadManager() OVERRIDE;
+ virtual bool HasCreatedDownloadManager() const OVERRIDE;
+ virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE;
+ virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
+ virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
+ virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
+ virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
+ int renderer_child_id) OVERRIDE;
+ virtual net::URLRequestContextGetter* GetRequestContextForMedia() OVERRIDE;
+ virtual net::URLRequestContextGetter*
+ GetRequestContextForExtensions() OVERRIDE;
+ virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp(
+ const std::string& app_id) OVERRIDE;
+ virtual const content::ResourceContext& GetResourceContext() OVERRIDE;
+ virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
+ virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
+ virtual HostZoomMap* GetHostZoomMap() OVERRIDE;
+ virtual GeolocationPermissionContext*
+ GetGeolocationPermissionContext() OVERRIDE;
+ virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE;
+ virtual FindBarState* GetFindBarState() OVERRIDE;
+ virtual bool HasProfileSyncService() const OVERRIDE;
+ virtual bool DidLastSessionExitCleanly() OVERRIDE;
+ virtual BookmarkModel* GetBookmarkModel() OVERRIDE;
+ virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE;
+ virtual TokenService* GetTokenService() OVERRIDE;
+ virtual ProfileSyncService* GetProfileSyncService() OVERRIDE;
+ virtual ProfileSyncService* GetProfileSyncService(
+ const std::string& cros_user) OVERRIDE;
+ virtual bool IsSameProfile(Profile* profile) OVERRIDE;
+ virtual Time GetStartTime() const OVERRIDE;
+ virtual SpellCheckHost* GetSpellCheckHost() OVERRIDE;
+ virtual void ReinitializeSpellCheckHost(bool force) OVERRIDE;
+ virtual WebKitContext* GetWebKitContext() OVERRIDE;
+ virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
+ virtual history::TopSites* GetTopSites() OVERRIDE;
+ virtual void MarkAsCleanShutdown() OVERRIDE;
+ virtual void InitExtensions(bool extensions_enabled) OVERRIDE;
+ virtual void InitPromoResources() OVERRIDE;
+ virtual void InitRegisteredProtocolHandlers() OVERRIDE;
+ virtual FilePath last_selected_directory() OVERRIDE;
+ virtual void set_last_selected_directory(const FilePath& path) OVERRIDE;
+
+#if defined(OS_CHROMEOS)
+ virtual void SetupChromeOSEnterpriseExtensionObserver() OVERRIDE;
+ virtual void InitChromeOSPreferences() OVERRIDE;
+#endif // defined(OS_CHROMEOS)
+
+ virtual void ExitedOffTheRecordMode();
+ virtual void OnBrowserAdded(const Browser* browser) OVERRIDE;
+ virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE;
+ virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE;
+ virtual ExtensionInfoMap* GetExtensionInfoMap() OVERRIDE;
+ virtual ChromeURLDataManager* GetChromeURLDataManager() OVERRIDE;
+ virtual PromoCounter* GetInstantPromoCounter() OVERRIDE;
+
+#if defined(OS_CHROMEOS)
+ virtual void ChangeAppLocale(const std::string& locale,
+ AppLocaleChangedVia) OVERRIDE;
+ virtual void OnLogin() OVERRIDE;
+#endif // defined(OS_CHROMEOS)
+
+ virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
+ virtual prerender::PrerenderManager* GetPrerenderManager() OVERRIDE;
+
+ // NotificationObserver implementation.
+ virtual void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE;
+
+ private:
+ void CreateQuotaManagerAndClients();
+
+ NotificationRegistrar registrar_;
+
+ // The real underlying profile.
+ Profile* profile_;
+
+ // Weak pointer owned by |profile_|.
+ PrefService* prefs_;
+
+ scoped_ptr<ExtensionProcessManager> extension_process_manager_;
+
+ OffTheRecordProfileIOData::Handle io_data_;
+
+ // Used so that Chrome code can influence how content module's DownloadManager
+ // functions.
+ scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_;
+
+ // The download manager that only stores downloaded items in memory.
+ scoped_refptr<DownloadManager> download_manager_;
+
+ // We use a non-persistent content settings map for OTR.
+ scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
+
+ // Use a separate zoom map for OTR.
+ scoped_refptr<HostZoomMap> host_zoom_map_;
+
+ // Use a special WebKit context for OTR browsing.
+ scoped_refptr<WebKitContext> webkit_context_;
+
+ // We don't want SSLHostState from the OTR profile to leak back to the main
+ // profile because then the main profile would learn some of the host names
+ // the user visited while OTR.
+ scoped_ptr<SSLHostState> ssl_host_state_;
+
+ // Use a separate FindBarState so search terms do not leak back to the main
+ // profile.
+ scoped_ptr<FindBarState> find_bar_state_;
+
+ // The TransportSecurityState that only stores enabled sites in memory.
+ scoped_refptr<net::TransportSecurityState>
+ transport_security_state_;
+
+ // Time we were started.
+ Time start_time_;
+
+ scoped_refptr<ChromeAppCacheService> appcache_service_;
+
+ // The main database tracker for this profile.
+ // Should be used only on the file thread.
+ scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
+
+ FilePath last_selected_directory_;
+
+ scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
+
+ // The file_system context for this profile.
+ scoped_refptr<fileapi::FileSystemContext> file_system_context_;
+
+ scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
+
+ scoped_ptr<ChromeURLDataManager> chrome_url_data_manager_;
+
+ scoped_refptr<quota::QuotaManager> quota_manager_;
+
+ // Used read-only.
+ scoped_refptr<TransportSecurityPersister> transport_security_loader_;
+
+ DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
+};
+
+#endif // CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_
diff --git a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
new file mode 100644
index 0000000..a4d786d
--- /dev/null
+++ b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
@@ -0,0 +1,167 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/profiles/off_the_record_profile_impl.h"
+
+#include "chrome/browser/net/ssl_config_service_manager.h"
+#include "chrome/browser/prefs/browser_prefs.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/browser_with_test_window_test.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_pref_service.h"
+#include "chrome/test/base/testing_profile.h"
+#include "content/browser/host_zoom_map.h"
+
+namespace {
+
+class TestingProfileWithHostZoomMap : public TestingProfile,
+ public NotificationObserver {
+ public:
+ TestingProfileWithHostZoomMap() {}
+
+ virtual ~TestingProfileWithHostZoomMap() {}
+
+ virtual HostZoomMap* GetHostZoomMap() {
+ if (!host_zoom_map_) {
+ host_zoom_map_ = new HostZoomMap();
+
+ registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ Source<HostZoomMap>(host_zoom_map_));
+ }
+ return host_zoom_map_.get();
+ }
+
+ virtual Profile* GetOffTheRecordProfile() OVERRIDE {
+ if (!off_the_record_profile_.get())
+ off_the_record_profile_.reset(CreateOffTheRecordProfile());
+ return off_the_record_profile_.get();
+ }
+
+ virtual PrefService* GetOffTheRecordPrefs() OVERRIDE {
+ return GetPrefs();
+ }
+
+ virtual void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE {
+ const std::string& host = *(Details<const std::string>(details).ptr());
+ if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) {
+ if (!host.empty()) {
+ double level = host_zoom_map_->GetZoomLevel(host);
+ DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
+ DictionaryValue* host_zoom_dictionary = update.Get();
+ if (level == host_zoom_map_->default_zoom_level()) {
+ host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
+ } else {
+ host_zoom_dictionary->SetWithoutPathExpansion(
+ host, Value::CreateDoubleValue(level));
+ }
+ }
+ }
+ }
+
+ private:
+ NotificationRegistrar registrar_;
+ scoped_refptr<HostZoomMap> host_zoom_map_;
+ scoped_ptr<Profile> off_the_record_profile_;
+ scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap);
+};
+
+} // namespace
+
+// We need to have a BrowserProcess in g_browser_process variable, since
+// OffTheRecordProfileImpl ctor uses it in
+// ProfileIOData::InitializeProfileParams.
+class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
+ protected:
+ OffTheRecordProfileImplTest() {}
+
+ virtual ~OffTheRecordProfileImplTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ prefs_.reset(new TestingPrefService);
+ browser::RegisterLocalState(prefs_.get());
+
+ browser_process()->SetLocalState(prefs_.get());
+
+ BrowserWithTestWindowTest::SetUp();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ BrowserWithTestWindowTest::TearDown();
+ browser_process()->SetLocalState(NULL);
+ DestroyBrowser();
+ prefs_.reset();
+ }
+
+ private:
+ TestingBrowserProcess* browser_process() {
+ return static_cast<TestingBrowserProcess*>(g_browser_process);
+ }
+
+ scoped_ptr<PrefService> prefs_;
+
+ DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImplTest);
+};
+
+// Test four things:
+// 1. Host zoom maps of parent profile and child profile are different.
+// 2. Child host zoom map inherites zoom level at construction.
+// 3. Change of zoom level doesn't propagate from child to parent.
+// 4. Change of zoom level propagate from parent to child.
+TEST_F(OffTheRecordProfileImplTest, GetHostZoomMap) {
+ // Constants for test case.
+ std::string const host("example.com");
+ double const zoom_level_25 = 2.5;
+ double const zoom_level_30 = 3.0;
+ double const zoom_level_40 = 4.0;
+
+ // Prepare parent profile.
+ scoped_ptr<Profile> parent_profile(new TestingProfileWithHostZoomMap);
+ ASSERT_TRUE(parent_profile.get());
+ ASSERT_TRUE(parent_profile->GetPrefs());
+ ASSERT_TRUE(parent_profile->GetOffTheRecordPrefs());
+
+ // Prepare parent host zoom map.
+ HostZoomMap* parent_zoom_map = parent_profile->GetHostZoomMap();
+ ASSERT_TRUE(parent_zoom_map);
+
+ parent_zoom_map->SetZoomLevel(host, zoom_level_25);
+ ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_25);
+
+ // TODO(yosin) We need to wait ProfileImpl::Observe done for
+ // NOTIFICATION_ZOOM_LEVEL_CHANGED.
+
+ // Prepare child profile as off the record profile.
+ scoped_ptr<Profile> child_profile(
+ new OffTheRecordProfileImpl(parent_profile.get()));
+
+ // Prepare child host zoom map.
+ HostZoomMap* child_zoom_map = child_profile->GetHostZoomMap();
+ ASSERT_TRUE(child_zoom_map);
+
+ // Verity.
+ EXPECT_NE(parent_zoom_map, child_zoom_map);
+
+ EXPECT_EQ(parent_zoom_map->GetZoomLevel(host),
+ child_zoom_map->GetZoomLevel(host)) <<
+ "Child must inherit from parent.";
+
+ child_zoom_map->SetZoomLevel(host, zoom_level_30);
+ ASSERT_EQ(child_zoom_map->GetZoomLevel(host), zoom_level_30);
+
+ EXPECT_NE(parent_zoom_map->GetZoomLevel(host),
+ child_zoom_map->GetZoomLevel(host)) <<
+ "Child change must not propaget to parent.";
+
+ parent_zoom_map->SetZoomLevel(host, zoom_level_40);
+ ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_40);
+
+ EXPECT_EQ(parent_zoom_map->GetZoomLevel(host),
+ child_zoom_map->GetZoomLevel(host)) <<
+ "Parent change should propaget to child.";
+}