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

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

Issue 410173002: Make ScreenOrientationProvider (Java) a bag of static methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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_android .h" 5 #include "content/browser/screen_orientation/screen_orientation_provider_android .h"
6 6
7 #include "content/browser/android/content_view_core_impl.h" 7 #include "content/browser/android/content_view_core_impl.h"
8 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" 8 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. 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/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (lock_orientation == blink::WebScreenOrientationLockNatural) { 62 if (lock_orientation == blink::WebScreenOrientationLockNatural) {
63 lock_orientation = GetNaturalLockType(); 63 lock_orientation = GetNaturalLockType();
64 if (lock_orientation == blink::WebScreenOrientationLockDefault) { 64 if (lock_orientation == blink::WebScreenOrientationLockDefault) {
65 // We are in a broken state, let's pretend we got canceled. 65 // We are in a broken state, let's pretend we got canceled.
66 dispatcher_->NotifyLockError(request_id, 66 dispatcher_->NotifyLockError(request_id,
67 blink::WebLockOrientationErrorCanceled); 67 blink::WebLockOrientationErrorCanceled);
68 return; 68 return;
69 } 69 }
70 } 70 }
71 71
72 if (j_screen_orientation_provider_.is_null()) {
73 j_screen_orientation_provider_.Reset(Java_ScreenOrientationProvider_create(
74 base::android::AttachCurrentThread()));
75 }
76
77 lock_applied_ = true; 72 lock_applied_ = true;
78 Java_ScreenOrientationProvider_lockOrientation( 73 Java_ScreenOrientationProvider_lockOrientation(
79 base::android::AttachCurrentThread(), 74 base::android::AttachCurrentThread(), lock_orientation);
80 j_screen_orientation_provider_.obj(), lock_orientation);
81 75
82 // If two calls happen close to each other, Android will ignore the first. 76 // If two calls happen close to each other, Android will ignore the first.
83 if (pending_lock_) { 77 if (pending_lock_) {
84 delete pending_lock_; 78 delete pending_lock_;
85 pending_lock_ = NULL; 79 pending_lock_ = NULL;
86 } 80 }
87 81
88 // If the orientation we are locking to matches the current orientation, we 82 // If the orientation we are locking to matches the current orientation, we
89 // should succeed immediately. 83 // should succeed immediately.
90 if (LockMatchesCurrentOrientation(lock_orientation)) { 84 if (LockMatchesCurrentOrientation(lock_orientation)) {
91 dispatcher_->NotifyLockSuccess(request_id); 85 dispatcher_->NotifyLockSuccess(request_id);
92 return; 86 return;
93 } 87 }
94 88
95 pending_lock_ = new LockInformation(request_id, lock_orientation); 89 pending_lock_ = new LockInformation(request_id, lock_orientation);
96 } 90 }
97 91
98 void ScreenOrientationProviderAndroid::UnlockOrientation() { 92 void ScreenOrientationProviderAndroid::UnlockOrientation() {
99 if (!lock_applied_) 93 if (!lock_applied_)
100 return; 94 return;
101 95
102 // j_screen_orientation_provider_ was set when locking so it can't be null.
103 DCHECK(!j_screen_orientation_provider_.is_null());
104
105 Java_ScreenOrientationProvider_unlockOrientation( 96 Java_ScreenOrientationProvider_unlockOrientation(
106 base::android::AttachCurrentThread(), 97 base::android::AttachCurrentThread());
107 j_screen_orientation_provider_.obj());
108 lock_applied_ = false; 98 lock_applied_ = false;
109 } 99 }
110 100
111 void ScreenOrientationProviderAndroid::OnOrientationChange() { 101 void ScreenOrientationProviderAndroid::OnOrientationChange() {
112 if (!pending_lock_) 102 if (!pending_lock_)
113 return; 103 return;
114 104
115 if (LockMatchesCurrentOrientation(pending_lock_->lock)) { 105 if (LockMatchesCurrentOrientation(pending_lock_->lock)) {
116 dispatcher_->NotifyLockSuccess(pending_lock_->request_id); 106 dispatcher_->NotifyLockSuccess(pending_lock_->request_id);
117 delete pending_lock_; 107 delete pending_lock_;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 203 }
214 204
215 // static 205 // static
216 ScreenOrientationProvider* ScreenOrientationProvider::Create( 206 ScreenOrientationProvider* ScreenOrientationProvider::Create(
217 ScreenOrientationDispatcherHost* dispatcher, 207 ScreenOrientationDispatcherHost* dispatcher,
218 WebContents* web_contents) { 208 WebContents* web_contents) {
219 return new ScreenOrientationProviderAndroid(dispatcher, web_contents); 209 return new ScreenOrientationProviderAndroid(dispatcher, web_contents);
220 } 210 }
221 211
222 } // namespace content 212 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698