summaryrefslogtreecommitdiff
path: root/chromium/components/zoom/zoom_event_manager.cc
blob: 29640ac4e719bc67a2c6f93126441f8cc8b60736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/zoom/zoom_event_manager.h"

#include <memory>

#include "components/zoom/zoom_event_manager_observer.h"
#include "content/public/browser/browser_context.h"

namespace {
static const char kBrowserZoomEventManager[] = "browser_zoom_event_manager";
}

namespace zoom {

ZoomEventManager* ZoomEventManager::GetForBrowserContext(
    content::BrowserContext* context) {
  if (!context->GetUserData(kBrowserZoomEventManager)) {
    context->SetUserData(kBrowserZoomEventManager,
                         std::make_unique<ZoomEventManager>());
  }
  return static_cast<ZoomEventManager*>(
      context->GetUserData(kBrowserZoomEventManager));
}

ZoomEventManager::ZoomEventManager() {}

ZoomEventManager::~ZoomEventManager() {}

void ZoomEventManager::OnZoomLevelChanged(
    const content::HostZoomMap::ZoomLevelChange& change) {
  zoom_level_changed_callbacks_.Notify(change);
}

std::unique_ptr<content::HostZoomMap::Subscription>
ZoomEventManager::AddZoomLevelChangedCallback(
    content::HostZoomMap::ZoomLevelChangedCallback callback) {
  return zoom_level_changed_callbacks_.Add(std::move(callback));
}

void ZoomEventManager::OnDefaultZoomLevelChanged() {
  for (auto& observer : observers_)
    observer.OnDefaultZoomLevelChanged();
}

void ZoomEventManager::AddObserver(ZoomEventManagerObserver* observer) {
  observers_.AddObserver(observer);
}

void ZoomEventManager::RemoveObserver(ZoomEventManagerObserver* observer) {
  observers_.RemoveObserver(observer);
}

}  // namespace zoom