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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 7 #include "content/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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "content/browser/browser_thread.h" 12 #include "content/browser/browser_thread.h"
13 #include "content/browser/renderer_host/render_process_host.h" 13 #include "content/browser/renderer_host/render_process_host.h"
14 #include "content/browser/renderer_host/render_view_host.h" 14 #include "content/browser/renderer_host/render_view_host.h"
15 #include "content/common/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
20 20
21 using WebKit::WebView; 21 using WebKit::WebView;
22 22
23 HostZoomMap::HostZoomMap() 23 HostZoomMap::HostZoomMap()
24 : default_zoom_level_(0.0), 24 : default_zoom_level_(0.0),
25 original_(this) { 25 original_(this) {
26 Init(); 26 Init();
27 } 27 }
28 28
29 HostZoomMap::HostZoomMap(HostZoomMap* original) 29 HostZoomMap::HostZoomMap(HostZoomMap* original)
30 : default_zoom_level_(0.0), 30 : default_zoom_level_(0.0),
31 original_(original) { 31 original_(original) {
32 DCHECK(original); 32 DCHECK(original);
33 Init(); 33 Init();
34 base::AutoLock auto_lock(original->lock_); 34 base::AutoLock auto_lock(original->lock_);
35 for (HostZoomLevels::const_iterator i(original->host_zoom_levels_.begin()); 35 for (HostZoomLevels::const_iterator i(original->host_zoom_levels_.begin());
36 i != original->host_zoom_levels_.end(); ++i) { 36 i != original->host_zoom_levels_.end(); ++i) {
37 host_zoom_levels_[i->first] = i->second; 37 host_zoom_levels_[i->first] = i->second;
38 } 38 }
39 } 39 }
40 40
41 void HostZoomMap::Init() { 41 void HostZoomMap::Init() {
42 registrar_.Add( 42 registrar_.Add(
43 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 43 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
44 NotificationService::AllSources()); 44 content::NotificationService::AllSources());
45 } 45 }
46 46
47 double HostZoomMap::GetZoomLevel(const std::string& host) const { 47 double HostZoomMap::GetZoomLevel(const std::string& host) const {
48 base::AutoLock auto_lock(lock_); 48 base::AutoLock auto_lock(lock_);
49 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); 49 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
50 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; 50 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second;
51 } 51 }
52 52
53 void HostZoomMap::SetZoomLevel(std::string host, double level) { 53 void HostZoomMap::SetZoomLevel(std::string host, double level) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 55
56 { 56 {
57 base::AutoLock auto_lock(lock_); 57 base::AutoLock auto_lock(lock_);
58 if (level == default_zoom_level_) 58 if (level == default_zoom_level_)
59 host_zoom_levels_.erase(host); 59 host_zoom_levels_.erase(host);
60 else 60 else
61 host_zoom_levels_[host] = level; 61 host_zoom_levels_[host] = level;
62 } 62 }
63 63
64 NotificationService::current()->Notify( 64 content::NotificationService::current()->Notify(
65 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 65 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
66 content::Source<HostZoomMap>(this), 66 content::Source<HostZoomMap>(this),
67 content::Details<const std::string>(&host)); 67 content::Details<const std::string>(&host));
68 } 68 }
69 69
70 double HostZoomMap::GetTemporaryZoomLevel(int render_process_id, 70 double HostZoomMap::GetTemporaryZoomLevel(int render_process_id,
71 int render_view_id) const { 71 int render_view_id) const {
72 base::AutoLock auto_lock(lock_); 72 base::AutoLock auto_lock(lock_);
73 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { 73 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) {
74 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 74 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
(...skipping 27 matching lines...) Expand all
102 if (level && i == temporary_zoom_levels_.size()) { 102 if (level && i == temporary_zoom_levels_.size()) {
103 TemporaryZoomLevel temp; 103 TemporaryZoomLevel temp;
104 temp.render_process_id = render_process_id; 104 temp.render_process_id = render_process_id;
105 temp.render_view_id = render_view_id; 105 temp.render_view_id = render_view_id;
106 temp.zoom_level = level; 106 temp.zoom_level = level;
107 temporary_zoom_levels_.push_back(temp); 107 temporary_zoom_levels_.push_back(temp);
108 } 108 }
109 } 109 }
110 110
111 std::string host; 111 std::string host;
112 NotificationService::current()->Notify( 112 content::NotificationService::current()->Notify(
113 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 113 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
114 content::Source<HostZoomMap>(this), 114 content::Source<HostZoomMap>(this),
115 content::Details<const std::string>(&host)); 115 content::Details<const std::string>(&host));
116 } 116 }
117 117
118 void HostZoomMap::Observe( 118 void HostZoomMap::Observe(
119 int type, 119 int type,
120 const content::NotificationSource& source, 120 const content::NotificationSource& source,
121 const content::NotificationDetails& details) { 121 const content::NotificationDetails& details) {
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 15 matching lines...) Expand all
138 } 138 }
139 break; 139 break;
140 } 140 }
141 default: 141 default:
142 NOTREACHED() << "Unexpected preference observed."; 142 NOTREACHED() << "Unexpected preference observed.";
143 } 143 }
144 } 144 }
145 145
146 HostZoomMap::~HostZoomMap() { 146 HostZoomMap::~HostZoomMap() {
147 } 147 }
OLDNEW
« no previous file with comments | « content/browser/download/mhtml_generation_manager.cc ('k') | content/browser/mach_broker_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698