| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #include "chrome/browser/profiles/profile_manager.h" | 65 #include "chrome/browser/profiles/profile_manager.h" |
| 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/ssl/chrome_ssl_host_state_delegate.h" | 72 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | 73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" |
| 74 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 74 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 75 #include "chrome/browser/ui/zoom/zoom_level_prefs_store_impl.h" |
| 75 #include "chrome/common/chrome_constants.h" | 76 #include "chrome/common/chrome_constants.h" |
| 76 #include "chrome/common/chrome_paths_internal.h" | 77 #include "chrome/common/chrome_paths_internal.h" |
| 77 #include "chrome/common/chrome_switches.h" | 78 #include "chrome/common/chrome_switches.h" |
| 78 #include "chrome/common/chrome_version_info.h" | 79 #include "chrome/common/chrome_version_info.h" |
| 79 #include "chrome/common/pref_names.h" | 80 #include "chrome/common/pref_names.h" |
| 80 #include "chrome/common/url_constants.h" | 81 #include "chrome/common/url_constants.h" |
| 81 #include "components/bookmarks/browser/bookmark_model.h" | 82 #include "components/bookmarks/browser/bookmark_model.h" |
| 82 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" | 83 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" |
| 83 #include "components/dom_distiller/core/url_constants.h" | 84 #include "components/dom_distiller/core/url_constants.h" |
| 84 #include "components/domain_reliability/monitor.h" | 85 #include "components/domain_reliability/monitor.h" |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 StartupBrowserCreator::GetSessionStartupPref( | 621 StartupBrowserCreator::GetSessionStartupPref( |
| 621 *CommandLine::ForCurrentProcess(), this).type; | 622 *CommandLine::ForCurrentProcess(), this).type; |
| 622 #endif | 623 #endif |
| 623 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = | 624 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = |
| 624 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; | 625 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; |
| 625 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || | 626 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || |
| 626 startup_pref_type == SessionStartupPref::LAST) { | 627 startup_pref_type == SessionStartupPref::LAST) { |
| 627 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; | 628 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; |
| 628 } | 629 } |
| 629 | 630 |
| 630 InitHostZoomMap(); | |
| 631 | |
| 632 base::Callback<void(bool)> data_reduction_proxy_unavailable; | 631 base::Callback<void(bool)> data_reduction_proxy_unavailable; |
| 633 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> | 632 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> |
| 634 data_reduction_proxy_params; | 633 data_reduction_proxy_params; |
| 635 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; | 634 scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator; |
| 635 |
| 636 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 636 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 637 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = | 637 DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = |
| 638 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); | 638 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); |
| 639 data_reduction_proxy_params = | 639 data_reduction_proxy_params = |
| 640 data_reduction_proxy_chrome_settings->params()->Clone(); | 640 data_reduction_proxy_chrome_settings->params()->Clone(); |
| 641 data_reduction_proxy_unavailable = | 641 data_reduction_proxy_unavailable = |
| 642 base::Bind( | 642 base::Bind( |
| 643 &data_reduction_proxy::DataReductionProxySettings::SetUnreachable, | 643 &data_reduction_proxy::DataReductionProxySettings::SetUnreachable, |
| 644 base::Unretained(data_reduction_proxy_chrome_settings)); | 644 base::Unretained(data_reduction_proxy_chrome_settings)); |
| 645 // The configurator is used by DataReductionProxyChromeSettings and | 645 // The configurator is used by DataReductionProxyChromeSettings and |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 #if !defined(OS_CHROMEOS) | 729 #if !defined(OS_CHROMEOS) |
| 730 // Listen for bookmark model load, to bootstrap the sync service. | 730 // Listen for bookmark model load, to bootstrap the sync service. |
| 731 // On CrOS sync service will be initialized after sign in. | 731 // On CrOS sync service will be initialized after sign in. |
| 732 BookmarkModel* model = BookmarkModelFactory::GetForProfile(this); | 732 BookmarkModel* model = BookmarkModelFactory::GetForProfile(this); |
| 733 model->AddObserver(new BookmarkModelLoadedObserver(this)); | 733 model->AddObserver(new BookmarkModelLoadedObserver(this)); |
| 734 #endif | 734 #endif |
| 735 | 735 |
| 736 gcm::PushMessagingServiceImpl::InitializeForProfile(this); | 736 gcm::PushMessagingServiceImpl::InitializeForProfile(this); |
| 737 } | 737 } |
| 738 | 738 |
| 739 void ProfileImpl::InitHostZoomMap() { | |
| 740 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | |
| 741 host_zoom_map->SetDefaultZoomLevel( | |
| 742 prefs_->GetDouble(prefs::kDefaultZoomLevel)); | |
| 743 | |
| 744 const base::DictionaryValue* host_zoom_dictionary = | |
| 745 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | |
| 746 // Careful: The returned value could be NULL if the pref has never been set. | |
| 747 if (host_zoom_dictionary != NULL) { | |
| 748 std::vector<std::string> keys_to_remove; | |
| 749 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd(); | |
| 750 i.Advance()) { | |
| 751 const std::string& host(i.key()); | |
| 752 double zoom_level = 0; | |
| 753 | |
| 754 bool success = i.value().GetAsDouble(&zoom_level); | |
| 755 DCHECK(success); | |
| 756 | |
| 757 // Filter out A) the empty host, B) zoom levels equal to the default; and | |
| 758 // remember them, so that we can later erase them from Prefs. | |
| 759 // Values of type A and B could have been stored due to crbug.com/364399. | |
| 760 // Values of type B could further have been stored before the default zoom | |
| 761 // level was set to its current value. In either case, SetZoomLevelForHost | |
| 762 // will ignore type B values, thus, to have consistency with HostZoomMap's | |
| 763 // internal state, these values must also be removed from Prefs. | |
| 764 if (host.empty() || | |
| 765 content::ZoomValuesEqual(zoom_level, | |
| 766 host_zoom_map->GetDefaultZoomLevel())) { | |
| 767 keys_to_remove.push_back(host); | |
| 768 continue; | |
| 769 } | |
| 770 | |
| 771 host_zoom_map->SetZoomLevelForHost(host, zoom_level); | |
| 772 } | |
| 773 | |
| 774 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | |
| 775 base::DictionaryValue* host_zoom_dictionary = update.Get(); | |
| 776 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin(); | |
| 777 it != keys_to_remove.end(); ++it) { | |
| 778 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL); | |
| 779 } | |
| 780 } | |
| 781 | |
| 782 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( | |
| 783 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this))); | |
| 784 } | |
| 785 | |
| 786 base::FilePath ProfileImpl::last_selected_directory() { | 739 base::FilePath ProfileImpl::last_selected_directory() { |
| 787 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 740 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
| 788 } | 741 } |
| 789 | 742 |
| 790 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { | 743 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
| 791 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 744 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 792 } | 745 } |
| 793 | 746 |
| 794 ProfileImpl::~ProfileImpl() { | 747 ProfileImpl::~ProfileImpl() { |
| 795 MaybeSendDestroyedNotification(); | 748 MaybeSendDestroyedNotification(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } | 791 } |
| 839 | 792 |
| 840 std::string ProfileImpl::GetProfileName() { | 793 std::string ProfileImpl::GetProfileName() { |
| 841 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 794 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| 842 } | 795 } |
| 843 | 796 |
| 844 Profile::ProfileType ProfileImpl::GetProfileType() const { | 797 Profile::ProfileType ProfileImpl::GetProfileType() const { |
| 845 return REGULAR_PROFILE; | 798 return REGULAR_PROFILE; |
| 846 } | 799 } |
| 847 | 800 |
| 801 double ProfileImpl::GetDefaultZoomLevel() const { |
| 802 return pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel); |
| 803 } |
| 804 |
| 805 scoped_ptr<content::ZoomLevelPrefsStore> |
| 806 ProfileImpl::CreateZoomLevelPrefsStore() { |
| 807 return scoped_ptr<content::ZoomLevelPrefsStore>( |
| 808 new browser::ZoomLevelPrefsStoreImpl); |
| 809 } |
| 810 |
| 848 base::FilePath ProfileImpl::GetPath() const { | 811 base::FilePath ProfileImpl::GetPath() const { |
| 849 return path_; | 812 return path_; |
| 850 } | 813 } |
| 851 | 814 |
| 852 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { | 815 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { |
| 853 return JsonPrefStore::GetTaskRunnerForFile( | 816 return JsonPrefStore::GetTaskRunnerForFile( |
| 854 GetPath(), BrowserThread::GetBlockingPool()); | 817 GetPath(), BrowserThread::GetBlockingPool()); |
| 855 } | 818 } |
| 856 | 819 |
| 857 bool ProfileImpl::IsOffTheRecord() const { | 820 bool ProfileImpl::IsOffTheRecord() const { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 this, GetPath().Append(chrome::kTopSitesFilename)); | 1109 this, GetPath().Append(chrome::kTopSitesFilename)); |
| 1147 } | 1110 } |
| 1148 return top_sites_.get(); | 1111 return top_sites_.get(); |
| 1149 } | 1112 } |
| 1150 | 1113 |
| 1151 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 1114 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
| 1152 return top_sites_.get(); | 1115 return top_sites_.get(); |
| 1153 } | 1116 } |
| 1154 | 1117 |
| 1155 void ProfileImpl::OnDefaultZoomLevelChanged() { | 1118 void ProfileImpl::OnDefaultZoomLevelChanged() { |
| 1156 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | 1119 BrowserContext::SetDefaultZoomLevel(this, GetDefaultZoomLevel()); |
| 1157 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); | |
| 1158 } | 1120 } |
| 1159 | 1121 |
| 1160 void ProfileImpl::OnZoomLevelChanged( | 1122 void ProfileImpl::OnZoomLevelChanged( |
| 1161 const HostZoomMap::ZoomLevelChange& change) { | 1123 const HostZoomMap::ZoomLevelChange& change) { |
| 1162 | 1124 |
| 1163 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | 1125 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) |
| 1164 return; | 1126 return; |
| 1165 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | |
| 1166 double level = change.zoom_level; | 1127 double level = change.zoom_level; |
| 1167 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 1128 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); |
| 1168 base::DictionaryValue* host_zoom_dictionary = update.Get(); | 1129 base::DictionaryValue* host_zoom_dictionary = update.Get(); |
| 1169 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) | 1130 if (content::ZoomValuesEqual(level, GetDefaultZoomLevel())) |
| 1170 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | 1131 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); |
| 1171 else | 1132 else |
| 1172 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); | 1133 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); |
| 1173 } | 1134 } |
| 1174 | 1135 |
| 1175 #if defined(ENABLE_SESSION_SERVICE) | 1136 #if defined(ENABLE_SESSION_SERVICE) |
| 1176 void ProfileImpl::StopCreateSessionServiceTimer() { | 1137 void ProfileImpl::StopCreateSessionServiceTimer() { |
| 1177 create_session_service_timer_.Stop(); | 1138 create_session_service_timer_.Stop(); |
| 1178 } | 1139 } |
| 1179 | 1140 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 ProfileImpl::CreateDomainReliabilityMonitor() { | 1374 ProfileImpl::CreateDomainReliabilityMonitor() { |
| 1414 domain_reliability::DomainReliabilityService* service = | 1375 domain_reliability::DomainReliabilityService* service = |
| 1415 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1376 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
| 1416 GetForBrowserContext(this); | 1377 GetForBrowserContext(this); |
| 1417 if (!service) | 1378 if (!service) |
| 1418 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1379 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
| 1419 | 1380 |
| 1420 return service->CreateMonitor( | 1381 return service->CreateMonitor( |
| 1421 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1382 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 1422 } | 1383 } |
| OLD | NEW |