Chromium Code Reviews| Index: content/public/browser/screen_orientation_provider.cc |
| diff --git a/content/public/browser/screen_orientation_provider.cc b/content/public/browser/screen_orientation_provider.cc |
| index 1a5350ded026755d2ef97e76a021e641ae114e71..7da24eb3d02a3f4605f178b9386710303c172498 100644 |
| --- a/content/public/browser/screen_orientation_provider.cc |
| +++ b/content/public/browser/screen_orientation_provider.cc |
| @@ -5,7 +5,6 @@ |
| #include "content/public/browser/screen_orientation_provider.h" |
| #include "base/callback_helpers.h" |
| -#include "base/optional.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/public/browser/render_widget_host.h" |
| @@ -28,10 +27,11 @@ ScreenOrientationProvider::~ScreenOrientationProvider() { |
| void ScreenOrientationProvider::LockOrientation( |
| blink::WebScreenOrientationLockType orientation, |
| const LockOrientationCallback& callback) { |
| - // ScreenOrientation should have cancelled all pending request at this point. |
| - DCHECK(on_result_callback_.is_null()); |
| - DCHECK(!pending_lock_orientation_.has_value()); |
| - on_result_callback_ = callback; |
| + // Cancel any pending lock request. |
| + NotifyLockResult(ScreenOrientationLockResult:: |
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
| + // Record new pending lock request. |
| + pending_callback_ = callback; |
| if (!delegate_ || !delegate_->ScreenOrientationProviderSupported()) { |
| NotifyLockResult(ScreenOrientationLockResult:: |
| @@ -81,13 +81,16 @@ void ScreenOrientationProvider::LockOrientation( |
| } |
| void ScreenOrientationProvider::UnlockOrientation() { |
| + // Cancel any pending lock request. |
| + NotifyLockResult(ScreenOrientationLockResult:: |
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
| + |
| if (!lock_applied_ || !delegate_) |
| return; |
| delegate_->Unlock(web_contents()); |
| lock_applied_ = false; |
| - pending_lock_orientation_.reset(); |
| } |
| void ScreenOrientationProvider::OnOrientationChange() { |
| @@ -95,7 +98,7 @@ void ScreenOrientationProvider::OnOrientationChange() { |
| return; |
| if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { |
| - DCHECK(!on_result_callback_.is_null()); |
| + DCHECK(!pending_callback_.is_null()); |
| NotifyLockResult( |
| ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
| } |
| @@ -103,11 +106,9 @@ void ScreenOrientationProvider::OnOrientationChange() { |
| void ScreenOrientationProvider::NotifyLockResult( |
| ScreenOrientationLockResult result) { |
| - if (on_result_callback_.is_null()) { |
| - pending_lock_orientation_.reset(); |
| - return; |
| + if (!pending_callback_.is_null()) { |
| + base::ResetAndReturn(&pending_callback_).Run(result); |
| } |
|
kinuko
2017/01/23 02:39:50
nit: no need of block for one-line body
leonhsl(Using Gerrit)
2017/01/23 02:47:10
Got it, as I've sent this CL to CQ now so I will a
|
| - base::ResetAndReturn(&on_result_callback_).Run(result); |
| pending_lock_orientation_.reset(); |
| } |