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 #include "components/ui/zoom/zoom_event_manager.h"
7 #include "components/ui/zoom/zoom_event_manager_observer.h"
8 #include "content/public/browser/browser_context.h"
11 static const char kBrowserZoomEventManager
[] = "browser_zoom_event_manager";
16 ZoomEventManager
* ZoomEventManager::GetForBrowserContext(
17 content::BrowserContext
* context
) {
18 if (!context
->GetUserData(kBrowserZoomEventManager
))
19 context
->SetUserData(kBrowserZoomEventManager
, new ZoomEventManager
);
20 return static_cast<ZoomEventManager
*>(
21 context
->GetUserData(kBrowserZoomEventManager
));
24 ZoomEventManager::ZoomEventManager() : weak_ptr_factory_(this) {
27 ZoomEventManager::~ZoomEventManager() {
30 void ZoomEventManager::OnZoomLevelChanged(
31 const content::HostZoomMap::ZoomLevelChange
& change
) {
32 zoom_level_changed_callbacks_
.Notify(change
);
35 scoped_ptr
<content::HostZoomMap::Subscription
>
36 ZoomEventManager::AddZoomLevelChangedCallback(
37 const content::HostZoomMap::ZoomLevelChangedCallback
& callback
) {
38 return zoom_level_changed_callbacks_
.Add(callback
);
41 void ZoomEventManager::OnDefaultZoomLevelChanged() {
42 FOR_EACH_OBSERVER(ZoomEventManagerObserver
, observers_
,
43 OnDefaultZoomLevelChanged());
46 void ZoomEventManager::AddZoomEventManagerObserver(
47 ZoomEventManagerObserver
* observer
) {
48 observers_
.AddObserver(observer
);
51 void ZoomEventManager::RemoveZoomEventManagerObserver(
52 ZoomEventManagerObserver
* observer
) {
53 observers_
.RemoveObserver(observer
);
56 } // namespace ui_zoom