| 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..b14fd8d70c3d3f82a1891c480024c1e28510f092 | 
| --- /dev/null | 
| +++ b/content/browser/screen_orientation/screen_orientation_service_impl.cc | 
| @@ -0,0 +1,80 @@ | 
| +// Copyright 2014 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/browser/web_contents/web_contents_impl.h" | 
| +#include "content/public/browser/screen_orientation_provider.h" | 
| + | 
| +namespace content { | 
| + | 
| +// static | 
| +void ScreenOrientationServiceImpl::Create( | 
| +    WebContents* web_contents, | 
| +    mojo::InterfaceRequest<ScreenOrientationService> request) { | 
| +  BindToRequest(new ScreenOrientationServiceImpl(web_contents), &request); | 
| +} | 
| + | 
| +ScreenOrientationServiceImpl::ScreenOrientationServiceImpl( | 
| +    WebContents* web_contents) | 
| +    : context_(static_cast<WebContentsImpl*>(web_contents) | 
| +                   ->screen_orientation_context()), | 
| +      provider_(ScreenOrientationProvider::Create( | 
| +          base::Bind(&ScreenOrientationServiceImpl::NotifyLockResult, | 
| +                     base::Unretained(this)), | 
| +          web_contents)) { | 
| +  context_->AddObserver(this); | 
| +} | 
| + | 
| +ScreenOrientationServiceImpl::~ScreenOrientationServiceImpl() { | 
| +  context_->RemoveObserver(this); | 
| +} | 
| + | 
| +void ScreenOrientationServiceImpl::NotifyLockResult( | 
| +    ScreenOrientationLockResult result) { | 
| +  if (on_result_callback_.is_null()) | 
| +    return; | 
| + | 
| +  on_result_callback_.Run(result); | 
| + | 
| +  // Reset the callback. | 
| +  on_result_callback_ = mojo::Callback<void(ScreenOrientationLockResult)>(); | 
| +} | 
| + | 
| +void ScreenOrientationServiceImpl::OnScreenOrientationChange() { | 
| +  if (provider_) | 
| +    provider_->OnOrientationChange(); | 
| +} | 
| + | 
| +void ScreenOrientationServiceImpl::OnNewLockRequest() { | 
| +  // Cancel any pending lock request. | 
| +  NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | 
| +} | 
| + | 
| +void ScreenOrientationServiceImpl::LockOrientation( | 
| +    ScreenOrientationLockType lock_type, | 
| +    const mojo::Callback<void(ScreenOrientationLockResult)>& callback) { | 
| +  context_->OnNewLockRequest(); | 
| + | 
| +  DCHECK(on_result_callback_.is_null()); | 
| +  on_result_callback_ = callback; | 
| + | 
| +  if (!provider_) { | 
| +    NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE); | 
| +    return; | 
| +  } | 
| + | 
| +  provider_->LockOrientation(lock_type); | 
| +} | 
| + | 
| +void ScreenOrientationServiceImpl::UnlockOrientation() { | 
| +  // Cancel any pending lock request. | 
| +  NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | 
| + | 
| +  if (provider_) | 
| +    provider_->UnlockOrientation(); | 
| +} | 
| + | 
| +}  // namespace content | 
|  |