 Chromium Code Reviews
 Chromium Code Reviews Issue 549603003:
  Create Mojo service for locking/unlocking screen orientation.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 549603003:
  Create Mojo service for locking/unlocking screen orientation.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/browser/web_contents/web_contents_impl.h" | |
| 9 #include "content/public/browser/screen_orientation_provider.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 // static | |
| 14 void ScreenOrientationServiceImpl::Create( | |
| 15 WebContents* web_contents, | |
| 16 mojo::InterfaceRequest<ScreenOrientationService> request) { | |
| 17 BindToRequest(new ScreenOrientationServiceImpl(web_contents), &request); | |
| 18 } | |
| 19 | |
| 20 ScreenOrientationServiceImpl::ScreenOrientationServiceImpl( | |
| 21 WebContents* web_contents) | |
| 22 : context_(static_cast<WebContentsImpl*>(web_contents) | |
| 23 ->screen_orientation_context()), | |
| 
qsr
2014/09/22 13:01:48
The -> should be on the previous line.
 | |
| 24 provider_(ScreenOrientationProvider::Create( | |
| 
qsr
2014/09/22 13:01:48
As discussed live, maybe we want the provider to b
 
blundell
2014/09/22 13:21:54
Yes, I agree. The provider can be per-WebContents
 | |
| 25 base::Bind(&ScreenOrientationServiceImpl::NotifyLockResult, | |
| 26 base::Unretained(this)), | |
| 27 web_contents)) { | |
| 28 context_->AddObserver(this); | |
| 29 } | |
| 30 | |
| 31 ScreenOrientationServiceImpl::~ScreenOrientationServiceImpl() { | |
| 32 context_->RemoveObserver(this); | |
| 33 } | |
| 34 | |
| 35 void ScreenOrientationServiceImpl::NotifyLockResult( | |
| 36 ScreenOrientationLockResult result) { | |
| 37 if (on_result_callback_.is_null()) | |
| 38 return; | |
| 39 | |
| 40 on_result_callback_.Run(result); | |
| 41 | |
| 42 // Reset the callback. | |
| 43 on_result_callback_ = mojo::Callback<void(ScreenOrientationLockResult)>(); | |
| 44 } | |
| 45 | |
| 46 void ScreenOrientationServiceImpl::OnScreenOrientationChange() { | |
| 47 if (provider_) | |
| 48 provider_->OnOrientationChange(); | |
| 49 } | |
| 50 | |
| 51 void ScreenOrientationServiceImpl::OnNewLockRequest() { | |
| 52 // Cancel any pending lock request. | |
| 53 NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | |
| 54 } | |
| 55 | |
| 56 void ScreenOrientationServiceImpl::LockOrientation( | |
| 57 ScreenOrientationLockType lock_type, | |
| 58 const mojo::Callback<void(ScreenOrientationLockResult)>& callback) { | |
| 59 context_->OnNewLockRequest(); | |
| 60 | |
| 61 DCHECK(on_result_callback_.is_null()); | |
| 62 on_result_callback_ = callback; | |
| 63 | |
| 64 if (!provider_) { | |
| 65 NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE); | |
| 66 return; | |
| 67 } | |
| 68 | |
| 69 provider_->LockOrientation(lock_type); | |
| 70 } | |
| 71 | |
| 72 void ScreenOrientationServiceImpl::UnlockOrientation() { | |
| 73 // Cancel any pending lock request. | |
| 74 NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | |
| 75 | |
| 76 if (provider_) | |
| 77 provider_->UnlockOrientation(); | |
| 78 } | |
| 79 | |
| 80 } // namespace content | |
| OLD | NEW |