| 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/public/common/associated_interface_provider.h" | 7 #include "content/public/common/associated_interface_provider.h" |
| 8 #include "content/public/renderer/render_frame.h" | 8 #include "content/public/renderer/render_frame.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 void ScreenOrientationDispatcher::CancelPendingLocks() { | 58 void ScreenOrientationDispatcher::CancelPendingLocks() { |
| 59 for (CallbackMap::Iterator<blink::WebLockOrientationCallback> | 59 for (CallbackMap::Iterator<blink::WebLockOrientationCallback> |
| 60 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { | 60 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { |
| 61 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled); | 61 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled); |
| 62 pending_callbacks_.Remove(iterator.GetCurrentKey()); | 62 pending_callbacks_.Remove(iterator.GetCurrentKey()); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ScreenOrientationDispatcher::lockOrientation( | 66 void ScreenOrientationDispatcher::lockOrientation( |
| 67 blink::WebScreenOrientationLockType orientation, | 67 blink::WebScreenOrientationLockType orientation, |
| 68 blink::WebLockOrientationCallback* callback) { | 68 std::unique_ptr<blink::WebLockOrientationCallback> callback) { |
| 69 CancelPendingLocks(); | 69 CancelPendingLocks(); |
| 70 | 70 |
| 71 int request_id = pending_callbacks_.Add(callback); | 71 int request_id = pending_callbacks_.Add(std::move(callback)); |
| 72 EnsureScreenOrientationService(); | 72 EnsureScreenOrientationService(); |
| 73 screen_orientation_->LockOrientation( | 73 screen_orientation_->LockOrientation( |
| 74 orientation, | 74 orientation, |
| 75 base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult, | 75 base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult, |
| 76 base::Unretained(this), request_id)); | 76 base::Unretained(this), request_id)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ScreenOrientationDispatcher::unlockOrientation() { | 79 void ScreenOrientationDispatcher::unlockOrientation() { |
| 80 CancelPendingLocks(); | 80 CancelPendingLocks(); |
| 81 EnsureScreenOrientationService(); | 81 EnsureScreenOrientationService(); |
| 82 screen_orientation_->UnlockOrientation(); | 82 screen_orientation_->UnlockOrientation(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void ScreenOrientationDispatcher::EnsureScreenOrientationService() { | 85 void ScreenOrientationDispatcher::EnsureScreenOrientationService() { |
| 86 if (!screen_orientation_) { | 86 if (!screen_orientation_) { |
| 87 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( | 87 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( |
| 88 &screen_orientation_); | 88 &screen_orientation_); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 int ScreenOrientationDispatcher::GetRequestIdForTests() { | 92 int ScreenOrientationDispatcher::GetRequestIdForTests() { |
| 93 if (pending_callbacks_.IsEmpty()) | 93 if (pending_callbacks_.IsEmpty()) |
| 94 return -1; | 94 return -1; |
| 95 CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator( | 95 CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator( |
| 96 &pending_callbacks_); | 96 &pending_callbacks_); |
| 97 return iterator.GetCurrentKey(); | 97 return iterator.GetCurrentKey(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace content | 100 } // namespace content |
| OLD | NEW |