| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #include "chrome/browser/profiles/profile_metrics.h" | 66 #include "chrome/browser/profiles/profile_metrics.h" |
| 67 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 67 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 68 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 68 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 69 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 69 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 70 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" | 70 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" |
| 71 #include "chrome/browser/sessions/session_service_factory.h" | 71 #include "chrome/browser/sessions/session_service_factory.h" |
| 72 #include "chrome/browser/signin/signin_ui_util.h" | 72 #include "chrome/browser/signin/signin_ui_util.h" |
| 73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 74 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | 74 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" |
| 75 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 75 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 76 #include "chrome/browser/ui/zoom/zoom_level_prefs_store_impl.h" |
| 76 #include "chrome/common/chrome_constants.h" | 77 #include "chrome/common/chrome_constants.h" |
| 77 #include "chrome/common/chrome_paths_internal.h" | 78 #include "chrome/common/chrome_paths_internal.h" |
| 78 #include "chrome/common/chrome_switches.h" | 79 #include "chrome/common/chrome_switches.h" |
| 79 #include "chrome/common/chrome_version_info.h" | 80 #include "chrome/common/chrome_version_info.h" |
| 80 #include "chrome/common/pref_names.h" | 81 #include "chrome/common/pref_names.h" |
| 81 #include "chrome/common/url_constants.h" | 82 #include "chrome/common/url_constants.h" |
| 82 #include "components/bookmarks/browser/bookmark_model.h" | 83 #include "components/bookmarks/browser/bookmark_model.h" |
| 83 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" | 84 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" |
| 84 #include "components/dom_distiller/core/url_constants.h" | 85 #include "components/dom_distiller/core/url_constants.h" |
| 85 #include "components/domain_reliability/monitor.h" | 86 #include "components/domain_reliability/monitor.h" |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 PrefService* prefs = GetPrefs(); | 545 PrefService* prefs = GetPrefs(); |
| 545 pref_change_registrar_.Init(prefs); | 546 pref_change_registrar_.Init(prefs); |
| 546 pref_change_registrar_.Add( | 547 pref_change_registrar_.Add( |
| 547 prefs::kGoogleServicesUsername, | 548 prefs::kGoogleServicesUsername, |
| 548 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, | 549 base::Bind(&ProfileImpl::UpdateProfileUserNameCache, |
| 549 base::Unretained(this))); | 550 base::Unretained(this))); |
| 550 pref_change_registrar_.Add( | 551 pref_change_registrar_.Add( |
| 551 prefs::kSupervisedUserId, | 552 prefs::kSupervisedUserId, |
| 552 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, | 553 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, |
| 553 base::Unretained(this))); | 554 base::Unretained(this))); |
| 554 pref_change_registrar_.Add( | |
| 555 prefs::kDefaultZoomLevel, | |
| 556 base::Bind(&ProfileImpl::OnDefaultZoomLevelChanged, | |
| 557 base::Unretained(this))); | |
| 558 | |
| 559 // Changes in the profile avatar. | 555 // Changes in the profile avatar. |
| 560 pref_change_registrar_.Add( | 556 pref_change_registrar_.Add( |
| 561 prefs::kProfileAvatarIndex, | 557 prefs::kProfileAvatarIndex, |
| 562 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 558 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
| 563 base::Unretained(this))); | 559 base::Unretained(this))); |
| 564 pref_change_registrar_.Add( | 560 pref_change_registrar_.Add( |
| 565 prefs::kProfileUsingDefaultAvatar, | 561 prefs::kProfileUsingDefaultAvatar, |
| 566 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 562 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
| 567 base::Unretained(this))); | 563 base::Unretained(this))); |
| 568 pref_change_registrar_.Add( | 564 pref_change_registrar_.Add( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 StartupBrowserCreator::GetSessionStartupPref( | 648 StartupBrowserCreator::GetSessionStartupPref( |
| 653 *CommandLine::ForCurrentProcess(), this).type; | 649 *CommandLine::ForCurrentProcess(), this).type; |
| 654 #endif | 650 #endif |
| 655 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = | 651 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = |
| 656 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; | 652 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; |
| 657 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || | 653 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || |
| 658 startup_pref_type == SessionStartupPref::LAST) { | 654 startup_pref_type == SessionStartupPref::LAST) { |
| 659 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; | 655 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; |
| 660 } | 656 } |
| 661 | 657 |
| 662 InitHostZoomMap(); | |
| 663 | |
| 664 base::Callback<void(bool)> data_reduction_proxy_unavailable; | 658 base::Callback<void(bool)> data_reduction_proxy_unavailable; |
| 665 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> | 659 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> |
| 666 data_reduction_proxy_params; | 660 data_reduction_proxy_params; |
| 667 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; | 661 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; |
| 662 |
| 668 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 663 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 669 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = | 664 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = |
| 670 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); | 665 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); |
| 671 data_reduction_proxy_params = | 666 data_reduction_proxy_params = |
| 672 data_reduction_proxy_chrome_settings->params()->Clone(); | 667 data_reduction_proxy_chrome_settings->params()->Clone(); |
| 673 data_reduction_proxy_unavailable = | 668 data_reduction_proxy_unavailable = |
| 674 base::Bind( | 669 base::Bind( |
| 675 &data_reduction_proxy::DataReductionProxySettings::SetUnreachable, | 670 &data_reduction_proxy::DataReductionProxySettings::SetUnreachable, |
| 676 base::Unretained(data_reduction_proxy_chrome_settings)); | 671 base::Unretained(data_reduction_proxy_chrome_settings)); |
| 677 // The configurator is used by DataReductionProxyChromeSettings and | 672 // The configurator is used by DataReductionProxyChromeSettings and |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 model->AddObserver(new BookmarkModelLoadedObserver(this)); | 760 model->AddObserver(new BookmarkModelLoadedObserver(this)); |
| 766 #endif | 761 #endif |
| 767 | 762 |
| 768 gcm::PushMessagingServiceImpl::InitializeForProfile(this); | 763 gcm::PushMessagingServiceImpl::InitializeForProfile(this); |
| 769 | 764 |
| 770 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) | 765 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) |
| 771 signin_ui_util::InitializePrefsForProfile(this); | 766 signin_ui_util::InitializePrefsForProfile(this); |
| 772 #endif | 767 #endif |
| 773 } | 768 } |
| 774 | 769 |
| 775 void ProfileImpl::InitHostZoomMap() { | |
| 776 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | |
| 777 host_zoom_map->SetDefaultZoomLevel( | |
| 778 prefs_->GetDouble(prefs::kDefaultZoomLevel)); | |
| 779 | |
| 780 const base::DictionaryValue* host_zoom_dictionary = | |
| 781 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | |
| 782 // Careful: The returned value could be NULL if the pref has never been set. | |
| 783 if (host_zoom_dictionary != NULL) { | |
| 784 std::vector<std::string> keys_to_remove; | |
| 785 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | |
| 786 i.Advance()) { | |
| 787 const std::string& host(i.key()); | |
| 788 double zoom_level = 0; | |
| 789 | |
| 790 bool success = i.value().GetAsDouble(&zoom_level); | |
| 791 DCHECK(success); | |
| 792 | |
| 793 // Filter out A) the empty host, B) zoom levels equal to the default; and | |
| 794 // remember them, so that we can later erase them from Prefs. | |
| 795 // Values of type A and B could have been stored due to crbug.com/364399. | |
| 796 // Values of type B could further have been stored before the default zoom | |
| 797 // level was set to its current value. In either case, SetZoomLevelForHost | |
| 798 // will ignore type B values, thus, to have consistency with HostZoomMap's | |
| 799 // internal state, these values must also be removed from Prefs. | |
| 800 if (host.empty() || | |
| 801 content::ZoomValuesEqual(zoom_level, | |
| 802 host_zoom_map->GetDefaultZoomLevel())) { | |
| 803 keys_to_remove.push_back(host); | |
| 804 continue; | |
| 805 } | |
| 806 | |
| 807 host_zoom_map->SetZoomLevelForHost(host, zoom_level); | |
| 808 } | |
| 809 | |
| 810 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
| 811 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
| 812 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | |
| 813 it != keys_to_remove.end(); ++it) { | |
| 814 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | |
| 815 } | |
| 816 } | |
| 817 | |
| 818 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | |
| 819 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | |
| 820 } | |
| 821 | |
| 822 base::FilePath ProfileImpl::last_selected_directory() { | 770 base::FilePath ProfileImpl::last_selected_directory() { |
| 823 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 771 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
| 824 } | 772 } |
| 825 | 773 |
| 826 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 774 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
| 827 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 775 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 828 } | 776 } |
| 829 | 777 |
| 830 ProfileImpl::~ProfileImpl() { | 778 ProfileImpl::~ProfileImpl() { |
| 831 MaybeSendDestroyedNotification(); | 779 MaybeSendDestroyedNotification(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 } | 822 } |
| 875 | 823 |
| 876 std::string ProfileImpl::GetProfileName() { | 824 std::string ProfileImpl::GetProfileName() { |
| 877 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 825 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| 878 } | 826 } |
| 879 | 827 |
| 880 Profile::ProfileType ProfileImpl::GetProfileType() const { | 828 Profile::ProfileType ProfileImpl::GetProfileType() const { |
| 881 return REGULAR_PROFILE; | 829 return REGULAR_PROFILE; |
| 882 } | 830 } |
| 883 | 831 |
| 832 scoped_ptr<content::ZoomLevelPrefsStore> |
| 833 ProfileImpl::CreateZoomLevelPrefsStore() { |
| 834 return scoped_ptr<content::ZoomLevelPrefsStore>( |
| 835 new chrome::ZoomLevelPrefsStoreImpl); |
| 836 } |
| 837 |
| 884 base::FilePath ProfileImpl::GetPath() const { | 838 base::FilePath ProfileImpl::GetPath() const { |
| 885 return path_; | 839 return path_; |
| 886 } | 840 } |
| 887 | 841 |
| 888 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { | 842 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { |
| 889 return JsonPrefStore::GetTaskRunnerForFile( | 843 return JsonPrefStore::GetTaskRunnerForFile( |
| 890 GetPath(), BrowserThread::GetBlockingPool()); | 844 GetPath(), BrowserThread::GetBlockingPool()); |
| 891 } | 845 } |
| 892 | 846 |
| 893 bool ProfileImpl::IsOffTheRecord() const { | 847 bool ProfileImpl::IsOffTheRecord() const { |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 top_sites_ = history::TopSites::Create( | 1135 top_sites_ = history::TopSites::Create( |
| 1182 this, GetPath().Append(chrome::kTopSitesFilename)); | 1136 this, GetPath().Append(chrome::kTopSitesFilename)); |
| 1183 } | 1137 } |
| 1184 return top_sites_.get(); | 1138 return top_sites_.get(); |
| 1185 } | 1139 } |
| 1186 | 1140 |
| 1187 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1141 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
| 1188 return top_sites_.get(); | 1142 return top_sites_.get(); |
| 1189 } | 1143 } |
| 1190 | 1144 |
| 1191 void ProfileImpl::OnDefaultZoomLevelChanged() { | |
| 1192 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | |
| 1193 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); | |
| 1194 } | |
| 1195 | |
| 1196 void ProfileImpl::OnZoomLevelChanged( | |
| 1197 const HostZoomMap::ZoomLevelChange& change) { | |
| 1198 | |
| 1199 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | |
| 1200 return; | |
| 1201 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | |
| 1202 double level = change.zoom_level; | |
| 1203 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
| 1204 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
| 1205 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) | |
| 1206 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | |
| 1207 else | |
| 1208 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); | |
| 1209 } | |
| 1210 | |
| 1211 #if defined(ENABLE_SESSION_SERVICE) | 1145 #if defined(ENABLE_SESSION_SERVICE) |
| 1212 void ProfileImpl::StopCreateSessionServiceTimer() { | 1146 void ProfileImpl::StopCreateSessionServiceTimer() { |
| 1213 create_session_service_timer_.Stop(); | 1147 create_session_service_timer_.Stop(); |
| 1214 } | 1148 } |
| 1215 | 1149 |
| 1216 void ProfileImpl::EnsureSessionServiceCreated() { | 1150 void ProfileImpl::EnsureSessionServiceCreated() { |
| 1217 SessionServiceFactory::GetForProfile(this); | 1151 SessionServiceFactory::GetForProfile(this); |
| 1218 } | 1152 } |
| 1219 #endif | 1153 #endif |
| 1220 | 1154 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 ProfileImpl::CreateDomainReliabilityMonitor() { | 1391 ProfileImpl::CreateDomainReliabilityMonitor() { |
| 1458 domain_reliability::DomainReliabilityService* service = | 1392 domain_reliability::DomainReliabilityService* service = |
| 1459 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1393 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
| 1460 GetForBrowserContext(this); | 1394 GetForBrowserContext(this); |
| 1461 if (!service) | 1395 if (!service) |
| 1462 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1396 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
| 1463 | 1397 |
| 1464 return service->CreateMonitor( | 1398 return service->CreateMonitor( |
| 1465 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1399 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 1466 } | 1400 } |
| OLD | NEW |