Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/sensors/sensors_source_chromeos.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "content/browser/browser_thread.h" | |
| 10 #include "content/browser/sensors/sensors_provider.h" | |
| 11 #include "dbus/bus.h" | |
| 12 #include "dbus/message.h" | |
| 13 #include "dbus/object_proxy.h" | |
| 14 | |
|
cwolfe
2011/09/12 22:15:55
My test driver is actually using the dbus APIs, so
| |
| 15 // TODO(cwolfe): Fix the DEPs so that these can be pulled in from | |
| 16 // "chromeos/dbus/service_constants.h". | |
| 17 namespace chromeos { | |
| 18 // Sensors service identifiers. | |
| 19 const char kSensorsServiceName[] = "org.chromium.Sensors"; | |
| 20 const char kSensorsServicePath[] = "/org/chromium/Sensors"; | |
| 21 const char kSensorsServiceInterface[] = "org.chromium.Sensors"; | |
| 22 // Sensors signal names. | |
| 23 const char kScreenOrientationChanged[] = "ScreenOrientationChanged"; | |
| 24 } // namespace chromeos | |
| 25 | |
| 26 namespace sensors { | |
| 27 | |
| 28 SensorsSourceChromeos::SensorsSourceChromeos() : sensors_proxy_(NULL) { | |
| 29 } | |
| 30 | |
| 31 bool SensorsSourceChromeos::Init() { | |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 33 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); | |
| 34 | |
| 35 dbus::Bus::Options options; | |
| 36 options.bus_type = dbus::Bus::SYSTEM; | |
| 37 options.connection_type = dbus::Bus::PRIVATE; | |
| 38 options.dbus_thread_message_loop_proxy = | |
| 39 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | |
| 40 bus_ = new dbus::Bus(options); | |
| 41 | |
| 42 sensors_proxy_ = bus_->GetObjectProxy(chromeos::kSensorsServiceName, | |
| 43 chromeos::kSensorsServicePath); | |
| 44 sensors_proxy_->ConnectToSignal(chromeos::kSensorsServiceInterface, | |
| 45 chromeos::kScreenOrientationChanged, | |
| 46 base::Bind(&SensorsSourceChromeos::OrientationChangedReceived, this), | |
| 47 base::Bind(&SensorsSourceChromeos::OrientationChangedConnected, this)); | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 void SensorsSourceChromeos::Stop() { | |
| 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 53 if (bus_) | |
| 54 bus_->ShutdownOnDBusThreadAndBlock(); | |
| 55 } | |
| 56 | |
| 57 SensorsSourceChromeos::~SensorsSourceChromeos() { | |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 59 Stop(); | |
| 60 } | |
| 61 | |
| 62 void SensorsSourceChromeos::OrientationChangedReceived(dbus::Signal* signal) { | |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 64 | |
| 65 ScreenOrientation orientation; | |
| 66 | |
| 67 dbus::MessageReader reader(signal); | |
| 68 int32 upward = 0; | |
| 69 if (!reader.PopInt32(&upward)) { | |
| 70 LOG(WARNING) << "Orientation changed signal had incorrect parameters: " | |
| 71 << signal->ToString(); | |
| 72 return; | |
| 73 } | |
| 74 orientation.upward = static_cast<ScreenOrientation::Side>(upward); | |
| 75 | |
| 76 Provider::GetInstance()->ScreenOrientationChanged(orientation); | |
| 77 } | |
| 78 | |
| 79 void SensorsSourceChromeos::OrientationChangedConnected( | |
| 80 const std::string& interface_name, | |
| 81 const std::string& signal_name, | |
| 82 bool success) { | |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 84 if (!success) | |
| 85 LOG(WARNING) << "Failed to connect to orientation changed signal."; | |
| 86 } | |
| 87 | |
| 88 } // namespace sensors | |
| OLD | NEW |