Commit 89805c18 authored by jam@chromium.org's avatar jam@chromium.org

Remove Profile code from HostZoomMap.

BUG=76788
Review URL: http://codereview.chromium.org/7067005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86367 0039d316-1c4b-4281-b951-d872f2087c98
parent 149b7aff
...@@ -484,7 +484,7 @@ class OffTheRecordProfileImpl : public Profile, ...@@ -484,7 +484,7 @@ class OffTheRecordProfileImpl : public Profile,
virtual HostZoomMap* GetHostZoomMap() { virtual HostZoomMap* GetHostZoomMap() {
if (!host_zoom_map_) if (!host_zoom_map_)
host_zoom_map_ = new HostZoomMap(this); host_zoom_map_ = new HostZoomMap();
return host_zoom_map_.get(); return host_zoom_map_.get();
} }
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "chrome/browser/policy/profile_policy_connector_factory.h" #include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/pref_value_store.h" #include "chrome/browser/prefs/pref_value_store.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/profiles/profile_dependency_manager.h" #include "chrome/browser/profiles/profile_dependency_manager.h"
...@@ -947,9 +948,28 @@ HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { ...@@ -947,9 +948,28 @@ HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
HostZoomMap* ProfileImpl::GetHostZoomMap() { HostZoomMap* ProfileImpl::GetHostZoomMap() {
if (!host_zoom_map_) { if (!host_zoom_map_) {
host_zoom_map_ = new HostZoomMap(this); host_zoom_map_ = new HostZoomMap();
host_zoom_map_->set_default_zoom_level( host_zoom_map_->set_default_zoom_level(
GetPrefs()->GetDouble(prefs::kDefaultZoomLevel)); GetPrefs()->GetDouble(prefs::kDefaultZoomLevel));
const DictionaryValue* host_zoom_dictionary =
prefs_->GetDictionary(prefs::kPerHostZoomLevels);
// Careful: The returned value could be NULL if the pref has never been set.
if (host_zoom_dictionary != NULL) {
for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys());
i != host_zoom_dictionary->end_keys(); ++i) {
const std::string& host(*i);
double zoom_level = 0;
bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion(
host, &zoom_level);
DCHECK(success);
host_zoom_map_->SetZoomLevel(GURL(host), zoom_level);
}
}
registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED,
Source<HostZoomMap>(host_zoom_map_));
} }
return host_zoom_map_.get(); return host_zoom_map_.get();
} }
...@@ -1374,6 +1394,21 @@ void ProfileImpl::Observe(NotificationType type, ...@@ -1374,6 +1394,21 @@ void ProfileImpl::Observe(NotificationType type,
registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
Source<Profile>(this)); Source<Profile>(this));
break; break;
case NotificationType::ZOOM_LEVEL_CHANGED: {
const std::string& host = *(Details<const std::string>(details).ptr());
if (!host.empty()) {
double level = host_zoom_map_->GetZoomLevel(GURL(host));
DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
DictionaryValue* host_zoom_dictionary = update.Get();
if (level == host_zoom_map_->default_zoom_level()) {
host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
} else {
host_zoom_dictionary->SetWithoutPathExpansion(
host, Value::CreateDoubleValue(level));
}
}
break;
}
default: default:
NOTREACHED(); NOTREACHED();
} }
......
...@@ -223,7 +223,7 @@ void BrowserToolbarGtk::Init(Profile* profile, ...@@ -223,7 +223,7 @@ void BrowserToolbarGtk::Init(Profile* profile,
wrench_menu_.reset(new MenuGtk(this, &wrench_menu_model_)); wrench_menu_.reset(new MenuGtk(this, &wrench_menu_model_));
registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED,
Source<Profile>(browser_->profile())); Source<HostZoomMap>(browser_->profile()->GetHostZoomMap()));
if (ShouldOnlyShowLocation()) { if (ShouldOnlyShowLocation()) {
gtk_widget_show(event_box_); gtk_widget_show(event_box_);
......
...@@ -230,7 +230,7 @@ WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, ...@@ -230,7 +230,7 @@ WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider,
tabstrip_model_->AddObserver(this); tabstrip_model_->AddObserver(this);
registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED,
Source<Profile>(browser_->profile())); Source<HostZoomMap>(browser_->profile()->GetHostZoomMap()));
registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
NotificationService::AllSources()); NotificationService::AllSources());
} }
......
...@@ -438,8 +438,9 @@ class WrenchMenu::ZoomView : public WrenchMenuView, ...@@ -438,8 +438,9 @@ class WrenchMenu::ZoomView : public WrenchMenuView,
UpdateZoomControls(); UpdateZoomControls();
registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, registrar_.Add(
Source<Profile>(menu->browser_->profile())); this, NotificationType::ZOOM_LEVEL_CHANGED,
Source<HostZoomMap>(menu->browser_->profile()->GetHostZoomMap()));
} }
gfx::Size GetPreferredSize() { gfx::Size GetPreferredSize() {
......
...@@ -55,7 +55,6 @@ include_rules = [ ...@@ -55,7 +55,6 @@ include_rules = [
"+chrome/browser/prefs/pref_change_registrar.h", "+chrome/browser/prefs/pref_change_registrar.h",
"+chrome/browser/prefs/pref_service.h", "+chrome/browser/prefs/pref_service.h",
"+chrome/browser/prefs/scoped_user_pref_update.h",
"+chrome/common/pref_names.h", "+chrome/common/pref_names.h",
# http://crbug.com/77090 # http://crbug.com/77090
......
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
#include "base/string_piece.h" #include "base/string_piece.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "content/browser/browser_thread.h" #include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host.h"
...@@ -22,30 +18,10 @@ ...@@ -22,30 +18,10 @@
using WebKit::WebView; using WebKit::WebView;
HostZoomMap::HostZoomMap(Profile* profile) HostZoomMap::HostZoomMap() : default_zoom_level_(0.0) {
: profile_(profile), default_zoom_level_(0.0) {
registrar_.Add( registrar_.Add(
this, NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, this, NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
NotificationService::AllSources()); NotificationService::AllSources());
base::AutoLock auto_lock(lock_);
host_zoom_levels_.clear();
const DictionaryValue* host_zoom_dictionary =
profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels);
// Careful: The returned value could be NULL if the pref has never been set.
if (host_zoom_dictionary != NULL) {
for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys());
i != host_zoom_dictionary->end_keys(); ++i) {
const std::string& host(*i);
double zoom_level = 0;
bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion(
host, &zoom_level);
DCHECK(success);
host_zoom_levels_[host] = zoom_level;
}
}
} }
double HostZoomMap::GetZoomLevel(const GURL& url) const { double HostZoomMap::GetZoomLevel(const GURL& url) const {
...@@ -69,22 +45,8 @@ void HostZoomMap::SetZoomLevel(const GURL& url, double level) { ...@@ -69,22 +45,8 @@ void HostZoomMap::SetZoomLevel(const GURL& url, double level) {
} }
NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED, NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED,
Source<Profile>(profile_), Source<HostZoomMap>(this),
NotificationService::NoDetails()); Details<const std::string>(&host));
// If we're in incognito mode, don't persist changes to the prefs. We'll keep
// them in memory only so they will be forgotten on exiting incognito.
if (profile_->IsOffTheRecord())
return;
DictionaryPrefUpdate update(profile_->GetPrefs(), prefs::kPerHostZoomLevels);
DictionaryValue* host_zoom_dictionary = update.Get();
if (level == default_zoom_level_) {
host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
} else {
host_zoom_dictionary->SetWithoutPathExpansion(
host, Value::CreateDoubleValue(level));
}
} }
double HostZoomMap::GetTemporaryZoomLevel(int render_process_id, double HostZoomMap::GetTemporaryZoomLevel(int render_process_id,
...@@ -129,7 +91,7 @@ void HostZoomMap::SetTemporaryZoomLevel(int render_process_id, ...@@ -129,7 +91,7 @@ void HostZoomMap::SetTemporaryZoomLevel(int render_process_id,
} }
NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED, NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED,
Source<Profile>(profile_), Source<HostZoomMap>(this),
NotificationService::NoDetails()); NotificationService::NoDetails());
} }
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "content/common/notification_registrar.h" #include "content/common/notification_registrar.h"
class GURL; class GURL;
class Profile;
// HostZoomMap needs to be deleted on the UI thread because it listens // HostZoomMap needs to be deleted on the UI thread because it listens
// to notifications on there (and holds a NotificationRegistrar). // to notifications on there (and holds a NotificationRegistrar).
...@@ -30,7 +29,7 @@ class HostZoomMap : ...@@ -30,7 +29,7 @@ class HostZoomMap :
public base::RefCountedThreadSafe<HostZoomMap, public base::RefCountedThreadSafe<HostZoomMap,
BrowserThread::DeleteOnUIThread> { BrowserThread::DeleteOnUIThread> {
public: public:
explicit HostZoomMap(Profile* profile); HostZoomMap();
// Returns the zoom level for a given url. The zoom level is determined by // Returns the zoom level for a given url. The zoom level is determined by
// the host portion of the URL, or (in the absence of a host) the complete // the host portion of the URL, or (in the absence of a host) the complete
...@@ -69,6 +68,7 @@ class HostZoomMap : ...@@ -69,6 +68,7 @@ class HostZoomMap :
const NotificationSource& source, const NotificationSource& source,
const NotificationDetails& details); const NotificationDetails& details);
double default_zoom_level() const { return default_zoom_level_; }
void set_default_zoom_level(double level) { default_zoom_level_ = level; } void set_default_zoom_level(double level) { default_zoom_level_ = level; }
private: private:
...@@ -79,9 +79,6 @@ class HostZoomMap : ...@@ -79,9 +79,6 @@ class HostZoomMap :
~HostZoomMap(); ~HostZoomMap();
// The profile we're associated with.
Profile* profile_;
// Copy of the pref data, so that we can read it on the IO thread. // Copy of the pref data, so that we can read it on the IO thread.
HostZoomLevels host_zoom_levels_; HostZoomLevels host_zoom_levels_;
double default_zoom_level_; double default_zoom_level_;
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "content/browser/browser_thread.h" #include "content/browser/browser_thread.h"
#include "content/browser/child_process_security_policy.h" #include "content/browser/child_process_security_policy.h"
#include "content/browser/content_browser_client.h" #include "content/browser/content_browser_client.h"
#include "content/browser/host_zoom_map.h"
#include "content/browser/plugin_process_host.h" #include "content/browser/plugin_process_host.h"
#include "content/browser/plugin_service.h" #include "content/browser/plugin_service.h"
#include "content/browser/ppapi_plugin_process_host.h" #include "content/browser/ppapi_plugin_process_host.h"
...@@ -292,7 +291,6 @@ RenderMessageFilter::RenderMessageFilter( ...@@ -292,7 +291,6 @@ RenderMessageFilter::RenderMessageFilter(
notification_prefs_( notification_prefs_(
DesktopNotificationServiceFactory::GetForProfile(profile)-> DesktopNotificationServiceFactory::GetForProfile(profile)->
prefs_cache()), prefs_cache()),
host_zoom_map_(profile->GetHostZoomMap()),
incognito_(profile->IsOffTheRecord()), incognito_(profile->IsOffTheRecord()),
webkit_context_(profile->GetWebKitContext()), webkit_context_(profile->GetWebKitContext()),
render_process_id_(render_process_id) { render_process_id_(render_process_id) {
...@@ -375,7 +373,6 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message, ...@@ -375,7 +373,6 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER(ViewHostMsg_RevealFolderInOS, OnRevealFolderInOS) IPC_MESSAGE_HANDLER(ViewHostMsg_RevealFolderInOS, OnRevealFolderInOS)
IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer, IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer,
OnAllocateSharedMemoryBuffer) OnAllocateSharedMemoryBuffer)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL)
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB, OnAllocTransportDIB) IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB, OnAllocTransportDIB)
IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB, OnFreeTransportDIB) IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB, OnFreeTransportDIB)
...@@ -674,40 +671,6 @@ void RenderMessageFilter::OnAllocateSharedMemoryBuffer( ...@@ -674,40 +671,6 @@ void RenderMessageFilter::OnAllocateSharedMemoryBuffer(
shared_buf.GiveToProcess(peer_handle(), handle); shared_buf.GiveToProcess(peer_handle(), handle);
} }
void RenderMessageFilter::OnDidZoomURL(const IPC::Message& message,
double zoom_level,
bool remember,
const GURL& url) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this,
&RenderMessageFilter::UpdateHostZoomLevelsOnUIThread,
zoom_level, remember, url, render_process_id_, message.routing_id()));
}
void RenderMessageFilter::UpdateHostZoomLevelsOnUIThread(
double zoom_level,
bool remember,
const GURL& url,
int render_process_id,
int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (remember) {
host_zoom_map_->SetZoomLevel(url, zoom_level);
// Notify renderers from this profile.
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
RenderProcessHost* render_process_host = i.GetCurrentValue();
if (render_process_host->profile() == profile_) {
render_process_host->Send(
new ViewMsg_SetZoomLevelForCurrentURL(url, zoom_level));
}
}
} else {
host_zoom_map_->SetTemporaryZoomLevel(
render_process_id, render_view_id, zoom_level);
}
}
net::URLRequestContext* RenderMessageFilter::GetRequestContextForURL( net::URLRequestContext* RenderMessageFilter::GetRequestContextForURL(
const GURL& url) { const GURL& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
struct FontDescriptor; struct FontDescriptor;
class ExtensionInfoMap; class ExtensionInfoMap;
class HostContentSettingsMap; class HostContentSettingsMap;
class HostZoomMap;
class NotificationsPrefsCache; class NotificationsPrefsCache;
class Profile; class Profile;
class RenderWidgetHelper; class RenderWidgetHelper;
...@@ -180,16 +179,6 @@ class RenderMessageFilter : public BrowserMessageFilter { ...@@ -180,16 +179,6 @@ class RenderMessageFilter : public BrowserMessageFilter {
// in the renderer on POSIX due to the sandbox. // in the renderer on POSIX due to the sandbox.
void OnAllocateSharedMemoryBuffer(uint32 buffer_size, void OnAllocateSharedMemoryBuffer(uint32 buffer_size,
base::SharedMemoryHandle* handle); base::SharedMemoryHandle* handle);
void OnDidZoomURL(const IPC::Message& message,
double zoom_level,
bool remember,
const GURL& url);
void UpdateHostZoomLevelsOnUIThread(double zoom_level,
bool remember,
const GURL& url,
int render_process_id,
int render_view_id);
void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); void OnResolveProxy(const GURL& url, IPC::Message* reply_msg);
// Browser side transport DIB allocation // Browser side transport DIB allocation
...@@ -254,9 +243,6 @@ class RenderMessageFilter : public BrowserMessageFilter { ...@@ -254,9 +243,6 @@ class RenderMessageFilter : public BrowserMessageFilter {
// Desktop Notifications permission messages. // Desktop Notifications permission messages.
scoped_refptr<NotificationsPrefsCache> notification_prefs_; scoped_refptr<NotificationsPrefsCache> notification_prefs_;
// Handles zoom-related messages.
scoped_refptr<HostZoomMap> host_zoom_map_;
// Whether this process is used for incognito tabs. // Whether this process is used for incognito tabs.
bool incognito_; bool incognito_;
......
...@@ -444,6 +444,7 @@ class RenderViewHost : public RenderWidgetHost { ...@@ -444,6 +444,7 @@ class RenderViewHost : public RenderWidgetHost {
void OnAccessibilityNotifications( void OnAccessibilityNotifications(
const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params); const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params);
void OnScriptEvalResponse(int id, const ListValue& result); void OnScriptEvalResponse(int id, const ListValue& result);
void OnDidZoomURL(double zoom_level, bool remember, const GURL& url);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
void OnMsgShowPopup(const ViewHostMsg_ShowPopup_Params& params); void OnMsgShowPopup(const ViewHostMsg_ShowPopup_Params& params);
......
...@@ -1259,7 +1259,9 @@ class NotificationType { ...@@ -1259,7 +1259,9 @@ class NotificationType {
BOOKMARK_CONTEXT_MENU_SHOWN, BOOKMARK_CONTEXT_MENU_SHOWN,
#endif #endif
// Sent when the zoom level changes. The source is the profile. // Sent when the zoom level changes. The source is the HostZoomMap. The
// details is a string of the hostname for which the zoom changed. In case
// of a temporary zoom level change, the details is an empty string.
ZOOM_LEVEL_CHANGED, ZOOM_LEVEL_CHANGED,
// Sent when the tab's closeable state has changed due to increase/decrease // Sent when the tab's closeable state has changed due to increase/decrease
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment