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

Unified 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: Remove ref counts, improve comments. Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
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 1b5f7a2f7d752a25cd4fef01246b7a277c975823..28e51f34ba849b5e347e6ecc849acdb60d8ff2f4 100644
--- a/content/browser/host_zoom_map_impl.cc
+++ b/content/browser/host_zoom_map_impl.cc
@@ -20,11 +20,11 @@
#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 "net/base/net_util.h"
-static const char* kHostZoomMapKeyName = "content_host_zoom_map";
-
namespace content {
namespace {
@@ -49,33 +49,45 @@ std::string GetHostFromProcessView(int render_process_id, int render_view_id) {
} // namespace
HostZoomMap* HostZoomMap::GetForBrowserContext(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::GetForBrowserContext(web_contents->GetBrowserContext()));
+ 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::GetForBrowserContext(web_contents->GetBrowserContext()));
+ HostZoomMap::GetForWebContents(web_contents));
host_zoom_map->SetZoomLevelForWebContents(
*static_cast<const WebContentsImpl*>(web_contents), level);
}
-HostZoomMapImpl::HostZoomMapImpl()
- : default_zoom_level_(0.0) {
+HostZoomMapImpl::HostZoomMapImpl(double default_zoom_level)
Fady Samuel 2014/08/13 19:45:43 Why do we take in a default zoom level here?
wjmaclean 2014/08/14 18:18:21 Since we know the default zoom level at constructi
+ : default_zoom_level_(default_zoom_level) {
registrar_.Add(
this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
NotificationService::AllSources());
@@ -140,6 +152,27 @@ double HostZoomMapImpl::GetZoomLevelForHostAndScheme(
return GetZoomLevelForHost(host);
}
+scoped_ptr<base::DictionaryValue> HostZoomMapImpl::ZoomLevelDictionary() const {
+ base::DictionaryValue* dictionary = new base::DictionaryValue();
+ {
+ base::AutoLock auto_lock(lock_);
+
+ for (HostZoomLevels::const_iterator i = host_zoom_levels_.begin();
+ i != host_zoom_levels_.end();
+ ++i) {
+ if (!ZoomValuesEqual(i->second, default_zoom_level_)) {
Fady Samuel 2014/08/13 19:45:42 if (ZoomValuesEqual(i->second, default_zoom_level_
wjmaclean 2014/08/14 18:18:21 Done.
+ dictionary->SetDoubleWithoutPathExpansion(i->first /* host */,
+ i->second /* level */);
+ }
+ }
+ }
+ return scoped_ptr<base::DictionaryValue>(dictionary);
+}
+
+// TODO(wjmaclean) The only non-test caller of this just throws away the non-
+// host entries and makes a dictionary, and so could probably be converted to
+// use ZoomLevelDictionary() instead. The test might also be amenable to
+// something similar.
HostZoomMap::ZoomLevelVector HostZoomMapImpl::GetAllZoomLevels() const {
HostZoomMap::ZoomLevelVector result;
{
@@ -374,8 +407,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::GetForBrowserContext(
- 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));
}
@@ -383,6 +418,8 @@ void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme,
}
HostZoomMapImpl::~HostZoomMapImpl() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698