Chromium Code Reviews| 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..7e31260759de417529017407d7928e5b21370200 |
| --- /dev/null |
| +++ b/content/browser/sensors/sensors_source_chromeos.cc |
| @@ -0,0 +1,78 @@ |
| +// 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 "chromeos/dbus/service_constants.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" |
| + |
| +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(chromeos::kSensorsServiceName, |
| + chromeos::kSensorsServicePath); |
| + sensors_proxy_->ConnectToSignal(chromeos::kSensorsServiceInterface, |
| + chromeos::kScreenOrientationChanged, |
| + base::Bind(&SensorsSourceChromeos::OrientationChangedReceived, this), |
| + base::Bind(&SensorsSourceChromeos::OrientationChangedConnected, this)); |
| + return true; |
|
sky
2011/09/12 21:21:19
This always returns true. Is there any point in a
cwolfe
2011/09/12 22:15:55
Only for consistency with other Inits. There was p
|
| +} |
| + |
| +void SensorsSourceChromeos::Stop() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
|
sky
2011/09/12 21:21:19
I don't see this getting invoked. When is it invok
cwolfe
2011/09/12 22:15:55
Just the destructor at the moment. Initially added
|
| + if (bus_) |
| + bus_->ShutdownOnDBusThreadAndBlock(); |
| +} |
| + |
| +SensorsSourceChromeos::~SensorsSourceChromeos() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
|
sky
2011/09/12 21:21:19
How are you guaranteeing this is going to be delet
cwolfe
2011/09/12 22:15:55
Now that I finally re-located DeleteOnUIThread, us
|
| + 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 |