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

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

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: callbacks Created 7 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
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/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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 const std::string& host(*i); 561 const std::string& host(*i);
562 double zoom_level = 0; 562 double zoom_level = 0;
563 563
564 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( 564 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion(
565 host, &zoom_level); 565 host, &zoom_level);
566 DCHECK(success); 566 DCHECK(success);
567 host_zoom_map->SetZoomLevel(host, zoom_level); 567 host_zoom_map->SetZoomLevel(host, zoom_level);
568 } 568 }
569 } 569 }
570 570
571 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 571 host_zoom_map->AddZoomLevelChangedCallback(
572 content::Source<HostZoomMap>(host_zoom_map)); 572 base::Bind(&ProfileImpl::OnZoomLevelChanged,
573 base::Unretained(this)));
573 } 574 }
574 575
575 FilePath ProfileImpl::last_selected_directory() { 576 FilePath ProfileImpl::last_selected_directory() {
576 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); 577 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
577 } 578 }
578 579
579 void ProfileImpl::set_last_selected_directory(const FilePath& path) { 580 void ProfileImpl::set_last_selected_directory(const FilePath& path) {
580 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); 581 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
581 } 582 }
582 583
583 ProfileImpl::~ProfileImpl() { 584 ProfileImpl::~ProfileImpl() {
584 MaybeSendDestroyedNotification(); 585 MaybeSendDestroyedNotification();
585 586
587 HostZoomMap::GetForBrowserContext(this)->RemoveZoomLevelChangedCallback(
588 base::Bind(&ProfileImpl::OnZoomLevelChanged,
589 base::Unretained(this)));
590
586 bool prefs_loaded = prefs_->GetInitializationStatus() != 591 bool prefs_loaded = prefs_->GetInitializationStatus() !=
587 PrefService::INITIALIZATION_STATUS_WAITING; 592 PrefService::INITIALIZATION_STATUS_WAITING;
588 593
589 #if defined(ENABLE_SESSION_SERVICE) 594 #if defined(ENABLE_SESSION_SERVICE)
590 StopCreateSessionServiceTimer(); 595 StopCreateSessionServiceTimer();
591 #endif 596 #endif
592 597
593 // Remove pref observers 598 // Remove pref observers
594 pref_change_registrar_.RemoveAll(); 599 pref_change_registrar_.RemoveAll();
595 600
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 top_sites_ = new history::TopSites(this); 912 top_sites_ = new history::TopSites(this);
908 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); 913 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename));
909 } 914 }
910 return top_sites_; 915 return top_sites_;
911 } 916 }
912 917
913 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 918 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
914 return top_sites_; 919 return top_sites_;
915 } 920 }
916 921
922 void ProfileImpl::OnZoomLevelChanged(const std::string& host) {
923 if (host.empty())
924 return;
925 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
926 double level = host_zoom_map->GetZoomLevel(host);
927 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
928 DictionaryValue* host_zoom_dictionary = update.Get();
929 if (level == host_zoom_map->GetDefaultZoomLevel()) {
930 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
931 } else {
932 host_zoom_dictionary->SetWithoutPathExpansion(
933 host, Value::CreateDoubleValue(level));
934 }
935 }
936
917 void ProfileImpl::Observe(int type, 937 void ProfileImpl::Observe(int type,
918 const content::NotificationSource& source, 938 const content::NotificationSource& source,
919 const content::NotificationDetails& details) { 939 const content::NotificationDetails& details) {
920 switch (type) { 940 switch (type) {
921 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: 941 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED:
922 // Causes lazy-load if sync is enabled. 942 // Causes lazy-load if sync is enabled.
923 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); 943 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this);
924 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, 944 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED,
925 content::Source<Profile>(this)); 945 content::Source<Profile>(this));
926 break; 946 break;
927 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: {
928 const std::string& host =
929 *(content::Details<const std::string>(details).ptr());
930 if (!host.empty()) {
931 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
932 double level = host_zoom_map->GetZoomLevel(host);
933 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
934 DictionaryValue* host_zoom_dictionary = update.Get();
935 if (level == host_zoom_map->GetDefaultZoomLevel()) {
936 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
937 } else {
938 host_zoom_dictionary->SetWithoutPathExpansion(
939 host, Value::CreateDoubleValue(level));
940 }
941 }
942 break;
943 }
944 default: 947 default:
945 NOTREACHED(); 948 NOTREACHED();
946 } 949 }
947 } 950 }
948 951
949 void ProfileImpl::OnDefaultZoomLevelChanged() { 952 void ProfileImpl::OnDefaultZoomLevelChanged() {
950 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( 953 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel(
951 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); 954 pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel));
952 } 955 }
953 956
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 if (!path.empty()) 1149 if (!path.empty())
1147 *cache_path = path; 1150 *cache_path = path;
1148 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1151 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1149 prefs_->GetInteger(prefs::kDiskCacheSize); 1152 prefs_->GetInteger(prefs::kDiskCacheSize);
1150 } 1153 }
1151 1154
1152 base::Callback<ChromeURLDataManagerBackend*(void)> 1155 base::Callback<ChromeURLDataManagerBackend*(void)>
1153 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { 1156 ProfileImpl::GetChromeURLDataManagerBackendGetter() const {
1154 return io_data_.GetChromeURLDataManagerBackendGetter(); 1157 return io_data_.GetChromeURLDataManagerBackendGetter();
1155 } 1158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698