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

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

Issue 6142009: Upating the app, ceee, chrome, ipc, media, and net directories to use the correct lock.h file. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Unified patch updating all references to the new base/synchronization/lock.h Created 9 years, 11 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 | « chrome/browser/host_zoom_map.h ('k') | chrome/browser/in_process_webkit/webkit_thread.h » ('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 <cmath> 5 #include <cmath>
6 6
7 #include "chrome/browser/host_zoom_map.h" 7 #include "chrome/browser/host_zoom_map.h"
8 8
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 registrar_.Add( 45 registrar_.Add(
46 this, NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 46 this, NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
47 NotificationService::AllSources()); 47 NotificationService::AllSources());
48 } 48 }
49 49
50 void HostZoomMap::Load() { 50 void HostZoomMap::Load() {
51 if (!profile_) 51 if (!profile_)
52 return; 52 return;
53 53
54 AutoLock auto_lock(lock_); 54 base::AutoLock auto_lock(lock_);
55 host_zoom_levels_.clear(); 55 host_zoom_levels_.clear();
56 const DictionaryValue* host_zoom_dictionary = 56 const DictionaryValue* host_zoom_dictionary =
57 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels); 57 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels);
58 // Careful: The returned value could be NULL if the pref has never been set. 58 // Careful: The returned value could be NULL if the pref has never been set.
59 if (host_zoom_dictionary != NULL) { 59 if (host_zoom_dictionary != NULL) {
60 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); 60 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys());
61 i != host_zoom_dictionary->end_keys(); ++i) { 61 i != host_zoom_dictionary->end_keys(); ++i) {
62 const std::string& host(*i); 62 const std::string& host(*i);
63 double zoom_level = 0; 63 double zoom_level = 0;
64 64
(...skipping 23 matching lines...) Expand all
88 } 88 }
89 } 89 }
90 90
91 // static 91 // static
92 void HostZoomMap::RegisterUserPrefs(PrefService* prefs) { 92 void HostZoomMap::RegisterUserPrefs(PrefService* prefs) {
93 prefs->RegisterDictionaryPref(prefs::kPerHostZoomLevels); 93 prefs->RegisterDictionaryPref(prefs::kPerHostZoomLevels);
94 } 94 }
95 95
96 double HostZoomMap::GetZoomLevel(const GURL& url) const { 96 double HostZoomMap::GetZoomLevel(const GURL& url) const {
97 std::string host(net::GetHostOrSpecFromURL(url)); 97 std::string host(net::GetHostOrSpecFromURL(url));
98 AutoLock auto_lock(lock_); 98 base::AutoLock auto_lock(lock_);
99 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); 99 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
100 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; 100 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second;
101 } 101 }
102 102
103 void HostZoomMap::SetZoomLevel(const GURL& url, double level) { 103 void HostZoomMap::SetZoomLevel(const GURL& url, double level) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105 if (!profile_) 105 if (!profile_)
106 return; 106 return;
107 107
108 std::string host(net::GetHostOrSpecFromURL(url)); 108 std::string host(net::GetHostOrSpecFromURL(url));
109 109
110 { 110 {
111 AutoLock auto_lock(lock_); 111 base::AutoLock auto_lock(lock_);
112 if (level == default_zoom_level_) 112 if (level == default_zoom_level_)
113 host_zoom_levels_.erase(host); 113 host_zoom_levels_.erase(host);
114 else 114 else
115 host_zoom_levels_[host] = level; 115 host_zoom_levels_[host] = level;
116 } 116 }
117 117
118 NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED, 118 NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED,
119 Source<Profile>(profile_), 119 Source<Profile>(profile_),
120 NotificationService::NoDetails()); 120 NotificationService::NoDetails());
121 121
(...skipping 12 matching lines...) Expand all
134 } else { 134 } else {
135 host_zoom_dictionary->SetWithoutPathExpansion( 135 host_zoom_dictionary->SetWithoutPathExpansion(
136 host, Value::CreateRealValue(level)); 136 host, Value::CreateRealValue(level));
137 } 137 }
138 } 138 }
139 updating_preferences_ = false; 139 updating_preferences_ = false;
140 } 140 }
141 141
142 double HostZoomMap::GetTemporaryZoomLevel(int render_process_id, 142 double HostZoomMap::GetTemporaryZoomLevel(int render_process_id,
143 int render_view_id) const { 143 int render_view_id) const {
144 AutoLock auto_lock(lock_); 144 base::AutoLock auto_lock(lock_);
145 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { 145 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) {
146 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 146 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
147 temporary_zoom_levels_[i].render_view_id == render_view_id) { 147 temporary_zoom_levels_[i].render_view_id == render_view_id) {
148 return temporary_zoom_levels_[i].zoom_level; 148 return temporary_zoom_levels_[i].zoom_level;
149 } 149 }
150 } 150 }
151 return 0; 151 return 0;
152 } 152 }
153 153
154 void HostZoomMap::SetTemporaryZoomLevel(int render_process_id, 154 void HostZoomMap::SetTemporaryZoomLevel(int render_process_id,
155 int render_view_id, 155 int render_view_id,
156 double level) { 156 double level) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
158 if (!profile_) 158 if (!profile_)
159 return; 159 return;
160 160
161 { 161 {
162 AutoLock auto_lock(lock_); 162 base::AutoLock auto_lock(lock_);
163 size_t i; 163 size_t i;
164 for (i = 0; i < temporary_zoom_levels_.size(); ++i) { 164 for (i = 0; i < temporary_zoom_levels_.size(); ++i) {
165 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 165 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
166 temporary_zoom_levels_[i].render_view_id == render_view_id) { 166 temporary_zoom_levels_[i].render_view_id == render_view_id) {
167 if (level) { 167 if (level) {
168 temporary_zoom_levels_[i].zoom_level = level; 168 temporary_zoom_levels_[i].zoom_level = level;
169 } else { 169 } else {
170 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); 170 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i);
171 } 171 }
172 break; 172 break;
(...skipping 13 matching lines...) Expand all
186 Source<Profile>(profile_), 186 Source<Profile>(profile_),
187 NotificationService::NoDetails()); 187 NotificationService::NoDetails());
188 } 188 }
189 189
190 void HostZoomMap::ResetToDefaults() { 190 void HostZoomMap::ResetToDefaults() {
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
192 if (!profile_) 192 if (!profile_)
193 return; 193 return;
194 194
195 { 195 {
196 AutoLock auto_lock(lock_); 196 base::AutoLock auto_lock(lock_);
197 host_zoom_levels_.clear(); 197 host_zoom_levels_.clear();
198 } 198 }
199 199
200 updating_preferences_ = true; 200 updating_preferences_ = true;
201 profile_->GetPrefs()->ClearPref(prefs::kPerHostZoomLevels); 201 profile_->GetPrefs()->ClearPref(prefs::kPerHostZoomLevels);
202 updating_preferences_ = false; 202 updating_preferences_ = false;
203 } 203 }
204 204
205 void HostZoomMap::Shutdown() { 205 void HostZoomMap::Shutdown() {
206 if (!profile_) 206 if (!profile_)
(...skipping 10 matching lines...) Expand all
217 const NotificationSource& source, 217 const NotificationSource& source,
218 const NotificationDetails& details) { 218 const NotificationDetails& details) {
219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
220 220
221 switch (type.value) { 221 switch (type.value) {
222 case NotificationType::PROFILE_DESTROYED: 222 case NotificationType::PROFILE_DESTROYED:
223 // If the profile is going away, we need to stop using it. 223 // If the profile is going away, we need to stop using it.
224 Shutdown(); 224 Shutdown();
225 break; 225 break;
226 case NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { 226 case NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: {
227 AutoLock auto_lock(lock_); 227 base::AutoLock auto_lock(lock_);
228 int render_view_id = Source<RenderViewHost>(source)->routing_id(); 228 int render_view_id = Source<RenderViewHost>(source)->routing_id();
229 int render_process_id = Source<RenderViewHost>(source)->process()->id(); 229 int render_process_id = Source<RenderViewHost>(source)->process()->id();
230 230
231 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { 231 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) {
232 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 232 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
233 temporary_zoom_levels_[i].render_view_id == render_view_id) { 233 temporary_zoom_levels_[i].render_view_id == render_view_id) {
234 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); 234 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i);
235 break; 235 break;
236 } 236 }
237 } 237 }
(...skipping 13 matching lines...) Expand all
251 break; 251 break;
252 } 252 }
253 default: 253 default:
254 NOTREACHED() << "Unexpected preference observed."; 254 NOTREACHED() << "Unexpected preference observed.";
255 } 255 }
256 } 256 }
257 257
258 HostZoomMap::~HostZoomMap() { 258 HostZoomMap::~HostZoomMap() {
259 Shutdown(); 259 Shutdown();
260 } 260 }
OLDNEW
« no previous file with comments | « chrome/browser/host_zoom_map.h ('k') | chrome/browser/in_process_webkit/webkit_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698