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

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

Issue 393133002: Migrate HostZoomMap to live in StoragePartition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to r288093. Created 6 years, 4 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
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 <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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #include "chrome/browser/profiles/profile_manager.h" 63 #include "chrome/browser/profiles/profile_manager.h"
64 #include "chrome/browser/profiles/profile_metrics.h" 64 #include "chrome/browser/profiles/profile_metrics.h"
65 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 65 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
66 #include "chrome/browser/services/gcm/gcm_profile_service.h" 66 #include "chrome/browser/services/gcm/gcm_profile_service.h"
67 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 67 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
68 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" 68 #include "chrome/browser/services/gcm/push_messaging_service_impl.h"
69 #include "chrome/browser/sessions/session_service_factory.h" 69 #include "chrome/browser/sessions/session_service_factory.h"
70 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" 70 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
71 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" 71 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
72 #include "chrome/browser/ui/startup/startup_browser_creator.h" 72 #include "chrome/browser/ui/startup/startup_browser_creator.h"
73 #include "chrome/browser/ui/zoom/zoom_level_prefs_delegate_impl.h"
73 #include "chrome/common/chrome_constants.h" 74 #include "chrome/common/chrome_constants.h"
74 #include "chrome/common/chrome_paths_internal.h" 75 #include "chrome/common/chrome_paths_internal.h"
75 #include "chrome/common/chrome_switches.h" 76 #include "chrome/common/chrome_switches.h"
76 #include "chrome/common/chrome_version_info.h" 77 #include "chrome/common/chrome_version_info.h"
77 #include "chrome/common/pref_names.h" 78 #include "chrome/common/pref_names.h"
78 #include "chrome/common/url_constants.h" 79 #include "chrome/common/url_constants.h"
79 #include "components/bookmarks/browser/bookmark_model.h" 80 #include "components/bookmarks/browser/bookmark_model.h"
80 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" 81 #include "components/dom_distiller/content/dom_distiller_viewer_source.h"
81 #include "components/dom_distiller/core/url_constants.h" 82 #include "components/dom_distiller/core/url_constants.h"
82 #include "components/domain_reliability/monitor.h" 83 #include "components/domain_reliability/monitor.h"
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 StartupBrowserCreator::GetSessionStartupPref( 613 StartupBrowserCreator::GetSessionStartupPref(
613 *CommandLine::ForCurrentProcess(), this).type; 614 *CommandLine::ForCurrentProcess(), this).type;
614 #endif 615 #endif
615 content::CookieStoreConfig::SessionCookieMode session_cookie_mode = 616 content::CookieStoreConfig::SessionCookieMode session_cookie_mode =
616 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES; 617 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES;
617 if (GetLastSessionExitType() == Profile::EXIT_CRASHED || 618 if (GetLastSessionExitType() == Profile::EXIT_CRASHED ||
618 startup_pref_type == SessionStartupPref::LAST) { 619 startup_pref_type == SessionStartupPref::LAST) {
619 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; 620 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES;
620 } 621 }
621 622
622 InitHostZoomMap();
623
624 // Make sure we initialize the ProfileIOData after everything else has been 623 // Make sure we initialize the ProfileIOData after everything else has been
625 // initialized that we might be reading from the IO thread. 624 // initialized that we might be reading from the IO thread.
626 625
627 io_data_.Init(cookie_path, channel_id_path, cache_path, 626 io_data_.Init(cookie_path, channel_id_path, cache_path,
628 cache_max_size, media_cache_path, media_cache_max_size, 627 cache_max_size, media_cache_path, media_cache_max_size,
629 extensions_cookie_path, GetPath(), infinite_cache_path, 628 extensions_cookie_path, GetPath(), infinite_cache_path,
630 predictor_, session_cookie_mode, GetSpecialStoragePolicy(), 629 predictor_, session_cookie_mode, GetSpecialStoragePolicy(),
631 CreateDomainReliabilityMonitor()); 630 CreateDomainReliabilityMonitor());
632 631
633 #if defined(ENABLE_PLUGINS) 632 #if defined(ENABLE_PLUGINS)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 #if !defined(OS_CHROMEOS) 682 #if !defined(OS_CHROMEOS)
684 // Listen for bookmark model load, to bootstrap the sync service. 683 // Listen for bookmark model load, to bootstrap the sync service.
685 // On CrOS sync service will be initialized after sign in. 684 // On CrOS sync service will be initialized after sign in.
686 BookmarkModel* model = BookmarkModelFactory::GetForProfile(this); 685 BookmarkModel* model = BookmarkModelFactory::GetForProfile(this);
687 model->AddObserver(new BookmarkModelLoadedObserver(this)); 686 model->AddObserver(new BookmarkModelLoadedObserver(this));
688 #endif 687 #endif
689 688
690 gcm::PushMessagingServiceImpl::InitializeForProfile(this); 689 gcm::PushMessagingServiceImpl::InitializeForProfile(this);
691 } 690 }
692 691
693 void ProfileImpl::InitHostZoomMap() {
694 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
695 host_zoom_map->SetDefaultZoomLevel(
696 prefs_->GetDouble(prefs::kDefaultZoomLevel));
697
698 const base::DictionaryValue* host_zoom_dictionary =
699 prefs_->GetDictionary(prefs::kPerHostZoomLevels);
700 // Careful: The returned value could be NULL if the pref has never been set.
701 if (host_zoom_dictionary != NULL) {
702 std::vector<std::string> keys_to_remove;
703 for (base::DictionaryValue::Iterator i(*host_zoom_dictionary); !i.IsAtEnd();
704 i.Advance()) {
705 const std::string& host(i.key());
706 double zoom_level = 0;
707
708 bool success = i.value().GetAsDouble(&zoom_level);
709 DCHECK(success);
710
711 // Filter out A) the empty host, B) zoom levels equal to the default; and
712 // remember them, so that we can later erase them from Prefs.
713 // Values of type A and B could have been stored due to crbug.com/364399.
714 // Values of type B could further have been stored before the default zoom
715 // level was set to its current value. In either case, SetZoomLevelForHost
716 // will ignore type B values, thus, to have consistency with HostZoomMap's
717 // internal state, these values must also be removed from Prefs.
718 if (host.empty() ||
719 content::ZoomValuesEqual(zoom_level,
720 host_zoom_map->GetDefaultZoomLevel())) {
721 keys_to_remove.push_back(host);
722 continue;
723 }
724
725 host_zoom_map->SetZoomLevelForHost(host, zoom_level);
726 }
727
728 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
729 base::DictionaryValue* host_zoom_dictionary = update.Get();
730 for (std::vector<std::string>::const_iterator it = keys_to_remove.begin();
731 it != keys_to_remove.end(); ++it) {
732 host_zoom_dictionary->RemoveWithoutPathExpansion(*it, NULL);
733 }
734 }
735
736 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback(
737 base::Bind(&ProfileImpl::OnZoomLevelChanged, base::Unretained(this)));
738 }
739
740 base::FilePath ProfileImpl::last_selected_directory() { 692 base::FilePath ProfileImpl::last_selected_directory() {
741 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); 693 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
742 } 694 }
743 695
744 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { 696 void ProfileImpl::set_last_selected_directory(const base::FilePath& path) {
745 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); 697 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
746 } 698 }
747 699
748 ProfileImpl::~ProfileImpl() { 700 ProfileImpl::~ProfileImpl() {
749 MaybeSendDestroyedNotification(); 701 MaybeSendDestroyedNotification();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 } 744 }
793 745
794 std::string ProfileImpl::GetProfileName() { 746 std::string ProfileImpl::GetProfileName() {
795 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); 747 return GetPrefs()->GetString(prefs::kGoogleServicesUsername);
796 } 748 }
797 749
798 Profile::ProfileType ProfileImpl::GetProfileType() const { 750 Profile::ProfileType ProfileImpl::GetProfileType() const {
799 return REGULAR_PROFILE; 751 return REGULAR_PROFILE;
800 } 752 }
801 753
754 double ProfileImpl::GetDefaultZoomLevel() const {
755 return pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel);
756 }
757
758 content::ZoomLevelPrefsDelegate* ProfileImpl::CreateZoomLevelPrefsDelegate() {
759 return new browser::ZoomLevelPrefsDelegateImpl;
760 }
761
802 base::FilePath ProfileImpl::GetPath() const { 762 base::FilePath ProfileImpl::GetPath() const {
803 return path_; 763 return path_;
804 } 764 }
805 765
806 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { 766 scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() {
807 return JsonPrefStore::GetTaskRunnerForFile( 767 return JsonPrefStore::GetTaskRunnerForFile(
808 GetPath(), BrowserThread::GetBlockingPool()); 768 GetPath(), BrowserThread::GetBlockingPool());
809 } 769 }
810 770
811 bool ProfileImpl::IsOffTheRecord() const { 771 bool ProfileImpl::IsOffTheRecord() const {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 this, GetPath().Append(chrome::kTopSitesFilename)); 1060 this, GetPath().Append(chrome::kTopSitesFilename));
1101 } 1061 }
1102 return top_sites_.get(); 1062 return top_sites_.get();
1103 } 1063 }
1104 1064
1105 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 1065 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
1106 return top_sites_.get(); 1066 return top_sites_.get();
1107 } 1067 }
1108 1068
1109 void ProfileImpl::OnDefaultZoomLevelChanged() { 1069 void ProfileImpl::OnDefaultZoomLevelChanged() {
1110 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( 1070 BrowserContext::SetDefaultZoomLevel(this, GetDefaultZoomLevel());
1111 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel));
1112 } 1071 }
1113 1072
1114 void ProfileImpl::OnZoomLevelChanged( 1073 void ProfileImpl::OnZoomLevelChanged(
1115 const HostZoomMap::ZoomLevelChange& change) { 1074 const HostZoomMap::ZoomLevelChange& change) {
1116 1075
1117 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) 1076 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST)
1118 return; 1077 return;
1119 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
1120 double level = change.zoom_level; 1078 double level = change.zoom_level;
1121 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); 1079 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
1122 base::DictionaryValue* host_zoom_dictionary = update.Get(); 1080 base::DictionaryValue* host_zoom_dictionary = update.Get();
1123 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) 1081 if (content::ZoomValuesEqual(level, GetDefaultZoomLevel()))
1124 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); 1082 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL);
1125 else 1083 else
1126 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); 1084 host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level);
1127 } 1085 }
1128 1086
1129 #if defined(ENABLE_SESSION_SERVICE) 1087 #if defined(ENABLE_SESSION_SERVICE)
1130 void ProfileImpl::StopCreateSessionServiceTimer() { 1088 void ProfileImpl::StopCreateSessionServiceTimer() {
1131 create_session_service_timer_.Stop(); 1089 create_session_service_timer_.Stop();
1132 } 1090 }
1133 1091
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 ProfileImpl::CreateDomainReliabilityMonitor() { 1325 ProfileImpl::CreateDomainReliabilityMonitor() {
1368 domain_reliability::DomainReliabilityService* service = 1326 domain_reliability::DomainReliabilityService* service =
1369 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> 1327 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1370 GetForBrowserContext(this); 1328 GetForBrowserContext(this);
1371 if (!service) 1329 if (!service)
1372 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); 1330 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>();
1373 1331
1374 return service->CreateMonitor( 1332 return service->CreateMonitor(
1375 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 1333 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
1376 } 1334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698