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

Side by Side Diff: content/renderer/screen_orientation/screen_orientation_dispatcher.h

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: clup Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ 5 #ifndef CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_
6 #define CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ 6 #define CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/id_map.h" 9 #include "base/id_map.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "content/common/screen_orientation.mojom.h"
11 #include "content/public/renderer/render_frame_observer.h" 12 #include "content/public/renderer/render_frame_observer.h"
12 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationCallback.h" 13 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationCallback.h"
13 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationClient.h" 14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationClient.h"
14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 15 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
15 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationType.h" 16 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationType.h"
16 17
17 namespace content { 18 namespace content {
18 19
20 using mojom::ScreenOrientationAssociatedPtr;
21 using ::blink::mojom::ScreenOrientationLockResult;
22
19 class RenderFrame; 23 class RenderFrame;
20 24
21 // ScreenOrientationDispatcher implements the WebScreenOrientationClient API 25 // ScreenOrientationDispatcher implements the WebScreenOrientationClient API
22 // which handles screen lock. It sends lock (or unlock) requests to the browser 26 // which handles screen lock. It sends lock (or unlock) requests to the browser
23 // process and listens for responses and let Blink know about the result of the 27 // process and listens for responses and let Blink know about the result of the
24 // request via WebLockOrientationCallback. 28 // request via WebLockOrientationCallback.
25 class CONTENT_EXPORT ScreenOrientationDispatcher : 29 class CONTENT_EXPORT ScreenOrientationDispatcher :
26 public RenderFrameObserver, 30 public RenderFrameObserver,
27 NON_EXPORTED_BASE(public blink::WebScreenOrientationClient) { 31 NON_EXPORTED_BASE(public blink::WebScreenOrientationClient) {
28 public: 32 public:
29 explicit ScreenOrientationDispatcher(RenderFrame* render_frame); 33 explicit ScreenOrientationDispatcher(RenderFrame* render_frame);
30 ~ScreenOrientationDispatcher() override; 34 ~ScreenOrientationDispatcher() override;
31 35
32 private: 36 private:
33 friend class ScreenOrientationDispatcherTest; 37 friend class ScreenOrientationDispatcherTest;
34 38
35 // RenderFrameObserver implementation. 39 // RenderFrameObserver implementation.
36 bool OnMessageReceived(const IPC::Message& message) override;
37 void OnDestruct() override; 40 void OnDestruct() override;
38 41
39 // blink::WebScreenOrientationClient implementation. 42 // blink::WebScreenOrientationClient implementation.
40 void lockOrientation(blink::WebScreenOrientationLockType orientation, 43 void lockOrientation(blink::WebScreenOrientationLockType orientation,
41 blink::WebLockOrientationCallback* callback) override; 44 blink::WebLockOrientationCallback* callback) override;
42 void unlockOrientation() override; 45 void unlockOrientation() override;
43 46
44 void OnLockSuccess(int request_id); 47 void OnLockOrientationResult(int request_id,
45 void OnLockError(int request_id, 48 ScreenOrientationLockResult result);
46 blink::WebLockOrientationError error);
47 49
48 void CancelPendingLocks(); 50 void CancelPendingLocks();
49 51
52 int GetRequestIdForTests();
53
54 void EnsureScreenOrientationService();
55
56 // This should only be called by ScreenOrientationDispatcherTest
57 void SetScreenOrientationForTests(
58 ScreenOrientationAssociatedPtr& screen_orientation_for_tests) {
59 screen_orientation_ = std::move(screen_orientation_for_tests);
60 }
61
50 // The pending_callbacks_ map is mostly meant to have a unique ID to associate 62 // The pending_callbacks_ map is mostly meant to have a unique ID to associate
51 // with every callback going trough the dispatcher. The map will own the 63 // with every callback going trough the dispatcher. The map will own the
52 // pointer in the sense that it will destroy it when Remove() will be called. 64 // pointer in the sense that it will destroy it when Remove() will be called.
53 // Furthermore, we only expect to have one callback at a time in this map, 65 // Furthermore, we only expect to have one callback at a time in this map,
54 // which is what IDMap was designed for. 66 // which is what IDMap was designed for.
55 typedef IDMap<blink::WebLockOrientationCallback, IDMapOwnPointer> CallbackMap; 67 typedef IDMap<blink::WebLockOrientationCallback, IDMapOwnPointer> CallbackMap;
56 CallbackMap pending_callbacks_; 68 CallbackMap pending_callbacks_;
57 69
70 ScreenOrientationAssociatedPtr screen_orientation_;
71
58 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcher); 72 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcher);
59 }; 73 };
60 74
61 } // namespace content 75 } // namespace content
62 76
63 #endif // CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ 77 #endif // CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698