| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/host_zoom_map_impl.h" | 7 #include "content/browser/host_zoom_map_impl.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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { | 48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { |
| 49 // This can only be called on the UI thread to avoid deadlocks, otherwise | 49 // This can only be called on the UI thread to avoid deadlocks, otherwise |
| 50 // UI: a.CopyFrom(b); | 50 // UI: a.CopyFrom(b); |
| 51 // IO: b.CopyFrom(a); | 51 // IO: b.CopyFrom(a); |
| 52 // can deadlock. | 52 // can deadlock. |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); | 54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); |
| 55 base::AutoLock auto_lock(lock_); | 55 base::AutoLock auto_lock(lock_); |
| 56 base::AutoLock copy_auto_lock(copy->lock_); | 56 base::AutoLock copy_auto_lock(copy->lock_); |
| 57 for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin()); | 57 host_zoom_levels_. |
| 58 i != copy->host_zoom_levels_.end(); ++i) { | 58 insert(copy->host_zoom_levels_.begin(), copy->host_zoom_levels_.end()); |
| 59 host_zoom_levels_[i->first] = i->second; | 59 for (SchemeHostZoomLevels::const_iterator i(copy-> |
| 60 scheme_host_zoom_levels_.begin()); |
| 61 i != copy->scheme_host_zoom_levels_.end(); ++i) { |
| 62 scheme_host_zoom_levels_[i->first] = HostZoomLevels(); |
| 63 scheme_host_zoom_levels_[i->first]. |
| 64 insert(i->second.begin(), i->second.end()); |
| 60 } | 65 } |
| 61 default_zoom_level_ = copy->default_zoom_level_; | 66 default_zoom_level_ = copy->default_zoom_level_; |
| 62 } | 67 } |
| 63 | 68 |
| 64 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const { | 69 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const { |
| 65 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
| 66 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); | 71 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); |
| 67 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; | 72 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; |
| 68 } | 73 } |
| 69 | 74 |
| 75 double HostZoomMapImpl::GetZoomLevel(const std::string& scheme, |
| 76 const std::string& host) const { |
| 77 { |
| 78 base::AutoLock auto_lock(lock_); |
| 79 SchemeHostZoomLevels::const_iterator scheme_iterator( |
| 80 scheme_host_zoom_levels_.find(scheme)); |
| 81 if (scheme_iterator != scheme_host_zoom_levels_.end()) { |
| 82 HostZoomLevels::const_iterator i(scheme_iterator->second.find(host)); |
| 83 if (i != scheme_iterator->second.end()) |
| 84 return i->second; |
| 85 } |
| 86 } |
| 87 return GetZoomLevel(host); |
| 88 } |
| 89 |
| 70 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) { | 90 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 72 | 92 |
| 73 { | 93 { |
| 74 base::AutoLock auto_lock(lock_); | 94 base::AutoLock auto_lock(lock_); |
| 75 | 95 |
| 76 if (ZoomValuesEqual(level, default_zoom_level_)) | 96 if (ZoomValuesEqual(level, default_zoom_level_)) |
| 77 host_zoom_levels_.erase(host); | 97 host_zoom_levels_.erase(host); |
| 78 else | 98 else |
| 79 host_zoom_levels_[host] = level; | 99 host_zoom_levels_[host] = level; |
| 80 } | 100 } |
| 81 | 101 |
| 82 // Notify renderers from this browser context. | 102 // Notify renderers from this browser context. |
| 83 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 103 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 84 !i.IsAtEnd(); i.Advance()) { | 104 !i.IsAtEnd(); i.Advance()) { |
| 85 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 105 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
| 86 if (HostZoomMap::GetForBrowserContext( | 106 if (HostZoomMap::GetForBrowserContext( |
| 87 render_process_host->GetBrowserContext()) == this) { | 107 render_process_host->GetBrowserContext()) == this) { |
| 88 render_process_host->Send( | 108 render_process_host->Send( |
| 89 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); | 109 new ViewMsg_SetZoomLevelForCurrentURL(std::string(), host, level)); |
| 90 } | 110 } |
| 91 } | 111 } |
| 92 | 112 |
| 113 NotificationService::current()->Notify( |
| 114 NOTIFICATION_ZOOM_LEVEL_CHANGED, |
| 115 Source<HostZoomMap>(this), |
| 116 Details<const std::string>(&host)); |
| 117 } |
| 118 |
| 119 void HostZoomMapImpl::SetZoomLevel(const std::string& scheme, |
| 120 const std::string& host, |
| 121 double level) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 123 { |
| 124 base::AutoLock auto_lock(lock_); |
| 125 scheme_host_zoom_levels_[scheme][host] = level; |
| 126 } |
| 127 |
| 128 // Notify renderers from this browser context. |
| 129 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 130 !i.IsAtEnd(); i.Advance()) { |
| 131 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
| 132 if (HostZoomMap::GetForBrowserContext( |
| 133 render_process_host->GetBrowserContext()) == this) { |
| 134 render_process_host->Send( |
| 135 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); |
| 136 } |
| 137 } |
| 138 |
| 93 NotificationService::current()->Notify( | 139 NotificationService::current()->Notify( |
| 94 NOTIFICATION_ZOOM_LEVEL_CHANGED, | 140 NOTIFICATION_ZOOM_LEVEL_CHANGED, |
| 95 Source<HostZoomMap>(this), | 141 Source<HostZoomMap>(this), |
| 96 Details<const std::string>(&host)); | 142 Details<const std::string>(&host)); |
| 97 } | 143 } |
| 98 | 144 |
| 99 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 145 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
| 100 return default_zoom_level_; | 146 return default_zoom_level_; |
| 101 } | 147 } |
| 102 | 148 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 219 } |
| 174 default: | 220 default: |
| 175 NOTREACHED() << "Unexpected preference observed."; | 221 NOTREACHED() << "Unexpected preference observed."; |
| 176 } | 222 } |
| 177 } | 223 } |
| 178 | 224 |
| 179 HostZoomMapImpl::~HostZoomMapImpl() { | 225 HostZoomMapImpl::~HostZoomMapImpl() { |
| 180 } | 226 } |
| 181 | 227 |
| 182 } // namespace content | 228 } // namespace content |
| OLD | NEW |