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

Side by Side Diff: content/browser/host_zoom_map_impl.cc

Issue 11340029: Move remaining files in content\browser to the content namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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
OLDNEW
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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h" 12 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/common/view_messages.h" 14 #include "content/common/view_messages.h"
15 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/resource_context.h" 19 #include "content/public/browser/resource_context.h"
20 #include "content/public/common/page_zoom.h" 20 #include "content/public/common/page_zoom.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
24 24
25 using WebKit::WebView; 25 using WebKit::WebView;
26 using content::BrowserThread;
27 using content::RenderProcessHost;
28 using content::RenderViewHost;
29 26
30 static const char* kHostZoomMapKeyName = "content_host_zoom_map"; 27 static const char* kHostZoomMapKeyName = "content_host_zoom_map";
31 28
32 namespace content { 29 namespace content {
33 30
34 HostZoomMap* HostZoomMap::GetForBrowserContext(BrowserContext* context) { 31 HostZoomMap* HostZoomMap::GetForBrowserContext(BrowserContext* context) {
35 HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>( 32 HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>(
36 context->GetUserData(kHostZoomMapKeyName)); 33 context->GetUserData(kHostZoomMapKeyName));
37 if (!rv) { 34 if (!rv) {
38 rv = new HostZoomMapImpl(); 35 rv = new HostZoomMapImpl();
39 context->SetUserData(kHostZoomMapKeyName, rv); 36 context->SetUserData(kHostZoomMapKeyName, rv);
40 } 37 }
41 return rv; 38 return rv;
42 } 39 }
43 40
44 } // namespace content
45
46 HostZoomMapImpl::HostZoomMapImpl() 41 HostZoomMapImpl::HostZoomMapImpl()
47 : default_zoom_level_(0.0) { 42 : default_zoom_level_(0.0) {
48 registrar_.Add( 43 registrar_.Add(
49 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 44 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
tfarina 2012/10/30 22:19:06 this fits above now.
50 content::NotificationService::AllSources()); 45 NotificationService::AllSources());
51 } 46 }
52 47
53 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { 48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) {
54 // 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
55 // UI: a.CopyFrom(b); 50 // UI: a.CopyFrom(b);
56 // IO: b.CopyFrom(a); 51 // IO: b.CopyFrom(a);
57 // can deadlock. 52 // can deadlock.
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); 54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface);
60 base::AutoLock auto_lock(lock_); 55 base::AutoLock auto_lock(lock_);
61 base::AutoLock copy_auto_lock(copy->lock_); 56 base::AutoLock copy_auto_lock(copy->lock_);
62 for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin()); 57 for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin());
63 i != copy->host_zoom_levels_.end(); ++i) { 58 i != copy->host_zoom_levels_.end(); ++i) {
64 host_zoom_levels_[i->first] = i->second; 59 host_zoom_levels_[i->first] = i->second;
65 } 60 }
66 } 61 }
67 62
68 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const { 63 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const {
69 base::AutoLock auto_lock(lock_); 64 base::AutoLock auto_lock(lock_);
70 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); 65 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
71 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; 66 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second;
72 } 67 }
73 68
74 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) { 69 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 71
77 { 72 {
78 base::AutoLock auto_lock(lock_); 73 base::AutoLock auto_lock(lock_);
79 74
80 if (content::ZoomValuesEqual(level, default_zoom_level_)) 75 if (ZoomValuesEqual(level, default_zoom_level_))
81 host_zoom_levels_.erase(host); 76 host_zoom_levels_.erase(host);
82 else 77 else
83 host_zoom_levels_[host] = level; 78 host_zoom_levels_[host] = level;
84 } 79 }
85 80
86 // Notify renderers from this browser context. 81 // Notify renderers from this browser context.
87 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 82 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
88 !i.IsAtEnd(); i.Advance()) { 83 !i.IsAtEnd(); i.Advance()) {
89 RenderProcessHost* render_process_host = i.GetCurrentValue(); 84 RenderProcessHost* render_process_host = i.GetCurrentValue();
90 if (HostZoomMap::GetForBrowserContext( 85 if (HostZoomMap::GetForBrowserContext(
91 render_process_host->GetBrowserContext()) == this) { 86 render_process_host->GetBrowserContext()) == this) {
92 render_process_host->Send( 87 render_process_host->Send(
93 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); 88 new ViewMsg_SetZoomLevelForCurrentURL(host, level));
94 } 89 }
95 } 90 }
96 91
97 content::NotificationService::current()->Notify( 92 NotificationService::current()->Notify(
98 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 93 NOTIFICATION_ZOOM_LEVEL_CHANGED,
tfarina 2012/10/30 22:19:06 fits above;
99 content::Source<HostZoomMap>(this), 94 Source<HostZoomMap>(this),
100 content::Details<const std::string>(&host)); 95 Details<const std::string>(&host));
101 } 96 }
102 97
103 double HostZoomMapImpl::GetDefaultZoomLevel() const { 98 double HostZoomMapImpl::GetDefaultZoomLevel() const {
104 return default_zoom_level_; 99 return default_zoom_level_;
105 } 100 }
106 101
107 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { 102 void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
108 default_zoom_level_ = level; 103 default_zoom_level_ = level;
109 } 104 }
110 105
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (level && i == temporary_zoom_levels_.size()) { 138 if (level && i == temporary_zoom_levels_.size()) {
144 TemporaryZoomLevel temp; 139 TemporaryZoomLevel temp;
145 temp.render_process_id = render_process_id; 140 temp.render_process_id = render_process_id;
146 temp.render_view_id = render_view_id; 141 temp.render_view_id = render_view_id;
147 temp.zoom_level = level; 142 temp.zoom_level = level;
148 temporary_zoom_levels_.push_back(temp); 143 temporary_zoom_levels_.push_back(temp);
149 } 144 }
150 } 145 }
151 146
152 std::string host; 147 std::string host;
153 content::NotificationService::current()->Notify( 148 NotificationService::current()->Notify(
154 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 149 NOTIFICATION_ZOOM_LEVEL_CHANGED,
tfarina 2012/10/30 22:19:06 fits above.
155 content::Source<HostZoomMap>(this), 150 Source<HostZoomMap>(this),
156 content::Details<const std::string>(&host)); 151 Details<const std::string>(&host));
157 } 152 }
158 153
159 void HostZoomMapImpl::Observe( 154 void HostZoomMapImpl::Observe(int type,
160 int type, 155 const NotificationSource& source,
161 const content::NotificationSource& source, 156 const NotificationDetails& details) {
162 const content::NotificationDetails& details) {
163 switch (type) { 157 switch (type) {
164 case content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { 158 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: {
165 base::AutoLock auto_lock(lock_); 159 base::AutoLock auto_lock(lock_);
166 int render_view_id = 160 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID();
167 content::Source<RenderViewHost>(source)->GetRoutingID();
168 int render_process_id = 161 int render_process_id =
169 content::Source<RenderViewHost>(source)->GetProcess()->GetID(); 162 Source<RenderViewHost>(source)->GetProcess()->GetID();
170 163
171 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { 164 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) {
172 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 165 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
173 temporary_zoom_levels_[i].render_view_id == render_view_id) { 166 temporary_zoom_levels_[i].render_view_id == render_view_id) {
174 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); 167 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i);
175 break; 168 break;
176 } 169 }
177 } 170 }
178 break; 171 break;
179 } 172 }
180 default: 173 default:
181 NOTREACHED() << "Unexpected preference observed."; 174 NOTREACHED() << "Unexpected preference observed.";
182 } 175 }
183 } 176 }
184 177
185 HostZoomMapImpl::~HostZoomMapImpl() { 178 HostZoomMapImpl::~HostZoomMapImpl() {
186 } 179 }
180
181 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698