Commit 74cbc97f authored by Ke He's avatar Ke He Committed by Commit Bot

Remove base::IDMap from screen_orientation_dispatcher.

As a part of Onion Soup, the screen_orientation_dispatcher will be
moved into blink where the base::IDMap is not allowed to use. So we
remove the base::IDMap first in this CL, which makes the next moving
step easier.

BUG=678545

Change-Id: Id46a80d07c4da90ce8807b1e97a9bee947b1944f
Reviewed-on: https://chromium-review.googlesource.com/846699
Commit-Queue: Ke He <ke.he@intel.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526657}
parent 3c052431
...@@ -26,42 +26,39 @@ void ScreenOrientationDispatcher::OnDestruct() { ...@@ -26,42 +26,39 @@ void ScreenOrientationDispatcher::OnDestruct() {
void ScreenOrientationDispatcher::OnLockOrientationResult( void ScreenOrientationDispatcher::OnLockOrientationResult(
int request_id, int request_id,
ScreenOrientationLockResult result) { ScreenOrientationLockResult result) {
blink::WebLockOrientationCallback* callback = if (!pending_callback_ || request_id != request_id_)
pending_callbacks_.Lookup(request_id);
if (!callback)
return; return;
switch (result) { switch (result) {
case ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS: case ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS:
callback->OnSuccess(); pending_callback_->OnSuccess();
break; break;
case ScreenOrientationLockResult:: case ScreenOrientationLockResult::
SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE: SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE:
callback->OnError(blink::kWebLockOrientationErrorNotAvailable); pending_callback_->OnError(blink::kWebLockOrientationErrorNotAvailable);
break; break;
case ScreenOrientationLockResult:: case ScreenOrientationLockResult::
SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED: SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED:
callback->OnError(blink::kWebLockOrientationErrorFullscreenRequired); pending_callback_->OnError(
blink::kWebLockOrientationErrorFullscreenRequired);
break; break;
case ScreenOrientationLockResult:: case ScreenOrientationLockResult::
SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED: SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED:
callback->OnError(blink::kWebLockOrientationErrorCanceled); pending_callback_->OnError(blink::kWebLockOrientationErrorCanceled);
break; break;
default: default:
NOTREACHED(); NOTREACHED();
break; break;
} }
pending_callbacks_.Remove(request_id); pending_callback_.reset();
} }
void ScreenOrientationDispatcher::CancelPendingLocks() { void ScreenOrientationDispatcher::CancelPendingLocks() {
for (CallbackMap::Iterator<blink::WebLockOrientationCallback> if (!pending_callback_)
iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { return;
iterator.GetCurrentValue()->OnError( pending_callback_->OnError(blink::kWebLockOrientationErrorCanceled);
blink::kWebLockOrientationErrorCanceled); pending_callback_.reset();
pending_callbacks_.Remove(iterator.GetCurrentKey());
}
} }
void ScreenOrientationDispatcher::LockOrientation( void ScreenOrientationDispatcher::LockOrientation(
...@@ -69,12 +66,12 @@ void ScreenOrientationDispatcher::LockOrientation( ...@@ -69,12 +66,12 @@ void ScreenOrientationDispatcher::LockOrientation(
std::unique_ptr<blink::WebLockOrientationCallback> callback) { std::unique_ptr<blink::WebLockOrientationCallback> callback) {
CancelPendingLocks(); CancelPendingLocks();
int request_id = pending_callbacks_.Add(std::move(callback)); pending_callback_ = std::move(callback);
EnsureScreenOrientationService(); EnsureScreenOrientationService();
screen_orientation_->LockOrientation( screen_orientation_->LockOrientation(
orientation, orientation,
base::BindOnce(&ScreenOrientationDispatcher::OnLockOrientationResult, base::BindOnce(&ScreenOrientationDispatcher::OnLockOrientationResult,
base::Unretained(this), request_id)); base::Unretained(this), ++request_id_));
} }
void ScreenOrientationDispatcher::UnlockOrientation() { void ScreenOrientationDispatcher::UnlockOrientation() {
...@@ -83,6 +80,10 @@ void ScreenOrientationDispatcher::UnlockOrientation() { ...@@ -83,6 +80,10 @@ void ScreenOrientationDispatcher::UnlockOrientation() {
screen_orientation_->UnlockOrientation(); screen_orientation_->UnlockOrientation();
} }
int ScreenOrientationDispatcher::GetRequestIdForTests() {
return pending_callback_ ? request_id_ : -1;
}
void ScreenOrientationDispatcher::EnsureScreenOrientationService() { void ScreenOrientationDispatcher::EnsureScreenOrientationService() {
if (!screen_orientation_) { if (!screen_orientation_) {
render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
...@@ -90,12 +91,4 @@ void ScreenOrientationDispatcher::EnsureScreenOrientationService() { ...@@ -90,12 +91,4 @@ void ScreenOrientationDispatcher::EnsureScreenOrientationService() {
} }
} }
int ScreenOrientationDispatcher::GetRequestIdForTests() {
if (pending_callbacks_.IsEmpty())
return -1;
CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator(
&pending_callbacks_);
return iterator.GetCurrentKey();
}
} // namespace content } // namespace content
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <utility> #include <utility>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/containers/id_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h" #include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h"
...@@ -63,14 +62,8 @@ class CONTENT_EXPORT ScreenOrientationDispatcher ...@@ -63,14 +62,8 @@ class CONTENT_EXPORT ScreenOrientationDispatcher
screen_orientation_ = std::move(screen_orientation_for_tests); screen_orientation_ = std::move(screen_orientation_for_tests);
} }
// The pending_callbacks_ map is mostly meant to have a unique ID to associate std::unique_ptr<blink::WebLockOrientationCallback> pending_callback_;
// with every callback going trough the dispatcher. The map will own the int request_id_ = 0;
// pointer in the sense that it will destroy it when Remove() will be called.
// Furthermore, we only expect to have one callback at a time in this map,
// which is what IDMap was designed for.
using CallbackMap =
base::IDMap<std::unique_ptr<blink::WebLockOrientationCallback>>;
CallbackMap pending_callbacks_;
ScreenOrientationAssociatedPtr screen_orientation_; ScreenOrientationAssociatedPtr screen_orientation_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment