Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / components / ui / zoom / zoom_event_manager.h
blobb18c3a4fd445acf58c4a8a94ad8761362c0aecef
1 // Copyright 2014 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 COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_H_
6 #define COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_H_
8 #include "base/callback_list.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/supports_user_data.h"
12 #include "content/public/browser/host_zoom_map.h"
14 namespace content {
15 class BrowserContext;
16 } // namespace content
18 namespace ui_zoom {
20 class ZoomEventManagerObserver;
22 // This class serves as a target for event notifications from all ZoomController
23 // objects. Classes that need to know about browser-specific zoom events (e.g.
24 // manual-mode zoom) should subscribe here.
25 class ZoomEventManager : public base::SupportsUserData::Data {
26 public:
27 ZoomEventManager();
28 ~ZoomEventManager() override;
30 // Returns the ZoomEventManager for the specified BrowserContext. This
31 // function creates the ZoomEventManager if it hasn't been created already.
32 static ZoomEventManager* GetForBrowserContext(
33 content::BrowserContext* context);
35 // Called by ZoomControllers when changes are made to zoom levels in manual
36 // mode in order that browser listeners can be notified.
37 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
39 // Add and remove zoom level changed callbacks.
40 // TODO(wjmaclean): Convert this callback mechanism to use
41 // ZoomEventManagerObserver instead.
42 scoped_ptr<content::HostZoomMap::Subscription> AddZoomLevelChangedCallback(
43 const content::HostZoomMap::ZoomLevelChangedCallback& callback);
45 // Called by ZoomLevelDelegates when changes are made to the default zoom
46 // level for their associated HostZoomMap.
47 void OnDefaultZoomLevelChanged();
49 // Add and remove observers.
50 void AddZoomEventManagerObserver(ZoomEventManagerObserver* observer);
51 void RemoveZoomEventManagerObserver(ZoomEventManagerObserver* observer);
53 // Get a weak ptr to be used by clients who may themselves be UserData for
54 // the context, since the order of destruction is undefined between the client
55 // and this class.
56 base::WeakPtr<ZoomEventManager> GetWeakPtr() {
57 return weak_ptr_factory_.GetWeakPtr();
60 private:
61 base::CallbackList<void(const content::HostZoomMap::ZoomLevelChange&)>
62 zoom_level_changed_callbacks_;
63 base::ObserverList<ZoomEventManagerObserver> observers_;
64 base::WeakPtrFactory<ZoomEventManager> weak_ptr_factory_;
66 DISALLOW_COPY_AND_ASSIGN(ZoomEventManager);
69 } // namespace ui_zoom
71 #endif // COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_H_