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

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

Powered by Google App Engine
This is Rietveld 408576698