| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 std::unique_ptr<blink::WebLockOrientationCallback> callback) { | 68 std::unique_ptr<blink::WebLockOrientationCallback> callback) { |
| 69 CancelPendingLocks(); | 69 CancelPendingLocks(); |
| 70 | 70 |
| 71 int request_id = pending_callbacks_.Add(std::move(callback)); | 71 int request_id = pending_callbacks_.Add(std::move(callback)); |
| 72 EnsureScreenOrientationService(); | 72 GetRemoteScreenOrientation()->LockOrientation( |
| 73 screen_orientation_->LockOrientation( | |
| 74 orientation, | 73 orientation, |
| 75 base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult, | 74 base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult, |
| 76 base::Unretained(this), request_id)); | 75 base::Unretained(this), request_id)); |
| 77 } | 76 } |
| 78 | 77 |
| 79 void ScreenOrientationDispatcher::unlockOrientation() { | 78 void ScreenOrientationDispatcher::unlockOrientation() { |
| 80 CancelPendingLocks(); | 79 CancelPendingLocks(); |
| 81 EnsureScreenOrientationService(); | 80 GetRemoteScreenOrientation()->UnlockOrientation(); |
| 82 screen_orientation_->UnlockOrientation(); | |
| 83 } | 81 } |
| 84 | 82 |
| 85 void ScreenOrientationDispatcher::EnsureScreenOrientationService() { | 83 void ScreenOrientationDispatcher::startAccurateListen() { |
| 84 GetRemoteScreenOrientation()->StartAccurateListen(); |
| 85 } |
| 86 |
| 87 void ScreenOrientationDispatcher::stopAccurateListen() { |
| 88 GetRemoteScreenOrientation()->StopAccurateListen(); |
| 89 } |
| 90 |
| 91 device::mojom::ScreenOrientation* |
| 92 ScreenOrientationDispatcher::GetRemoteScreenOrientation() { |
| 86 if (!screen_orientation_) { | 93 if (!screen_orientation_) { |
| 87 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( | 94 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( |
| 88 &screen_orientation_); | 95 &screen_orientation_); |
| 89 } | 96 } |
| 97 |
| 98 return screen_orientation_.get(); |
| 90 } | 99 } |
| 91 | 100 |
| 92 int ScreenOrientationDispatcher::GetRequestIdForTests() { | 101 int ScreenOrientationDispatcher::GetRequestIdForTests() { |
| 93 if (pending_callbacks_.IsEmpty()) | 102 if (pending_callbacks_.IsEmpty()) |
| 94 return -1; | 103 return -1; |
| 95 CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator( | 104 CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator( |
| 96 &pending_callbacks_); | 105 &pending_callbacks_); |
| 97 return iterator.GetCurrentKey(); | 106 return iterator.GetCurrentKey(); |
| 98 } | 107 } |
| 99 | 108 |
| 100 } // namespace content | 109 } // namespace content |
| OLD | NEW |