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

Side by Side Diff: content/browser/screen_orientation/screen_orientation_provider.cc

Issue 2688383002: [ScreenOrientation] Merge mojo interface ScreenOrientationListener into ScreenOrientation
Patch Set: Created 3 years, 10 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
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/browser/screen_orientation/screen_orientation_provider.h" 5 #include "content/browser/screen_orientation/screen_orientation_provider.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/navigation_handle.h" 10 #include "content/public/browser/navigation_handle.h"
11 #include "content/public/browser/render_widget_host.h" 11 #include "content/public/browser/render_widget_host.h"
12 #include "content/public/browser/screen_orientation_delegate.h" 12 #include "content/public/browser/screen_orientation_delegate.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationError.h" 14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationError.h"
15 15
16 #if defined(OS_ANDROID)
17 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h"
18 #endif
19
16 namespace content { 20 namespace content {
17 21
18 using device::mojom::ScreenOrientationLockResult; 22 using device::mojom::ScreenOrientationLockResult;
19 23
20 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; 24 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr;
21 25
22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) 26 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents)
23 : WebContentsObserver(web_contents), 27 : WebContentsObserver(web_contents),
24 lock_applied_(false), 28 lock_applied_(false),
25 bindings_(web_contents, this) {} 29 bindings_(web_contents, this) {}
26 30
27 ScreenOrientationProvider::~ScreenOrientationProvider() = default; 31 ScreenOrientationProvider::~ScreenOrientationProvider() {
32 #if defined(OS_ANDROID)
33 if (accurate_listen_count_ > 0) {
34 ScreenOrientationDelegateAndroid::StopAccurateListening();
35 }
mlamouri (slow - plz ping) 2017/02/15 10:58:41 style: no { }
leonhsl(Using Gerrit) 2017/02/16 05:00:05 Done.
36 #endif
37 }
28 38
29 void ScreenOrientationProvider::LockOrientation( 39 void ScreenOrientationProvider::LockOrientation(
30 blink::WebScreenOrientationLockType orientation, 40 blink::WebScreenOrientationLockType orientation,
31 const LockOrientationCallback& callback) { 41 const LockOrientationCallback& callback) {
32 // Cancel any pending lock request. 42 // Cancel any pending lock request.
33 NotifyLockResult(ScreenOrientationLockResult:: 43 NotifyLockResult(ScreenOrientationLockResult::
34 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); 44 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
35 // Record new pending lock request. 45 // Record new pending lock request.
36 pending_callback_ = callback; 46 pending_callback_ = callback;
37 47
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); 98 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
89 99
90 if (!lock_applied_ || !delegate_) 100 if (!lock_applied_ || !delegate_)
91 return; 101 return;
92 102
93 delegate_->Unlock(web_contents()); 103 delegate_->Unlock(web_contents());
94 104
95 lock_applied_ = false; 105 lock_applied_ = false;
96 } 106 }
97 107
108 void ScreenOrientationProvider::StartAccurateListen() {
109 #if defined(OS_ANDROID)
110 ++accurate_listen_count_;
111 if (accurate_listen_count_ == 1)
112 ScreenOrientationDelegateAndroid::StartAccurateListening();
113 #endif
114 }
115
116 void ScreenOrientationProvider::StopAccurateListen() {
117 #if defined(OS_ANDROID)
118 DCHECK(accurate_listen_count_ > 0);
119 --accurate_listen_count_;
120 if (accurate_listen_count_ == 0)
121 ScreenOrientationDelegateAndroid::StopAccurateListening();
122 #endif
123 }
124
98 void ScreenOrientationProvider::OnOrientationChange() { 125 void ScreenOrientationProvider::OnOrientationChange() {
99 if (!pending_lock_orientation_.has_value()) 126 if (!pending_lock_orientation_.has_value())
100 return; 127 return;
101 128
102 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { 129 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) {
103 DCHECK(!pending_callback_.is_null()); 130 DCHECK(!pending_callback_.is_null());
104 NotifyLockResult( 131 NotifyLockResult(
105 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); 132 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS);
106 } 133 }
107 } 134 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 case blink::WebScreenOrientationLockDefault: 240 case blink::WebScreenOrientationLockDefault:
214 NOTREACHED(); 241 NOTREACHED();
215 return false; 242 return false;
216 } 243 }
217 244
218 NOTREACHED(); 245 NOTREACHED();
219 return false; 246 return false;
220 } 247 }
221 248
222 } // namespace content 249 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698