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 |