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/host_zoom_map.cc

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