Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2109)

Unified Diff: content/public/browser/screen_orientation_provider.cc

Issue 2630323002: [ScreenOrientation] Fix a possible crash point in ScreenOrientationProvider. (Closed)
Patch Set: ScreenOrientation does not maintain pending lock request Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/browser/screen_orientation_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « content/public/browser/screen_orientation_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698