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

Side by Side Diff: chrome/browser/host_zoom_map.cc

Issue 3304015: Use PrefChangeRegistrar everywhere (Closed)
Patch Set: final version for commit Created 10 years, 2 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
« no previous file with comments | « chrome/browser/host_zoom_map.h ('k') | chrome/browser/host_zoom_map_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/host_zoom_map.h" 5 #include "chrome/browser/host_zoom_map.h"
6 6
7 #include "base/string_piece.h" 7 #include "base/string_piece.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/prefs/scoped_pref_update.h" 11 #include "chrome/browser/prefs/scoped_pref_update.h"
12 #include "chrome/browser/profile.h" 12 #include "chrome/browser/profile.h"
13 #include "chrome/common/notification_details.h" 13 #include "chrome/common/notification_details.h"
14 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
15 #include "chrome/common/notification_source.h" 15 #include "chrome/common/notification_source.h"
16 #include "chrome/common/notification_type.h" 16 #include "chrome/common/notification_type.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "net/base/net_util.h" 19 #include "net/base/net_util.h"
20 20
21 HostZoomMap::HostZoomMap(Profile* profile) 21 HostZoomMap::HostZoomMap(Profile* profile)
22 : profile_(profile), 22 : profile_(profile),
23 updating_preferences_(false) { 23 updating_preferences_(false) {
24 Load(); 24 Load();
25 registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 25 registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
26 Source<Profile>(profile)); 26 Source<Profile>(profile));
27 // Don't observe pref changes (e.g. from sync) in Incognito; once we create 27 // Don't observe pref changes (e.g. from sync) in Incognito; once we create
28 // the incognito window it should have no further connection to the main 28 // the incognito window it should have no further connection to the main
29 // profile/prefs. 29 // profile/prefs.
30 if (!profile_->IsOffTheRecord()) 30 if (!profile_->IsOffTheRecord()) {
31 profile_->GetPrefs()->AddPrefObserver(prefs::kPerHostZoomLevels, this); 31 pref_change_registrar_.Init(profile_->GetPrefs());
32 pref_change_registrar_.Add(prefs::kPerHostZoomLevels, this);
33 }
32 } 34 }
33 35
34 void HostZoomMap::Load() { 36 void HostZoomMap::Load() {
35 if (!profile_) 37 if (!profile_)
36 return; 38 return;
37 39
38 AutoLock auto_lock(lock_); 40 AutoLock auto_lock(lock_);
39 host_zoom_levels_.clear(); 41 host_zoom_levels_.clear();
40 const DictionaryValue* host_zoom_dictionary = 42 const DictionaryValue* host_zoom_dictionary =
41 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels); 43 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 123 }
122 124
123 void HostZoomMap::Shutdown() { 125 void HostZoomMap::Shutdown() {
124 if (!profile_) 126 if (!profile_)
125 return; 127 return;
126 128
127 registrar_.Remove(this, 129 registrar_.Remove(this,
128 NotificationType::PROFILE_DESTROYED, 130 NotificationType::PROFILE_DESTROYED,
129 Source<Profile>(profile_)); 131 Source<Profile>(profile_));
130 if (!profile_->IsOffTheRecord()) 132 if (!profile_->IsOffTheRecord())
131 profile_->GetPrefs()->RemovePrefObserver(prefs::kPerHostZoomLevels, this); 133 pref_change_registrar_.RemoveAll();
132 profile_ = NULL; 134 profile_ = NULL;
133 } 135 }
134 136
135 void HostZoomMap::Observe( 137 void HostZoomMap::Observe(
136 NotificationType type, 138 NotificationType type,
137 const NotificationSource& source, 139 const NotificationSource& source,
138 const NotificationDetails& details) { 140 const NotificationDetails& details) {
139 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 141 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
140 142
141 // If the profile is going away, we need to stop using it. 143 // If the profile is going away, we need to stop using it.
(...skipping 13 matching lines...) Expand all
155 return; 157 return;
156 } 158 }
157 } 159 }
158 160
159 NOTREACHED() << "Unexpected preference observed."; 161 NOTREACHED() << "Unexpected preference observed.";
160 } 162 }
161 163
162 HostZoomMap::~HostZoomMap() { 164 HostZoomMap::~HostZoomMap() {
163 Shutdown(); 165 Shutdown();
164 } 166 }
OLDNEW
« no previous file with comments | « chrome/browser/host_zoom_map.h ('k') | chrome/browser/host_zoom_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698