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

Unified Diff: content/renderer/screen_orientation/screen_orientation_dispatcher.cc

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Codereview update Created 4 years, 2 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
Index: content/renderer/screen_orientation/screen_orientation_dispatcher.cc
diff --git a/content/renderer/screen_orientation/screen_orientation_dispatcher.cc b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
index 5f2071d377945cab190ed1bfd71ddf2da976e616..adf830bf159440acfa32c1c24cb188571ff37ac4 100644
--- a/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
+++ b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
@@ -2,55 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "content/public/common/associated_interface_provider.h"
+#include "content/public/renderer/render_frame.h"
#include "content/renderer/screen_orientation/screen_orientation_dispatcher.h"
-#include "content/common/screen_orientation_messages.h"
-
namespace content {
+using ::blink::mojom::ScreenOrientationLockResult;
+
ScreenOrientationDispatcher::ScreenOrientationDispatcher(
RenderFrame* render_frame)
- : RenderFrameObserver(render_frame) {
-}
+ : render_frame_(render_frame) {}
ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
}
-bool ScreenOrientationDispatcher::OnMessageReceived(
- const IPC::Message& message) {
- bool handled = true;
-
- IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcher, message)
- IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockSuccess,
- OnLockSuccess)
- IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockError,
- OnLockError)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
-
- return handled;
-}
-
-void ScreenOrientationDispatcher::OnDestruct() {
- delete this;
blundell 2016/10/25 16:09:27 i guess this is why you had to add the code in Ren
lunalu1 2016/11/03 23:15:26 my bad.
-}
-
-void ScreenOrientationDispatcher::OnLockSuccess(int request_id) {
+void ScreenOrientationDispatcher::OnLockOrientationResult(
+ int request_id,
+ ScreenOrientationLockResult result) {
blink::WebLockOrientationCallback* callback =
pending_callbacks_.Lookup(request_id);
if (!callback)
return;
- callback->onSuccess();
- pending_callbacks_.Remove(request_id);
-}
-void ScreenOrientationDispatcher::OnLockError(
- int request_id, blink::WebLockOrientationError error) {
- blink::WebLockOrientationCallback* callback =
- pending_callbacks_.Lookup(request_id);
- if (!callback)
- return;
- callback->onError(error);
+ switch (result) {
+ case ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS:
+ callback->onSuccess();
+ break;
+ case ScreenOrientationLockResult::
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE:
+ callback->onError(blink::WebLockOrientationErrorNotAvailable);
+ break;
+ case ScreenOrientationLockResult::
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED:
+ callback->onError(blink::WebLockOrientationErrorFullscreenRequired);
+ break;
+ case ScreenOrientationLockResult::
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED:
+ callback->onError(blink::WebLockOrientationErrorCanceled);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+
pending_callbacks_.Remove(request_id);
}
@@ -68,13 +63,31 @@ void ScreenOrientationDispatcher::lockOrientation(
CancelPendingLocks();
int request_id = pending_callbacks_.Add(callback);
- Send(new ScreenOrientationHostMsg_LockRequest(
- routing_id(), orientation, request_id));
+ setScreenOrientationInterface();
+ screen_orientation_->LockOrientation(
+ orientation,
+ base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult,
+ base::Unretained(this), request_id));
}
void ScreenOrientationDispatcher::unlockOrientation() {
CancelPendingLocks();
- Send(new ScreenOrientationHostMsg_Unlock(routing_id()));
+ setScreenOrientationInterface();
+ screen_orientation_->UnlockOrientation();
+}
+
+void ScreenOrientationDispatcher::setScreenOrientationInterface() {
blundell 2016/10/25 16:09:27 nit: this should be Set... (and similar for Get...
lunalu1 2016/11/03 23:15:26 Done.
+ if (!screen_orientation_)
+ render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(
+ &screen_orientation_);
+}
+
+int ScreenOrientationDispatcher::getRequestIdForTests() {
+ if (pending_callbacks_.IsEmpty())
+ return -1;
+ CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator(
+ &pending_callbacks_);
+ return iterator.GetCurrentKey();
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698