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

Side by Side Diff: content/renderer/screen_orientation/mock_screen_orientation_controller.cc

Issue 300063012: Make async methods UpdateLock() and ResetLock() in MockScreenOrientationController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated by comments Created 6 years, 6 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 unified diff | Download patch
« no previous file with comments | « content/renderer/screen_orientation/mock_screen_orientation_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "content/renderer/screen_orientation/mock_screen_orientation_controller .h" 5 #include "content/renderer/screen_orientation/mock_screen_orientation_controller .h"
6 6
7 #include "base/bind.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
8 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" 10 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h"
9 11
10 namespace content { 12 namespace content {
11 13
12 MockScreenOrientationController::MockScreenOrientationController() 14 MockScreenOrientationController::MockScreenOrientationController()
13 : current_lock_(blink::WebScreenOrientationLockDefault), 15 : current_lock_(blink::WebScreenOrientationLockDefault),
14 device_orientation_(blink::WebScreenOrientationPortraitPrimary), 16 device_orientation_(blink::WebScreenOrientationPortraitPrimary),
15 current_orientation_(blink::WebScreenOrientationPortraitPrimary), 17 current_orientation_(blink::WebScreenOrientationPortraitPrimary),
16 listener_(NULL) { 18 listener_(NULL) {
19 // Since MockScreenOrientationController is held by LazyInstance reference,
20 // add this ref for it.
21 AddRef();
22 }
23
24 MockScreenOrientationController::~MockScreenOrientationController() {
17 } 25 }
18 26
19 void MockScreenOrientationController::SetListener( 27 void MockScreenOrientationController::SetListener(
20 blink::WebScreenOrientationListener* listener) { 28 blink::WebScreenOrientationListener* listener) {
21 listener_ = listener; 29 listener_ = listener;
22 } 30 }
23 31
24 void MockScreenOrientationController::ResetData() { 32 void MockScreenOrientationController::ResetData() {
25 current_lock_ = blink::WebScreenOrientationLockDefault; 33 current_lock_ = blink::WebScreenOrientationLockDefault;
26 device_orientation_ = blink::WebScreenOrientationPortraitPrimary; 34 device_orientation_ = blink::WebScreenOrientationPortraitPrimary;
27 current_orientation_ = blink::WebScreenOrientationPortraitPrimary; 35 current_orientation_ = blink::WebScreenOrientationPortraitPrimary;
28 } 36 }
29 37
30 void MockScreenOrientationController::UpdateLock( 38 void MockScreenOrientationController::UpdateLock(
31 blink::WebScreenOrientationLockType lock) { 39 blink::WebScreenOrientationLockType lock) {
40 base::MessageLoop::current()->PostTask(
41 FROM_HERE,
42 base::Bind(&MockScreenOrientationController::UpdateLockSync, this, lock));
43 }
44 void MockScreenOrientationController::UpdateLockSync(
45 blink::WebScreenOrientationLockType lock) {
32 DCHECK(lock != blink::WebScreenOrientationLockDefault); 46 DCHECK(lock != blink::WebScreenOrientationLockDefault);
33 current_lock_ = lock; 47 current_lock_ = lock;
34 if (!IsOrientationAllowedByCurrentLock(current_orientation_)) 48 if (!IsOrientationAllowedByCurrentLock(current_orientation_))
35 UpdateScreenOrientation(SuitableOrientationForCurrentLock()); 49 UpdateScreenOrientation(SuitableOrientationForCurrentLock());
36 } 50 }
37 51
38 void MockScreenOrientationController::ResetLock() { 52 void MockScreenOrientationController::ResetLock() {
53 base::MessageLoop::current()->PostTask(
54 FROM_HERE,
55 base::Bind(&MockScreenOrientationController::ResetLockSync, this));
56 }
57
58 void MockScreenOrientationController::ResetLockSync() {
39 bool will_screen_orientation_need_updating = 59 bool will_screen_orientation_need_updating =
40 !IsOrientationAllowedByCurrentLock(device_orientation_); 60 !IsOrientationAllowedByCurrentLock(device_orientation_);
41 current_lock_ = blink::WebScreenOrientationLockDefault; 61 current_lock_ = blink::WebScreenOrientationLockDefault;
42 if (will_screen_orientation_need_updating) 62 if (will_screen_orientation_need_updating)
43 UpdateScreenOrientation(device_orientation_); 63 UpdateScreenOrientation(device_orientation_);
44 } 64 }
45 65
46 void MockScreenOrientationController::UpdateDeviceOrientation( 66 void MockScreenOrientationController::UpdateDeviceOrientation(
47 blink::WebScreenOrientationType orientation) { 67 blink::WebScreenOrientationType orientation) {
48 if (device_orientation_ == orientation) 68 if (device_orientation_ == orientation)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 case blink::WebScreenOrientationLockLandscape: 118 case blink::WebScreenOrientationLockLandscape:
99 return blink::WebScreenOrientationLandscapePrimary; 119 return blink::WebScreenOrientationLandscapePrimary;
100 case blink::WebScreenOrientationLockLandscapeSecondary: 120 case blink::WebScreenOrientationLockLandscapeSecondary:
101 return blink::WebScreenOrientationLandscapePrimary; 121 return blink::WebScreenOrientationLandscapePrimary;
102 default: 122 default:
103 return blink::WebScreenOrientationPortraitPrimary; 123 return blink::WebScreenOrientationPortraitPrimary;
104 } 124 }
105 } 125 }
106 126
107 } // namespace content 127 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/screen_orientation/mock_screen_orientation_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698