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

Unified Diff: chrome/browser/profiles/profile.cc

Issue 393133002: Migrate HostZoomMap to live in StoragePartition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile.cc
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index f57decdc2f4ff8c68a4af47d201ae6629bd9ff3c..8557bacaede4b4ec1605f809a6e3f1ebcc127626 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -19,6 +19,7 @@
#include "components/sync_driver/sync_prefs.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
+#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
@@ -36,6 +37,8 @@
#include "extensions/browser/pref_names.h"
#endif
+using content::HostZoomMap;
+
Profile::Profile()
: restored_last_session_(false),
sent_destroyed_notification_(false),
@@ -267,3 +270,46 @@ bool ProfileCompare::operator()(Profile* a, Profile* b) const {
return false;
return a->GetOriginalProfile() < b->GetOriginalProfile();
}
+
+double Profile::GetDefaultZoomLevel() {
+ return GetDefaultStoragePartition(this)
+ ->GetHostZoomMap()
+ ->GetDefaultZoomLevel();
+}
+
+void Profile::TrackZoomLevelsFromParent(Profile* parent) {
+ // This function only makes sense in a derived class that implements
+ // HostZoomMaps.
+ DCHECK(parent->GetProfileType() != INCOGNITO_PROFILE);
+
+ // Here we only want to use zoom levels stored in the main-context's default
+ // storage partition. We're not interested in zoom levels in special
+ // partitions, e.g. those used by WebViewGuests.
+ HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this);
+ HostZoomMap* parent_host_zoom_map =
+ HostZoomMap::GetDefaultForBrowserContext(parent);
+ host_zoom_map->CopyFrom(parent_host_zoom_map);
+ // Observe parent profile's HostZoomMap changes so they can also be applied
+ // to this profile's HostZoomMap.
+ // Important: this function should never be made virtual without moving the
+ // subscription down to the leaf nodes(s).
+ track_zoom_subscription_ = parent_host_zoom_map->AddZoomLevelChangedCallback(
+ base::Bind(&Profile::TrackZoomLevelChanged, base::Unretained(this)));
+}
+
+void Profile::TrackZoomLevelChanged(
+ const HostZoomMap::ZoomLevelChange& change) {
+ HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this);
+ switch (change.mode) {
+ case HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM:
+ return;
+ case HostZoomMap::ZOOM_CHANGED_FOR_HOST:
+ host_zoom_map->SetZoomLevelForHost(change.host, change.zoom_level);
+ return;
+ case HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST:
+ host_zoom_map->SetZoomLevelForHostAndScheme(change.scheme,
+ change.host,
+ change.zoom_level);
+ return;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698