| OLD | NEW |
| 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/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, | 315 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, |
| 316 false, | 316 false, |
| 317 PrefServiceSyncable::SYNCABLE_PREF); | 317 PrefServiceSyncable::SYNCABLE_PREF); |
| 318 } | 318 } |
| 319 | 319 |
| 320 ProfileImpl::ProfileImpl( | 320 ProfileImpl::ProfileImpl( |
| 321 const FilePath& path, | 321 const FilePath& path, |
| 322 Delegate* delegate, | 322 Delegate* delegate, |
| 323 CreateMode create_mode, | 323 CreateMode create_mode, |
| 324 base::SequencedTaskRunner* sequenced_task_runner) | 324 base::SequencedTaskRunner* sequenced_task_runner) |
| 325 : path_(path), | 325 : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged, |
| 326 base::Unretained(this))), |
| 327 path_(path), |
| 326 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 328 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
| 327 host_content_settings_map_(NULL), | 329 host_content_settings_map_(NULL), |
| 328 last_session_exit_type_(EXIT_NORMAL), | 330 last_session_exit_type_(EXIT_NORMAL), |
| 329 start_time_(Time::Now()), | 331 start_time_(Time::Now()), |
| 330 delegate_(delegate), | 332 delegate_(delegate), |
| 331 predictor_(NULL) { | 333 predictor_(NULL) { |
| 332 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 334 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 333 "profile files to the root directory!"; | 335 "profile files to the root directory!"; |
| 334 | 336 |
| 335 #if defined(ENABLE_SESSION_SERVICE) | 337 #if defined(ENABLE_SESSION_SERVICE) |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 const std::string& host(*i); | 562 const std::string& host(*i); |
| 561 double zoom_level = 0; | 563 double zoom_level = 0; |
| 562 | 564 |
| 563 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( | 565 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( |
| 564 host, &zoom_level); | 566 host, &zoom_level); |
| 565 DCHECK(success); | 567 DCHECK(success); |
| 566 host_zoom_map->SetZoomLevel(host, zoom_level); | 568 host_zoom_map->SetZoomLevel(host, zoom_level); |
| 567 } | 569 } |
| 568 } | 570 } |
| 569 | 571 |
| 570 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 572 host_zoom_map->AddZoomLevelChangedCallback(zoom_callback_); |
| 571 content::Source<HostZoomMap>(host_zoom_map)); | |
| 572 } | 573 } |
| 573 | 574 |
| 574 FilePath ProfileImpl::last_selected_directory() { | 575 FilePath ProfileImpl::last_selected_directory() { |
| 575 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 576 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
| 576 } | 577 } |
| 577 | 578 |
| 578 void ProfileImpl::set_last_selected_directory(const FilePath& path) { | 579 void ProfileImpl::set_last_selected_directory(const FilePath& path) { |
| 579 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 580 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 580 } | 581 } |
| 581 | 582 |
| 582 ProfileImpl::~ProfileImpl() { | 583 ProfileImpl::~ProfileImpl() { |
| 583 MaybeSendDestroyedNotification(); | 584 MaybeSendDestroyedNotification(); |
| 584 | 585 |
| 586 HostZoomMap::GetForBrowserContext(this)->RemoveZoomLevelChangedCallback( |
| 587 zoom_callback_); |
| 588 |
| 585 bool prefs_loaded = prefs_->GetInitializationStatus() != | 589 bool prefs_loaded = prefs_->GetInitializationStatus() != |
| 586 PrefService::INITIALIZATION_STATUS_WAITING; | 590 PrefService::INITIALIZATION_STATUS_WAITING; |
| 587 | 591 |
| 588 #if defined(ENABLE_SESSION_SERVICE) | 592 #if defined(ENABLE_SESSION_SERVICE) |
| 589 StopCreateSessionServiceTimer(); | 593 StopCreateSessionServiceTimer(); |
| 590 #endif | 594 #endif |
| 591 | 595 |
| 592 // Remove pref observers | 596 // Remove pref observers |
| 593 pref_change_registrar_.RemoveAll(); | 597 pref_change_registrar_.RemoveAll(); |
| 594 | 598 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 void ProfileImpl::Observe(int type, | 927 void ProfileImpl::Observe(int type, |
| 924 const content::NotificationSource& source, | 928 const content::NotificationSource& source, |
| 925 const content::NotificationDetails& details) { | 929 const content::NotificationDetails& details) { |
| 926 switch (type) { | 930 switch (type) { |
| 927 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: | 931 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: |
| 928 // Causes lazy-load if sync is enabled. | 932 // Causes lazy-load if sync is enabled. |
| 929 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); | 933 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); |
| 930 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 934 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
| 931 content::Source<Profile>(this)); | 935 content::Source<Profile>(this)); |
| 932 break; | 936 break; |
| 933 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { | |
| 934 const std::string& host = | |
| 935 *(content::Details<const std::string>(details).ptr()); | |
| 936 if (!host.empty()) { | |
| 937 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | |
| 938 double level = host_zoom_map->GetZoomLevel(host); | |
| 939 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
| 940 DictionaryValue* host_zoom_dictionary = update.Get(); | |
| 941 if (level == host_zoom_map->GetDefaultZoomLevel()) { | |
| 942 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); | |
| 943 } else { | |
| 944 host_zoom_dictionary->SetWithoutPathExpansion( | |
| 945 host, Value::CreateDoubleValue(level)); | |
| 946 } | |
| 947 } | |
| 948 break; | |
| 949 } | |
| 950 default: | 937 default: |
| 951 NOTREACHED(); | 938 NOTREACHED(); |
| 952 } | 939 } |
| 953 } | 940 } |
| 954 | 941 |
| 955 void ProfileImpl::OnDefaultZoomLevelChanged() { | 942 void ProfileImpl::OnDefaultZoomLevelChanged() { |
| 956 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | 943 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( |
| 957 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); | 944 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); |
| 958 } | 945 } |
| 959 | 946 |
| 947 void ProfileImpl::OnZoomLevelChanged(const std::string& host) { |
| 948 if (host.empty()) |
| 949 return; |
| 950 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); |
| 951 double level = host_zoom_map->GetZoomLevel(host); |
| 952 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); |
| 953 DictionaryValue* host_zoom_dictionary = update.Get(); |
| 954 if (level == host_zoom_map->GetDefaultZoomLevel()) { |
| 955 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); |
| 956 } else { |
| 957 host_zoom_dictionary->SetWithoutPathExpansion( |
| 958 host, Value::CreateDoubleValue(level)); |
| 959 } |
| 960 } |
| 961 |
| 960 #if defined(ENABLE_SESSION_SERVICE) | 962 #if defined(ENABLE_SESSION_SERVICE) |
| 961 void ProfileImpl::StopCreateSessionServiceTimer() { | 963 void ProfileImpl::StopCreateSessionServiceTimer() { |
| 962 create_session_service_timer_.Stop(); | 964 create_session_service_timer_.Stop(); |
| 963 } | 965 } |
| 964 | 966 |
| 965 void ProfileImpl::EnsureSessionServiceCreated() { | 967 void ProfileImpl::EnsureSessionServiceCreated() { |
| 966 SessionServiceFactory::GetForProfile(this); | 968 SessionServiceFactory::GetForProfile(this); |
| 967 } | 969 } |
| 968 #endif | 970 #endif |
| 969 | 971 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 FilePath* cache_path, | 1149 FilePath* cache_path, |
| 1148 int* max_size) { | 1150 int* max_size) { |
| 1149 DCHECK(cache_path); | 1151 DCHECK(cache_path); |
| 1150 DCHECK(max_size); | 1152 DCHECK(max_size); |
| 1151 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1153 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
| 1152 if (!path.empty()) | 1154 if (!path.empty()) |
| 1153 *cache_path = path; | 1155 *cache_path = path; |
| 1154 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1156 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1155 prefs_->GetInteger(prefs::kDiskCacheSize); | 1157 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1156 } | 1158 } |
| OLD | NEW |