| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |