OLD | NEW |
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/screen_orientation_dispatcher.h" | 5 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" |
6 | 6 |
7 #include "content/common/screen_orientation_messages.h" | 7 #include "content/common/screen_orientation_messages.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 blink::WebScreenOrientationType orientation) { | 37 blink::WebScreenOrientationType orientation) { |
38 blink::WebLockOrientationCallback* callback = | 38 blink::WebLockOrientationCallback* callback = |
39 pending_callbacks_.Lookup(request_id); | 39 pending_callbacks_.Lookup(request_id); |
40 if (!callback) | 40 if (!callback) |
41 return; | 41 return; |
42 callback->onSuccess(angle, orientation); | 42 callback->onSuccess(angle, orientation); |
43 pending_callbacks_.Remove(request_id); | 43 pending_callbacks_.Remove(request_id); |
44 } | 44 } |
45 | 45 |
46 void ScreenOrientationDispatcher::OnLockError( | 46 void ScreenOrientationDispatcher::OnLockError( |
47 int request_id, | 47 int request_id, blink::WebLockOrientationError error) { |
48 blink::WebLockOrientationCallback::ErrorType error) { | |
49 blink::WebLockOrientationCallback* callback = | 48 blink::WebLockOrientationCallback* callback = |
50 pending_callbacks_.Lookup(request_id); | 49 pending_callbacks_.Lookup(request_id); |
51 if (!callback) | 50 if (!callback) |
52 return; | 51 return; |
53 callback->onError(error); | 52 callback->onError(error); |
54 pending_callbacks_.Remove(request_id); | 53 pending_callbacks_.Remove(request_id); |
55 } | 54 } |
56 | 55 |
57 void ScreenOrientationDispatcher::CancelPendingLocks() { | 56 void ScreenOrientationDispatcher::CancelPendingLocks() { |
58 for (CallbackMap::Iterator<blink::WebLockOrientationCallback> | 57 for (CallbackMap::Iterator<blink::WebLockOrientationCallback> |
59 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { | 58 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { |
60 iterator.GetCurrentValue()->onError( | 59 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled); |
61 blink::WebLockOrientationCallback::ErrorTypeCanceled); | |
62 pending_callbacks_.Remove(iterator.GetCurrentKey()); | 60 pending_callbacks_.Remove(iterator.GetCurrentKey()); |
63 } | 61 } |
64 } | 62 } |
65 | 63 |
66 void ScreenOrientationDispatcher::lockOrientation( | 64 void ScreenOrientationDispatcher::lockOrientation( |
67 blink::WebScreenOrientationLockType orientation, | 65 blink::WebScreenOrientationLockType orientation, |
68 blink::WebLockOrientationCallback* callback) { | 66 blink::WebLockOrientationCallback* callback) { |
69 CancelPendingLocks(); | 67 CancelPendingLocks(); |
70 | 68 |
71 int request_id = pending_callbacks_.Add(callback); | 69 int request_id = pending_callbacks_.Add(callback); |
72 Send(new ScreenOrientationHostMsg_LockRequest( | 70 Send(new ScreenOrientationHostMsg_LockRequest( |
73 routing_id(), orientation, request_id)); | 71 routing_id(), orientation, request_id)); |
74 } | 72 } |
75 | 73 |
76 void ScreenOrientationDispatcher::unlockOrientation() { | 74 void ScreenOrientationDispatcher::unlockOrientation() { |
77 CancelPendingLocks(); | 75 CancelPendingLocks(); |
78 Send(new ScreenOrientationHostMsg_Unlock(routing_id())); | 76 Send(new ScreenOrientationHostMsg_Unlock(routing_id())); |
79 } | 77 } |
80 | 78 |
81 } // namespace content | 79 } // namespace content |
OLD | NEW |