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

Unified Diff: chrome/browser/chromeos/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: Move sensors source to chrome/browser/chromeos and update DEPS. 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: chrome/browser/chromeos/sensors_source_chromeos.cc
diff --git a/chrome/browser/chromeos/sensors_source_chromeos.cc b/chrome/browser/chromeos/sensors_source_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..233511afd4a51f32d2394bd9526bd0f94385c7c2
--- /dev/null
+++ b/chrome/browser/chromeos/sensors_source_chromeos.cc
@@ -0,0 +1,88 @@
+// 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 "chrome/browser/chromeos/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"
+
+// TODO(cwolfe): Fix the DEPs so that these can be pulled in from
+// "chromeos/dbus/service_constants.h".
+namespace chromeos {
+// Sensors service identifiers.
+const char kSensorsServiceName[] = "org.chromium.Sensors";
+const char kSensorsServicePath[] = "/org/chromium/Sensors";
+const char kSensorsServiceInterface[] = "org.chromium.Sensors";
+// Sensors signal names.
+const char kScreenOrientationChanged[] = "ScreenOrientationChanged";
+} // namespace chromeos
+
+namespace sensors {
+
+SensorsSourceChromeos::SensorsSourceChromeos() : sensors_proxy_(NULL) {
+}
+
+bool SensorsSourceChromeos::Init() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE));
+
+ 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::FILE);
+ bus_ = new dbus::Bus(options);
+
+ sensors_proxy_ = bus_->GetObjectProxy(chromeos::kSensorsServiceName,
+ chromeos::kSensorsServicePath);
+ sensors_proxy_->ConnectToSignal(chromeos::kSensorsServiceInterface,
+ chromeos::kScreenOrientationChanged,
+ base::Bind(&SensorsSourceChromeos::OrientationChangedReceived, this),
+ base::Bind(&SensorsSourceChromeos::OrientationChangedConnected, this));
+ return true;
+}
+
+void SensorsSourceChromeos::Stop() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (bus_)
+ bus_->ShutdownOnDBusThreadAndBlock();
+}
+
+SensorsSourceChromeos::~SensorsSourceChromeos() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ Stop();
+}
+
+void SensorsSourceChromeos::OrientationChangedReceived(dbus::Signal* signal) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ ScreenOrientation orientation;
+
+ dbus::MessageReader reader(signal);
+ int32 upward = 0;
+ if (!reader.PopInt32(&upward)) {
+ LOG(WARNING) << "Orientation changed signal had incorrect parameters: "
+ << signal->ToString();
+ return;
+ }
+ orientation.upward = static_cast<ScreenOrientation::Side>(upward);
+
+ Provider::GetInstance()->ScreenOrientationChanged(orientation);
+}
+
+void SensorsSourceChromeos::OrientationChangedConnected(
+ const std::string& interface_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