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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/screen_orientation/screen_orientation_service_impl.cc
diff --git a/content/browser/screen_orientation/screen_orientation_service_impl.cc b/content/browser/screen_orientation/screen_orientation_service_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7f3e195da476303684326b7cf63039633b151df9
--- /dev/null
+++ b/content/browser/screen_orientation/screen_orientation_service_impl.cc
@@ -0,0 +1,67 @@
+// Copyright 2016 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 "content/browser/screen_orientation/screen_orientation_service_impl.h"
+
+#include "base/bind.h"
+#include "content/public/browser/screen_orientation_provider.h"
+
+namespace content {
+
+using typename mojom::ScreenOrientationLockResult;
+
+// static
+void ScreenOrientationServiceImpl::Create(
+ ScreenOrientationProvider* provider,
+ mojom::ScreenOrientationServiceRequest request) {
+ new ScreenOrientationServiceImpl(provider, std::move(request));
+}
+
+ScreenOrientationServiceImpl::ScreenOrientationServiceImpl(
+ ScreenOrientationProvider* provider,
+ mojom::ScreenOrientationServiceRequest request)
+ : provider_(provider),
+ binding_(this, std::move(request)),
+ weak_factory_(this) {}
+
+ScreenOrientationServiceImpl::~ScreenOrientationServiceImpl() = default;
+
+void ScreenOrientationServiceImpl::LockOrientation(
+ blink::WebScreenOrientationLockType orientation,
+ const LockOrientationCallback& callback) {
+ DCHECK(on_result_callback_.is_null());
+ on_result_callback_ = callback;
+
+ if (!provider_) {
+ NotifyLockResult(ScreenOrientationLockResult::
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE);
+ return;
+ }
+
+ provider_->LockOrientation(
+ orientation, base::Bind(&ScreenOrientationServiceImpl::NotifyLockResult,
+ weak_factory_.GetWeakPtr()));
+}
+
+void ScreenOrientationServiceImpl::UnlockOrientation() {
+ // Cancel any pending lock request.
+ NotifyLockResult(ScreenOrientationLockResult::
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
+
+ if (provider_)
+ provider_->UnlockOrientation();
+}
+
+void ScreenOrientationServiceImpl::NotifyLockResult(
+ ScreenOrientationLockResult result) {
+ if (on_result_callback_.is_null())
+ return;
+
+ on_result_callback_.Run(result);
+
+ // Reset the callback.
+ on_result_callback_ = LockOrientationCallback();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698