Index: chrome/browser/chromeos/dbus/sensors_client.cc |
diff --git a/chrome/browser/chromeos/dbus/sensors_client.cc b/chrome/browser/chromeos/dbus/sensors_client.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d6b073c7bf1ae54782671c51a2103f0019166c4a |
--- /dev/null |
+++ b/chrome/browser/chromeos/dbus/sensors_client.cc |
@@ -0,0 +1,99 @@ |
+// 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/dbus/sensors_client.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "chrome/browser/chromeos/system/runtime_environment.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"; |
+ |
+// The SensorsClient implementation used in production. |
+class SensorsClientImpl : public SensorsClient { |
+ public: |
+ explicit SensorsClientImpl(dbus::Bus* bus) |
+ : sensors_proxy_(NULL), |
+ weak_ptr_factory_(this) { |
+ sensors_proxy_ = bus->GetObjectProxy(chromeos::kSensorsServiceName, |
+ chromeos::kSensorsServicePath); |
+ sensors_proxy_->ConnectToSignal( |
+ chromeos::kSensorsServiceInterface, |
+ chromeos::kScreenOrientationChanged, |
+ base::Bind(&SensorsClientImpl::OrientationChangedReceived, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::Bind(&SensorsClientImpl::OrientationChangedConnected, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ } |
+ |
+ virtual ~SensorsClientImpl() { |
+ } |
+ |
+ private: |
+ void OrientationChangedReceived(dbus::Signal* signal) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ sensors::ScreenOrientation orientation; |
+ |
+ dbus::MessageReader reader(signal); |
+ int32 upward = 0; |
+ if (!reader.PopInt32(&upward)) { |
+ LOG(WARNING) << "Orientation changed signal had incorrect parameters: " |
+ << signal->ToString(); |
+ return; |
+ } |
+ VLOG(1) << "Orientation changed to upward " << upward; |
+ orientation.upward = static_cast<sensors::ScreenOrientation::Side>(upward); |
+ |
+ sensors::Provider::GetInstance()->ScreenOrientationChanged(orientation); |
+ } |
+ |
+ void 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."; |
+ } |
+ |
+ dbus::ObjectProxy* sensors_proxy_; |
+ base::WeakPtrFactory<SensorsClientImpl> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SensorsClientImpl); |
+}; |
+ |
+// The SensorsClient implementation used on Linux desktop, |
+// which does nothing. |
+class SensorsClientStubImpl : public SensorsClient { |
+}; |
+ |
+SensorsClient::SensorsClient() { |
+} |
+ |
+SensorsClient::~SensorsClient() { |
+} |
+ |
+SensorsClient* SensorsClient::Create(dbus::Bus* bus) { |
+ if (system::runtime_environment::IsRunningOnChromeOS()) { |
+ return new SensorsClientImpl(bus); |
+ } else { |
+ return new SensorsClientStubImpl(); |
+ } |
+} |
+ |
+} // namespace chromeos |