| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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 // static |
| 13 void ScreenOrientationServiceImpl::Create( |
| 14 ScreenOrientationProvider* provider, |
| 15 mojo::InterfaceRequest<ScreenOrientationService> request) { |
| 16 BindToRequest(new ScreenOrientationServiceImpl(provider), &request); |
| 17 } |
| 18 |
| 19 ScreenOrientationServiceImpl::ScreenOrientationServiceImpl( |
| 20 ScreenOrientationProvider* provider) |
| 21 : provider_(provider), |
| 22 weak_factory_(this) { |
| 23 } |
| 24 |
| 25 ScreenOrientationServiceImpl::~ScreenOrientationServiceImpl() { |
| 26 } |
| 27 |
| 28 void ScreenOrientationServiceImpl::NotifyLockResult( |
| 29 ScreenOrientationLockResult result) { |
| 30 if (on_result_callback_.is_null()) |
| 31 return; |
| 32 |
| 33 on_result_callback_.Run(result); |
| 34 |
| 35 // Reset the callback. |
| 36 on_result_callback_ = mojo::Callback<void(ScreenOrientationLockResult)>(); |
| 37 } |
| 38 |
| 39 void ScreenOrientationServiceImpl::LockOrientation( |
| 40 ScreenOrientationLockType lock_type, |
| 41 const mojo::Callback<void(ScreenOrientationLockResult)>& callback) { |
| 42 DCHECK(on_result_callback_.is_null()); |
| 43 on_result_callback_ = callback; |
| 44 |
| 45 if (!provider_) { |
| 46 NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE); |
| 47 return; |
| 48 } |
| 49 |
| 50 provider_->LockOrientation( |
| 51 lock_type, |
| 52 base::Bind(&ScreenOrientationServiceImpl::NotifyLockResult, |
| 53 weak_factory_.GetWeakPtr())); |
| 54 } |
| 55 |
| 56 void ScreenOrientationServiceImpl::UnlockOrientation() { |
| 57 // Cancel any pending lock request. |
| 58 NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
| 59 |
| 60 if (provider_) |
| 61 provider_->UnlockOrientation(); |
| 62 } |
| 63 |
| 64 } // namespace content |
| OLD | NEW |