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

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

Issue 2069010: Merge 47568 - Forget zoom levels set/changed in incognito mode when exiting i... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/375/src/
Patch Set: Created 10 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/profile.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/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/chrome_thread.h" 8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/pref_service.h" 9 #include "chrome/browser/pref_service.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
11 #include "chrome/browser/scoped_pref_update.h" 11 #include "chrome/browser/scoped_pref_update.h"
12 #include "chrome/common/notification_details.h" 12 #include "chrome/common/notification_details.h"
13 #include "chrome/common/notification_source.h" 13 #include "chrome/common/notification_source.h"
14 #include "chrome/common/notification_type.h" 14 #include "chrome/common/notification_type.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 16
17 HostZoomMap::HostZoomMap(Profile* profile) 17 HostZoomMap::HostZoomMap(Profile* profile)
18 : profile_(profile), 18 : profile_(profile),
19 updating_preferences_(false) { 19 updating_preferences_(false) {
20 Load(); 20 Load();
21 registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 21 registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
22 Source<Profile>(profile)); 22 Source<Profile>(profile));
23 profile_->GetPrefs()->AddPrefObserver(prefs::kPerHostZoomLevels, this); 23 // Don't observe pref changes (e.g. from sync) in Incognito; once we create
24 // the incognito window it should have no further connection to the main
25 // profile/prefs.
26 if (!profile_->IsOffTheRecord())
27 profile_->GetPrefs()->AddPrefObserver(prefs::kPerHostZoomLevels, this);
24 } 28 }
25 29
26 void HostZoomMap::Load() { 30 void HostZoomMap::Load() {
27 if (!profile_) 31 if (!profile_)
28 return; 32 return;
29 33
30 AutoLock auto_lock(lock_); 34 AutoLock auto_lock(lock_);
31 host_zoom_levels_.clear(); 35 host_zoom_levels_.clear();
32 const DictionaryValue* host_zoom_dictionary = 36 const DictionaryValue* host_zoom_dictionary =
33 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels); 37 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return; 69 return;
66 70
67 { 71 {
68 AutoLock auto_lock(lock_); 72 AutoLock auto_lock(lock_);
69 if (level == 0) 73 if (level == 0)
70 host_zoom_levels_.erase(host); 74 host_zoom_levels_.erase(host);
71 else 75 else
72 host_zoom_levels_[host] = level; 76 host_zoom_levels_[host] = level;
73 } 77 }
74 78
79 // If we're in incognito mode, don't persist changes to the prefs. We'll keep
80 // them in memory only so they will be forgotten on exiting incognito.
81 if (profile_->IsOffTheRecord())
82 return;
83
75 updating_preferences_ = true; 84 updating_preferences_ = true;
76 { 85 {
77 ScopedPrefUpdate update(profile_->GetPrefs(), prefs::kPerHostZoomLevels); 86 ScopedPrefUpdate update(profile_->GetPrefs(), prefs::kPerHostZoomLevels);
78 DictionaryValue* host_zoom_dictionary = 87 DictionaryValue* host_zoom_dictionary =
79 profile_->GetPrefs()->GetMutableDictionary(prefs::kPerHostZoomLevels); 88 profile_->GetPrefs()->GetMutableDictionary(prefs::kPerHostZoomLevels);
80 std::wstring wide_host(UTF8ToWide(host)); 89 std::wstring wide_host(UTF8ToWide(host));
81 if (level == 0) { 90 if (level == 0) {
82 host_zoom_dictionary->RemoveWithoutPathExpansion(wide_host, NULL); 91 host_zoom_dictionary->RemoveWithoutPathExpansion(wide_host, NULL);
83 } else { 92 } else {
84 host_zoom_dictionary->SetWithoutPathExpansion( 93 host_zoom_dictionary->SetWithoutPathExpansion(
(...skipping 19 matching lines...) Expand all
104 updating_preferences_ = false; 113 updating_preferences_ = false;
105 } 114 }
106 115
107 void HostZoomMap::Shutdown() { 116 void HostZoomMap::Shutdown() {
108 if (!profile_) 117 if (!profile_)
109 return; 118 return;
110 119
111 registrar_.Remove(this, 120 registrar_.Remove(this,
112 NotificationType::PROFILE_DESTROYED, 121 NotificationType::PROFILE_DESTROYED,
113 Source<Profile>(profile_)); 122 Source<Profile>(profile_));
114 profile_->GetPrefs()->RemovePrefObserver(prefs::kPerHostZoomLevels, this); 123 if (!profile_->IsOffTheRecord())
124 profile_->GetPrefs()->RemovePrefObserver(prefs::kPerHostZoomLevels, this);
115 profile_ = NULL; 125 profile_ = NULL;
116 } 126 }
117 127
118 void HostZoomMap::Observe( 128 void HostZoomMap::Observe(
119 NotificationType type, 129 NotificationType type,
120 const NotificationSource& source, 130 const NotificationSource& source,
121 const NotificationDetails& details) { 131 const NotificationDetails& details) {
122 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 132 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
123 133
124 // If the profile is going away, we need to stop using it. 134 // If the profile is going away, we need to stop using it.
(...skipping 13 matching lines...) Expand all
138 return; 148 return;
139 } 149 }
140 } 150 }
141 151
142 NOTREACHED() << "Unexpected preference observed."; 152 NOTREACHED() << "Unexpected preference observed.";
143 } 153 }
144 154
145 HostZoomMap::~HostZoomMap() { 155 HostZoomMap::~HostZoomMap() {
146 Shutdown(); 156 Shutdown();
147 } 157 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698