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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
12 #include "base/compiler_specific.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #include "base/supports_user_data.h"
15 #include "base/synchronization/lock.h"
16 #include "content/public/browser/host_zoom_map.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
22 // HostZoomMap needs to be deleted on the UI thread because it listens
23 // to notifications on there (and holds a NotificationRegistrar).
24 class CONTENT_EXPORT HostZoomMapImpl
: public NON_EXPORTED_BASE(HostZoomMap
),
25 public NotificationObserver
,
26 public base::SupportsUserData::Data
{
29 virtual ~HostZoomMapImpl();
31 // HostZoomMap implementation:
32 virtual void CopyFrom(HostZoomMap
* copy
) OVERRIDE
;
33 virtual double GetZoomLevelForHostAndScheme(
34 const std::string
& scheme
,
35 const std::string
& host
) const OVERRIDE
;
36 virtual void SetZoomLevelForHost(
37 const std::string
& host
,
38 double level
) OVERRIDE
;
39 virtual void SetZoomLevelForHostAndScheme(
40 const std::string
& scheme
,
41 const std::string
& host
,
42 double level
) OVERRIDE
;
43 virtual double GetDefaultZoomLevel() const OVERRIDE
;
44 virtual void SetDefaultZoomLevel(double level
) OVERRIDE
;
45 virtual scoped_ptr
<Subscription
> AddZoomLevelChangedCallback(
46 const ZoomLevelChangedCallback
& callback
) OVERRIDE
;
48 // Returns the temporary zoom level that's only valid for the lifetime of
49 // the given WebContents (i.e. isn't saved and doesn't affect other
50 // WebContentses) if it exists, the default zoom level otherwise.
52 // This may be called on any thread.
53 double GetTemporaryZoomLevel(int render_process_id
,
54 int render_view_id
) const;
56 // Sets the temporary zoom level that's only valid for the lifetime of this
59 // This should only be called on the UI thread.
60 void SetTemporaryZoomLevel(int render_process_id
,
64 // NotificationObserver implementation.
65 virtual void Observe(int type
,
66 const NotificationSource
& source
,
67 const NotificationDetails
& details
) OVERRIDE
;
70 double GetZoomLevelForHost(const std::string
& host
) const;
72 typedef std::map
<std::string
, double> HostZoomLevels
;
73 typedef std::map
<std::string
, HostZoomLevels
> SchemeHostZoomLevels
;
75 // Callbacks called when zoom level changes.
76 base::CallbackList
<void(const ZoomLevelChange
&)>
77 zoom_level_changed_callbacks_
;
79 // Copy of the pref data, so that we can read it on the IO thread.
80 HostZoomLevels host_zoom_levels_
;
81 SchemeHostZoomLevels scheme_host_zoom_levels_
;
82 double default_zoom_level_
;
84 struct TemporaryZoomLevel
{
85 int render_process_id
;
90 // Don't expect more than a couple of tabs that are using a temporary zoom
91 // level, so vector is fine for now.
92 std::vector
<TemporaryZoomLevel
> temporary_zoom_levels_
;
94 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
95 // |temporary_zoom_levels_| to guarantee thread safety.
96 mutable base::Lock lock_
;
98 NotificationRegistrar registrar_
;
100 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl
);
103 } // namespace content
105 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_