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

Unified Diff: services/device/screen_orientation/screen_orientation_listener_android.cc

Issue 2745443002: [Device Service] Port ScreenOrientationListener into Device Service. (Closed)
Patch Set: Add DEPS Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: services/device/screen_orientation/screen_orientation_listener_android.cc
diff --git a/services/device/screen_orientation/screen_orientation_listener_android.cc b/services/device/screen_orientation/screen_orientation_listener_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0c863d8b699f0e0646ba57f02e85e916fc5774f3
--- /dev/null
+++ b/services/device/screen_orientation/screen_orientation_listener_android.cc
@@ -0,0 +1,58 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/device/screen_orientation/screen_orientation_listener_android.h"
+
+#include "base/android/jni_android.h"
+#include "base/message_loop/message_loop.h"
+#include "jni/ScreenOrientationListener_jni.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+
+namespace device {
+
+// static
+void ScreenOrientationListenerAndroid::Create(
+ mojom::ScreenOrientationListenerRequest request) {
+ mojo::MakeStrongBinding(
leonhsl(Using Gerrit) 2017/03/09 08:22:31 ScreenOrientationListenerAndroid lives on IO threa
+ base::WrapUnique(new ScreenOrientationListenerAndroid()),
+ std::move(request));
+}
+
+ScreenOrientationListenerAndroid::ScreenOrientationListenerAndroid()
+ : listeners_count_(0) {}
+
+ScreenOrientationListenerAndroid::~ScreenOrientationListenerAndroid() {
+ DCHECK(base::MessageLoopForIO::IsCurrent());
+ if (listeners_count_ > 0) {
+ Java_ScreenOrientationListener_startAccurateListening(
+ base::android::AttachCurrentThread());
+ }
+}
+
+void ScreenOrientationListenerAndroid::Start() {
+ DCHECK(base::MessageLoopForIO::IsCurrent());
+ ++listeners_count_;
+ if (listeners_count_ == 1) {
+ // Ask the ScreenOrientationListener (Java) to start accurately listening to
+ // the screen orientation. It keep track of the number of start request if
+ // it is already running an accurate listening.
+ Java_ScreenOrientationListener_startAccurateListening(
+ base::android::AttachCurrentThread());
+ }
+}
+
+void ScreenOrientationListenerAndroid::Stop() {
+ DCHECK(base::MessageLoopForIO::IsCurrent());
+ DCHECK(listeners_count_ > 0);
+ --listeners_count_;
+ if (listeners_count_ == 0) {
+ // Ask the ScreenOrientationListener (Java) to stop accurately listening to
+ // the screen orientation. It will actually stop only if the number of stop
+ // requests matches the number of start requests.
+ Java_ScreenOrientationListener_stopAccurateListening(
+ base::android::AttachCurrentThread());
+ }
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698