summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/screen_orientation/screen_orientation_dispatcher.cc
blob: 67512ed90df8c687b589c2dde9d6a18a4c850482 (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
// 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 "third_party/blink/renderer/modules/screen_orientation/screen_orientation_dispatcher.h"

#include "services/device/public/mojom/constants.mojom-blink.h"
#include "services/service_manager/public/cpp/connector.h"
#include "third_party/blink/public/platform/platform.h"

namespace blink {

ScreenOrientationDispatcher& ScreenOrientationDispatcher::Instance() {
  DEFINE_STATIC_LOCAL(Persistent<ScreenOrientationDispatcher>,
                      screen_orientation_dispatcher,
                      (new ScreenOrientationDispatcher));
  return *screen_orientation_dispatcher;
}

ScreenOrientationDispatcher::ScreenOrientationDispatcher() = default;

ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
  DCHECK(!listener_);
}

void ScreenOrientationDispatcher::Trace(blink::Visitor* visitor) {
  PlatformEventDispatcher::Trace(visitor);
}

void ScreenOrientationDispatcher::StartListening(LocalFrame* frame) {
  DCHECK(!listener_);

  Platform::Current()->GetConnector()->BindInterface(
      device::mojom::blink::kServiceName, mojo::MakeRequest(&listener_));
  listener_->Start();
}

void ScreenOrientationDispatcher::StopListening() {
  DCHECK(listener_);

  listener_->Stop();
  listener_.reset();
}

}  // namespace blink