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

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

Issue 9416070: Move creation and ownership of HostZoomMap to content instead of having every embedder do this. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac/cros browsertests Created 8 years, 10 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
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 239 }
240 240
241 ProfileImpl::ProfileImpl(const FilePath& path, 241 ProfileImpl::ProfileImpl(const FilePath& path,
242 Profile::Delegate* delegate) 242 Profile::Delegate* delegate)
243 : path_(path), 243 : path_(path),
244 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( 244 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_(
245 new VisitedLinkEventListener(this))), 245 new VisitedLinkEventListener(this))),
246 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), 246 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
247 extension_devtools_manager_(NULL), 247 extension_devtools_manager_(NULL),
248 host_content_settings_map_(NULL), 248 host_content_settings_map_(NULL),
249 host_zoom_map_(NULL),
250 history_service_created_(false), 249 history_service_created_(false),
251 favicon_service_created_(false), 250 favicon_service_created_(false),
252 created_web_data_service_(false), 251 created_web_data_service_(false),
253 created_password_store_(false), 252 created_password_store_(false),
254 start_time_(Time::Now()), 253 start_time_(Time::Now()),
255 #if defined(OS_WIN) 254 #if defined(OS_WIN)
256 checked_instant_promo_(false), 255 checked_instant_promo_(false),
257 #endif 256 #endif
258 delegate_(delegate), 257 delegate_(delegate),
259 predictor_(NULL), 258 predictor_(NULL),
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname); 384 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname);
386 385
387 SessionStartupPref startup_pref = 386 SessionStartupPref startup_pref =
388 BrowserInit::GetSessionStartupPref(*CommandLine::ForCurrentProcess(), 387 BrowserInit::GetSessionStartupPref(*CommandLine::ForCurrentProcess(),
389 this); 388 this);
390 bool restore_old_session_cookies = 389 bool restore_old_session_cookies =
391 session_restore_enabled_ && 390 session_restore_enabled_ &&
392 (!DidLastSessionExitCleanly() || 391 (!DidLastSessionExitCleanly() ||
393 startup_pref.type == SessionStartupPref::LAST); 392 startup_pref.type == SessionStartupPref::LAST);
394 393
394 InitHostZoomMap();
395
395 // Make sure we initialize the ProfileIOData after everything else has been 396 // Make sure we initialize the ProfileIOData after everything else has been
396 // initialized that we might be reading from the IO thread. 397 // initialized that we might be reading from the IO thread.
397 398
398 io_data_.Init(cookie_path, origin_bound_cert_path, cache_path, 399 io_data_.Init(cookie_path, origin_bound_cert_path, cache_path,
399 cache_max_size, media_cache_path, media_cache_max_size, 400 cache_max_size, media_cache_path, media_cache_max_size,
400 extensions_cookie_path, app_path, predictor_, 401 extensions_cookie_path, app_path, predictor_,
401 g_browser_process->local_state(), 402 g_browser_process->local_state(),
402 g_browser_process->io_thread(), 403 g_browser_process->io_thread(),
403 restore_old_session_cookies); 404 restore_old_session_cookies);
404 405
405 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( 406 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
406 PluginPrefs::GetForProfile(this), 407 PluginPrefs::GetForProfile(this),
407 io_data_.GetResourceContextNoInit()); 408 io_data_.GetResourceContextNoInit());
408 409
409 // Creation has been finished. 410 // Creation has been finished.
410 if (delegate_) 411 if (delegate_)
411 delegate_->OnProfileCreated(this, true); 412 delegate_->OnProfileCreated(this, true);
412 413
413 content::NotificationService::current()->Notify( 414 content::NotificationService::current()->Notify(
414 chrome::NOTIFICATION_PROFILE_CREATED, 415 chrome::NOTIFICATION_PROFILE_CREATED,
415 content::Source<Profile>(this), 416 content::Source<Profile>(this),
416 content::NotificationService::NoDetails()); 417 content::NotificationService::NoDetails());
417 } 418 }
418 419
420 void ProfileImpl::InitHostZoomMap() {
421 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
422 host_zoom_map->SetDefaultZoomLevel(
423 prefs_->GetDouble(prefs::kDefaultZoomLevel));
424
425 const DictionaryValue* host_zoom_dictionary =
426 prefs_->GetDictionary(prefs::kPerHostZoomLevels);
427 // Careful: The returned value could be NULL if the pref has never been set.
428 if (host_zoom_dictionary != NULL) {
429 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys());
430 i != host_zoom_dictionary->end_keys(); ++i) {
431 const std::string& host(*i);
432 double zoom_level = 0;
433
434 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion(
435 host, &zoom_level);
436 DCHECK(success);
437 host_zoom_map->SetZoomLevel(host, zoom_level);
438 }
439 }
440
441 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
442 content::Source<HostZoomMap>(host_zoom_map));
443 }
444
419 void ProfileImpl::InitExtensions(bool extensions_enabled) { 445 void ProfileImpl::InitExtensions(bool extensions_enabled) {
420 if (user_script_master_ || extension_service_.get()) 446 if (user_script_master_ || extension_service_.get())
421 return; // Already initialized. 447 return; // Already initialized.
422 448
423 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 449 const CommandLine* command_line = CommandLine::ForCurrentProcess();
424 if (command_line->HasSwitch( 450 if (command_line->HasSwitch(
425 switches::kEnableExtensionTimelineApi)) { 451 switches::kEnableExtensionTimelineApi)) {
426 extension_devtools_manager_ = new ExtensionDevToolsManager(this); 452 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
427 } 453 }
428 454
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 891 }
866 892
867 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { 893 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
868 if (!host_content_settings_map_.get()) { 894 if (!host_content_settings_map_.get()) {
869 host_content_settings_map_ = new HostContentSettingsMap( 895 host_content_settings_map_ = new HostContentSettingsMap(
870 GetPrefs(), GetExtensionService(), false); 896 GetPrefs(), GetExtensionService(), false);
871 } 897 }
872 return host_content_settings_map_.get(); 898 return host_content_settings_map_.get();
873 } 899 }
874 900
875 HostZoomMap* ProfileImpl::GetHostZoomMap() {
876 if (!host_zoom_map_) {
877 host_zoom_map_ = HostZoomMap::Create();
878 host_zoom_map_->SetDefaultZoomLevel(
879 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel));
880
881 const DictionaryValue* host_zoom_dictionary =
882 prefs_->GetDictionary(prefs::kPerHostZoomLevels);
883 // Careful: The returned value could be NULL if the pref has never been set.
884 if (host_zoom_dictionary != NULL) {
885 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys());
886 i != host_zoom_dictionary->end_keys(); ++i) {
887 const std::string& host(*i);
888 double zoom_level = 0;
889
890 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion(
891 host, &zoom_level);
892 DCHECK(success);
893 host_zoom_map_->SetZoomLevel(host, zoom_level);
894 }
895 }
896
897 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
898 content::Source<HostZoomMap>(host_zoom_map_));
899 }
900 return host_zoom_map_.get();
901 }
902
903 content::GeolocationPermissionContext* 901 content::GeolocationPermissionContext*
904 ProfileImpl::GetGeolocationPermissionContext() { 902 ProfileImpl::GetGeolocationPermissionContext() {
905 if (!geolocation_permission_context_.get()) { 903 if (!geolocation_permission_context_.get()) {
906 geolocation_permission_context_ = 904 geolocation_permission_context_ =
907 new ChromeGeolocationPermissionContext(this); 905 new ChromeGeolocationPermissionContext(this);
908 } 906 }
909 return geolocation_permission_context_.get(); 907 return geolocation_permission_context_.get();
910 } 908 }
911 909
912 content::SpeechInputPreferences* ProfileImpl::GetSpeechInputPreferences() { 910 content::SpeechInputPreferences* ProfileImpl::GetSpeechInputPreferences() {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { 1202 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) {
1205 clear_local_state_on_exit_ = 1203 clear_local_state_on_exit_ =
1206 prefs->GetBoolean(prefs::kClearSiteDataOnExit); 1204 prefs->GetBoolean(prefs::kClearSiteDataOnExit);
1207 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { 1205 } else if (*pref_name_in == prefs::kGoogleServicesUsername) {
1208 UpdateProfileUserNameCache(); 1206 UpdateProfileUserNameCache();
1209 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { 1207 } else if (*pref_name_in == prefs::kProfileAvatarIndex) {
1210 UpdateProfileAvatarCache(); 1208 UpdateProfileAvatarCache();
1211 } else if (*pref_name_in == prefs::kProfileName) { 1209 } else if (*pref_name_in == prefs::kProfileName) {
1212 UpdateProfileNameCache(); 1210 UpdateProfileNameCache();
1213 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { 1211 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
1214 GetHostZoomMap()->SetDefaultZoomLevel( 1212 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel(
1215 prefs->GetDouble(prefs::kDefaultZoomLevel)); 1213 prefs->GetDouble(prefs::kDefaultZoomLevel));
1216 } 1214 }
1217 break; 1215 break;
1218 } 1216 }
1219 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: 1217 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED:
1220 // Causes lazy-load if sync is enabled. 1218 // Causes lazy-load if sync is enabled.
1221 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); 1219 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this);
1222 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, 1220 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED,
1223 content::Source<Profile>(this)); 1221 content::Source<Profile>(this));
1224 break; 1222 break;
1225 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { 1223 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: {
1226 const std::string& host = 1224 const std::string& host =
1227 *(content::Details<const std::string>(details).ptr()); 1225 *(content::Details<const std::string>(details).ptr());
1228 if (!host.empty()) { 1226 if (!host.empty()) {
1229 double level = host_zoom_map_->GetZoomLevel(host); 1227 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
1228 double level = host_zoom_map->GetZoomLevel(host);
1230 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); 1229 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
1231 DictionaryValue* host_zoom_dictionary = update.Get(); 1230 DictionaryValue* host_zoom_dictionary = update.Get();
1232 if (level == host_zoom_map_->GetDefaultZoomLevel()) { 1231 if (level == host_zoom_map->GetDefaultZoomLevel()) {
1233 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); 1232 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
1234 } else { 1233 } else {
1235 host_zoom_dictionary->SetWithoutPathExpansion( 1234 host_zoom_dictionary->SetWithoutPathExpansion(
1236 host, Value::CreateDoubleValue(level)); 1235 host, Value::CreateDoubleValue(level));
1237 } 1236 }
1238 } 1237 }
1239 break; 1238 break;
1240 } 1239 }
1241 default: 1240 default:
1242 NOTREACHED(); 1241 NOTREACHED();
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 FilePath* cache_path, 1482 FilePath* cache_path,
1484 int* max_size) { 1483 int* max_size) {
1485 DCHECK(cache_path); 1484 DCHECK(cache_path);
1486 DCHECK(max_size); 1485 DCHECK(max_size);
1487 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); 1486 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1488 if (!path.empty()) 1487 if (!path.empty())
1489 *cache_path = path; 1488 *cache_path = path;
1490 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1489 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1491 prefs_->GetInteger(prefs::kDiskCacheSize); 1490 prefs_->GetInteger(prefs::kDiskCacheSize);
1492 } 1491 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698