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

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

Issue 393133002: Migrate HostZoomMap to live in StoragePartition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add proper method mock for BrowserContext::CreateZoomLevelDelegate() override. Created 6 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 "content/browser/host_zoom_map_impl.h" 5 #include "content/browser/host_zoom_map_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "content/browser/frame_host/navigation_entry_impl.h" 13 #include "content/browser/frame_host/navigation_entry_impl.h"
14 #include "content/browser/renderer_host/render_process_host_impl.h" 14 #include "content/browser/renderer_host/render_process_host_impl.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/web_contents/web_contents_impl.h" 16 #include "content/browser/web_contents/web_contents_impl.h"
17 #include "content/common/view_messages.h" 17 #include "content/common/view_messages.h"
18 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/resource_context.h" 22 #include "content/public/browser/resource_context.h"
23 #include "content/public/browser/site_instance.h"
24 #include "content/public/browser/storage_partition.h"
23 #include "content/public/common/page_zoom.h" 25 #include "content/public/common/page_zoom.h"
24 #include "content/public/common/url_constants.h" 26 #include "content/public/common/url_constants.h"
25 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
26 28
27 namespace content { 29 namespace content {
28 30
29 namespace { 31 namespace {
30 32
31 const char kHostZoomMapKeyName[] = "content_host_zoom_map";
32
33 std::string GetHostFromProcessView(int render_process_id, int render_view_id) { 33 std::string GetHostFromProcessView(int render_process_id, int render_view_id) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 RenderViewHost* render_view_host = 35 RenderViewHost* render_view_host =
36 RenderViewHost::FromID(render_process_id, render_view_id); 36 RenderViewHost::FromID(render_process_id, render_view_id);
37 if (!render_view_host) 37 if (!render_view_host)
38 return std::string(); 38 return std::string();
39 39
40 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); 40 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host);
41 41
42 NavigationEntry* entry = 42 NavigationEntry* entry =
(...skipping 11 matching lines...) Expand all
54 case PAGE_TYPE_ERROR: 54 case PAGE_TYPE_ERROR:
55 return GURL(kUnreachableWebDataURL); 55 return GURL(kUnreachableWebDataURL);
56 // TODO(wjmaclean): In future, give interstitial pages special treatment as 56 // TODO(wjmaclean): In future, give interstitial pages special treatment as
57 // well. 57 // well.
58 default: 58 default:
59 return entry->GetURL(); 59 return entry->GetURL();
60 } 60 }
61 } 61 }
62 62
63 HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) { 63 HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) {
64 HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>( 64 StoragePartition* partition =
65 context->GetUserData(kHostZoomMapKeyName)); 65 BrowserContext::GetDefaultStoragePartition(context);
66 if (!rv) { 66 DCHECK(partition);
67 rv = new HostZoomMapImpl(); 67 return partition->GetHostZoomMap();
68 context->SetUserData(kHostZoomMapKeyName, rv); 68 }
69 } 69
70 return rv; 70 HostZoomMap* HostZoomMap::Get(SiteInstance* instance) {
71 StoragePartition* partition = BrowserContext::GetStoragePartition(
72 instance->GetBrowserContext(), instance);
73 DCHECK(partition);
74 return partition->GetHostZoomMap();
75 }
76
77 HostZoomMap* HostZoomMap::GetForWebContents(const WebContents* contents) {
78 StoragePartition* partition =
79 BrowserContext::GetStoragePartition(contents->GetBrowserContext(),
80 contents->GetSiteInstance());
81 DCHECK(partition);
82 return partition->GetHostZoomMap();
71 } 83 }
72 84
73 // Helper function for setting/getting zoom levels for WebContents without 85 // Helper function for setting/getting zoom levels for WebContents without
74 // having to import HostZoomMapImpl everywhere. 86 // having to import HostZoomMapImpl everywhere.
75 double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { 87 double HostZoomMap::GetZoomLevel(const WebContents* web_contents) {
76 HostZoomMapImpl* host_zoom_map = 88 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
77 static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( 89 HostZoomMap::GetForWebContents(web_contents));
78 web_contents->GetBrowserContext()));
79 return host_zoom_map->GetZoomLevelForWebContents( 90 return host_zoom_map->GetZoomLevelForWebContents(
80 *static_cast<const WebContentsImpl*>(web_contents)); 91 *static_cast<const WebContentsImpl*>(web_contents));
81 } 92 }
82 93
83 void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { 94 void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) {
84 HostZoomMapImpl* host_zoom_map = 95 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
85 static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( 96 HostZoomMap::GetForWebContents(web_contents));
86 web_contents->GetBrowserContext()));
87 host_zoom_map->SetZoomLevelForWebContents( 97 host_zoom_map->SetZoomLevelForWebContents(
88 *static_cast<const WebContentsImpl*>(web_contents), level); 98 *static_cast<const WebContentsImpl*>(web_contents), level);
89 } 99 }
90 100
91 void HostZoomMap::SendErrorPageZoomLevelRefresh( 101 void HostZoomMap::SendErrorPageZoomLevelRefresh(
92 const WebContents* web_contents) { 102 const WebContents* web_contents) {
93 HostZoomMapImpl* host_zoom_map = 103 HostZoomMapImpl* host_zoom_map =
94 static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( 104 static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext(
95 web_contents->GetBrowserContext())); 105 web_contents->GetBrowserContext()));
96 host_zoom_map->SendErrorPageZoomLevelRefresh(); 106 host_zoom_map->SendErrorPageZoomLevelRefresh();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 HostZoomMap::ZoomLevelChange change; 246 HostZoomMap::ZoomLevelChange change;
237 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; 247 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST;
238 change.host = host; 248 change.host = host;
239 change.scheme = scheme; 249 change.scheme = scheme;
240 change.zoom_level = level; 250 change.zoom_level = level;
241 251
242 zoom_level_changed_callbacks_.Notify(change); 252 zoom_level_changed_callbacks_.Notify(change);
243 } 253 }
244 254
245 double HostZoomMapImpl::GetDefaultZoomLevel() const { 255 double HostZoomMapImpl::GetDefaultZoomLevel() const {
256 // This function may be called on different threads, and presumably there's
257 // no guarantee setting a double is an atomic op on all platforms.
Charlie Reis 2014/11/11 05:29:22 I think you missed the change here, since this sti
wjmaclean 2014/11/11 19:20:52 I must be losing my mind ... thought I had fixed t
Charlie Reis 2014/11/11 23:52:01 Thanks-- that sounds good to me.
258 base::AutoLock auto_lock(lock_);
246 return default_zoom_level_; 259 return default_zoom_level_;
247 } 260 }
248 261
249 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { 262 void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
250 default_zoom_level_ = level; 263 default_zoom_level_ = level;
251 } 264 }
252 265
253 scoped_ptr<HostZoomMap::Subscription> 266 scoped_ptr<HostZoomMap::Subscription>
254 HostZoomMapImpl::AddZoomLevelChangedCallback( 267 HostZoomMapImpl::AddZoomLevelChangedCallback(
255 const ZoomLevelChangedCallback& callback) { 268 const ZoomLevelChangedCallback& callback) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 GetZoomLevelForHost( 402 GetZoomLevelForHost(
390 GetHostFromProcessView(render_process_id, render_view_id)))); 403 GetHostFromProcessView(render_process_id, render_view_id))));
391 } 404 }
392 405
393 void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, 406 void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme,
394 const std::string& host, 407 const std::string& host,
395 double level) { 408 double level) {
396 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 409 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
397 !i.IsAtEnd(); i.Advance()) { 410 !i.IsAtEnd(); i.Advance()) {
398 RenderProcessHost* render_process_host = i.GetCurrentValue(); 411 RenderProcessHost* render_process_host = i.GetCurrentValue();
399 if (HostZoomMap::GetDefaultForBrowserContext( 412 // TODO(wjmaclean) This will need to be cleaned up when
400 render_process_host->GetBrowserContext()) == this) { 413 // RenderProcessHost::GetStoragePartition() goes away. Perhaps have
414 // RenderProcessHost expose a GetHostZoomMap() function?
415 if (render_process_host->GetStoragePartition()->GetHostZoomMap() == this) {
401 render_process_host->Send( 416 render_process_host->Send(
402 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); 417 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level));
403 } 418 }
404 } 419 }
405 } 420 }
406 421
407 void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { 422 void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() {
408 GURL error_url(kUnreachableWebDataURL); 423 GURL error_url(kUnreachableWebDataURL);
409 std::string host = net::GetHostOrSpecFromURL(error_url); 424 std::string host = net::GetHostOrSpecFromURL(error_url);
410 double error_page_zoom_level = GetZoomLevelForHost(host); 425 double error_page_zoom_level = GetZoomLevelForHost(host);
411 426
412 SendZoomLevelChange(std::string(), host, error_page_zoom_level); 427 SendZoomLevelChange(std::string(), host, error_page_zoom_level);
413 } 428 }
414 429
415 HostZoomMapImpl::~HostZoomMapImpl() { 430 HostZoomMapImpl::~HostZoomMapImpl() {
431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
416 } 432 }
417 433
418 } // namespace content 434 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698