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

Unified Diff: content/browser/sensors/sensors_source_chromeos.cc

Issue 7862020: chromeos: Add operations to monitor the screen orientation. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Juggle some code to content and general cleanup. Created 9 years, 3 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: content/browser/sensors/sensors_source_chromeos.cc
diff --git a/content/browser/sensors/sensors_source_chromeos.cc b/content/browser/sensors/sensors_source_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..991054df3caadda121db80ee7db5188a3ea1702d
--- /dev/null
+++ b/content/browser/sensors/sensors_source_chromeos.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 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 "content/browser/sensors/sensors_source_chromeos.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "content/browser/browser_thread.h"
+#include "content/browser/sensors/sensors_provider.h"
+#include "dbus/bus.h"
+#include "dbus/message.h"
+#include "dbus/object_proxy.h"
+
+static const char kSensorsServiceName[] = "org.chromium.Sensors";
satorux1 2011/09/12 19:46:38 D-Bus constants should be defined in system_api.gi
tfarina 2011/09/12 20:07:12 static is not necessary here. const has implicit i
cwolfe 2011/09/12 21:17:36 Forgot about system_api. Unfortunately that would
+static const char kSensorsPath[] = "/";
satorux1 2011/09/12 19:46:38 Using "/" as object path is not correct: crosbug.
cwolfe 2011/09/12 21:17:36 Done.
satorux1 2011/09/12 21:55:14 I take it back. You should keep it as "/" for now,
+static const char kSensorsInterface[] = "org.chromium.Sensors";
+static const char kSensorsOrientationChanged[] = "ScreenOrientationChanged";
+
+namespace sensors {
+
+SensorsSourceChromeos::SensorsSourceChromeos() : sensors_proxy_(NULL) {
+}
+
+bool SensorsSourceChromeos::Init() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
+
+ dbus::Bus::Options options;
+ options.bus_type = dbus::Bus::SYSTEM;
+ options.connection_type = dbus::Bus::PRIVATE;
+ options.dbus_thread_message_loop_proxy =
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
+ bus_ = new dbus::Bus(options);
+
+ sensors_proxy_ = bus_->GetObjectProxy(kSensorsServiceName, kSensorsPath);
+ sensors_proxy_->ConnectToSignal(kSensorsInterface, kSensorsOrientationChanged,
+ base::Bind(&SensorsSourceChromeos::OrientationChangedReceived, this),
+ base::Bind(&SensorsSourceChromeos::OrientationChangedConnected, this));
+ return true;
+}
+
+void SensorsSourceChromeos::Stop() {
satorux1 2011/09/12 19:46:38 You might want to add DCHECK(BrowserThread::Curre
cwolfe 2011/09/12 21:17:36 Done. Come to think of it, isn't there a which-th
+ if (bus_)
+ bus_->ShutdownAndBlock();
satorux1 2011/09/12 19:46:38 Shutdown is a bit tricky. Since you are using the
cwolfe 2011/09/12 21:17:36 Done.
+}
+
+SensorsSourceChromeos::~SensorsSourceChromeos() {
+ Stop();
+}
+
+void SensorsSourceChromeos::OrientationChangedReceived(dbus::Signal* signal) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ ScreenOrientation orientation;
+
+ dbus::MessageReader reader(signal);
+ int32 upward;
satorux1 2011/09/12 19:46:38 initialize with 0? Uninitialized variable can be l
cwolfe 2011/09/12 21:17:36 Done.
+ if (!reader.PopInt32(&upward)) {
+ LOG(WARNING) << "Orientation changed signal had incorrect parameters.";
satorux1 2011/09/12 19:46:38 Let's add << signal->ToString() in the warning. Th
cwolfe 2011/09/12 21:17:36 Done.
+ return;
+ }
+ orientation.upward = static_cast<ScreenOrientation::Side>(upward);
+
+ Provider::GetInstance()->ScreenOrientationChanged(orientation);
+}
+
+void SensorsSourceChromeos::OrientationChangedConnected(
+ const std::string& iface_name,
+ const std::string& signal_name,
+ bool success) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!success)
+ LOG(WARNING) << "Failed to connect to orientation changed signal.";
+}
+
+} // namespace sensors

Powered by Google App Engine
This is Rietveld 408576698