Chromium Code Reviews| Index: content/browser/host_zoom_map_impl.cc |
| diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc |
| index 81f8182924d58d4d7700b3e072a914cd3c572d4d..52ec563882196854a65b2889a4914416e8564be9 100644 |
| --- a/content/browser/host_zoom_map_impl.cc |
| +++ b/content/browser/host_zoom_map_impl.cc |
| @@ -20,6 +20,8 @@ |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/browser/resource_context.h" |
| +#include "content/public/browser/site_instance.h" |
| +#include "content/public/browser/storage_partition.h" |
| #include "content/public/common/page_zoom.h" |
| #include "content/public/common/url_constants.h" |
| #include "net/base/net_util.h" |
| @@ -28,8 +30,6 @@ namespace content { |
| namespace { |
| -const char kHostZoomMapKeyName[] = "content_host_zoom_map"; |
| - |
| std::string GetHostFromProcessView(int render_process_id, int render_view_id) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| RenderViewHost* render_view_host = |
| @@ -61,29 +61,39 @@ GURL HostZoomMap::GetURLFromEntry(const NavigationEntry* entry) { |
| } |
| HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) { |
| - HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>( |
| - context->GetUserData(kHostZoomMapKeyName)); |
| - if (!rv) { |
| - rv = new HostZoomMapImpl(); |
| - context->SetUserData(kHostZoomMapKeyName, rv); |
| - } |
| - return rv; |
| + StoragePartition* partition = |
| + BrowserContext::GetDefaultStoragePartition(context); |
| + DCHECK(partition); |
| + return partition->GetHostZoomMap(); |
| +} |
| + |
| +HostZoomMap* HostZoomMap::Get(SiteInstance* instance) { |
| + StoragePartition* partition = BrowserContext::GetStoragePartition( |
| + instance->GetBrowserContext(), instance); |
| + DCHECK(partition); |
| + return partition->GetHostZoomMap(); |
| +} |
| + |
| +HostZoomMap* HostZoomMap::GetForWebContents(const WebContents* contents) { |
| + StoragePartition* partition = |
| + BrowserContext::GetStoragePartition(contents->GetBrowserContext(), |
| + contents->GetSiteInstance()); |
| + DCHECK(partition); |
| + return partition->GetHostZoomMap(); |
| } |
| // Helper function for setting/getting zoom levels for WebContents without |
| // having to import HostZoomMapImpl everywhere. |
| double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { |
| - HostZoomMapImpl* host_zoom_map = |
| - static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( |
| - web_contents->GetBrowserContext())); |
| + HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| + HostZoomMap::GetForWebContents(web_contents)); |
| return host_zoom_map->GetZoomLevelForWebContents( |
| *static_cast<const WebContentsImpl*>(web_contents)); |
| } |
| void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { |
| - HostZoomMapImpl* host_zoom_map = |
| - static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( |
| - web_contents->GetBrowserContext())); |
| + HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| + HostZoomMap::GetForWebContents(web_contents)); |
| host_zoom_map->SetZoomLevelForWebContents( |
| *static_cast<const WebContentsImpl*>(web_contents), level); |
| } |
| @@ -243,6 +253,9 @@ void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, |
| } |
| double HostZoomMapImpl::GetDefaultZoomLevel() const { |
| + // This function may be called on different threads, and presumably there's |
| + // no guarantee setting a double is an atomic op on all platforms. |
|
Charlie Reis
2014/11/04 23:43:17
Why do we need this to be called from multiple thr
wjmaclean
2014/11/05 21:55:42
Comment update to "getting". Albert Wong asked for
|
| + base::AutoLock auto_lock(lock_); |
| return default_zoom_level_; |
| } |
| @@ -396,8 +409,10 @@ void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, |
| for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| !i.IsAtEnd(); i.Advance()) { |
| RenderProcessHost* render_process_host = i.GetCurrentValue(); |
| - if (HostZoomMap::GetDefaultForBrowserContext( |
| - render_process_host->GetBrowserContext()) == this) { |
| + // TODO(wjmaclean) This will need to be cleaned up when |
| + // RenderProcessHost::GetStoragePartition() goes away. Perhaps have |
| + // RenderProcessHost expose a GetHostZoomMap() function? |
| + if (render_process_host->GetStoragePartition()->GetHostZoomMap() == this) { |
| render_process_host->Send( |
| new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); |
| } |
| @@ -413,6 +428,7 @@ void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { |
| } |
| HostZoomMapImpl::~HostZoomMapImpl() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| } |
| } // namespace content |