Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: content/browser/screen_orientation/screen_orientation_service_impl.cc

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Moved enum mojo definition to content/common due to dependency issue Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #include "content/browser/screen_orientation/screen_orientation_service_impl.h"
6
7 #include "base/bind.h"
8 #include "content/public/browser/screen_orientation_provider.h"
9
10 namespace content {
11
12 using typename mojom::ScreenOrientationLockResult;
13
14 // static
15 void ScreenOrientationServiceImpl::Create(
16 ScreenOrientationProvider* provider,
17 mojom::ScreenOrientationServiceRequest request) {
18 new ScreenOrientationServiceImpl(provider, std::move(request));
19 }
20
21 ScreenOrientationServiceImpl::ScreenOrientationServiceImpl(
22 ScreenOrientationProvider* provider,
23 mojom::ScreenOrientationServiceRequest request)
24 : provider_(provider),
25 binding_(this, std::move(request)),
26 weak_factory_(this) {}
27
28 ScreenOrientationServiceImpl::~ScreenOrientationServiceImpl() = default;
29
30 void ScreenOrientationServiceImpl::LockOrientation(
31 blink::WebScreenOrientationLockType orientation,
32 const LockOrientationCallback& callback) {
33 DCHECK(on_result_callback_.is_null());
34 on_result_callback_ = callback;
35
36 if (!provider_) {
37 NotifyLockResult(ScreenOrientationLockResult::
38 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE);
39 return;
40 }
41
42 provider_->LockOrientation(
43 orientation, base::Bind(&ScreenOrientationServiceImpl::NotifyLockResult,
44 weak_factory_.GetWeakPtr()));
45 }
46
47 void ScreenOrientationServiceImpl::UnlockOrientation() {
48 // Cancel any pending lock request.
49 NotifyLockResult(ScreenOrientationLockResult::
50 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
51
52 if (provider_)
53 provider_->UnlockOrientation();
54 }
55
56 void ScreenOrientationServiceImpl::NotifyLockResult(
57 ScreenOrientationLockResult result) {
58 if (on_result_callback_.is_null())
59 return;
60
61 on_result_callback_.Run(result);
62
63 // Reset the callback.
64 on_result_callback_ = LockOrientationCallback();
65 }
66
67 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698