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 "chromeos/dbus/service_constants.h" | |
| 10 #include "content/browser/browser_thread.h" | |
| 11 #include "content/browser/sensors/sensors_provider.h" | |
| 12 #include "dbus/bus.h" | |
| 13 #include "dbus/message.h" | |
| 14 #include "dbus/object_proxy.h" | |
| 15 | |
| 16 namespace sensors { | |
| 17 | |
| 18 SensorsSourceChromeos::SensorsSourceChromeos() : sensors_proxy_(NULL) { | |
| 19 } | |
| 20 | |
| 21 bool SensorsSourceChromeos::Init() { | |
| 22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 23 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); | |
| 24 | |
| 25 dbus::Bus::Options options; | |
| 26 options.bus_type = dbus::Bus::SYSTEM; | |
| 27 options.connection_type = dbus::Bus::PRIVATE; | |
| 28 options.dbus_thread_message_loop_proxy = | |
| 29 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | |
| 30 bus_ = new dbus::Bus(options); | |
| 31 | |
| 32 sensors_proxy_ = bus_->GetObjectProxy(chromeos::kSensorsServiceName, | |
| 33 chromeos::kSensorsServicePath); | |
| 34 sensors_proxy_->ConnectToSignal(chromeos::kSensorsServiceInterface, | |
| 35 chromeos::kScreenOrientationChanged, | |
| 36 base::Bind(&SensorsSourceChromeos::OrientationChangedReceived, this), | |
| 37 base::Bind(&SensorsSourceChromeos::OrientationChangedConnected, this)); | |
| 38 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
| |
| 39 } | |
| 40 | |
| 41 void SensorsSourceChromeos::Stop() { | |
| 42 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
| |
| 43 if (bus_) | |
| 44 bus_->ShutdownOnDBusThreadAndBlock(); | |
| 45 } | |
| 46 | |
| 47 SensorsSourceChromeos::~SensorsSourceChromeos() { | |
| 48 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
| |
| 49 Stop(); | |
| 50 } | |
| 51 | |
| 52 void SensorsSourceChromeos::OrientationChangedReceived(dbus::Signal* signal) { | |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 54 | |
| 55 ScreenOrientation orientation; | |
| 56 | |
| 57 dbus::MessageReader reader(signal); | |
| 58 int32 upward = 0; | |
| 59 if (!reader.PopInt32(&upward)) { | |
| 60 LOG(WARNING) << "Orientation changed signal had incorrect parameters: " | |
| 61 << signal->ToString(); | |
| 62 return; | |
| 63 } | |
| 64 orientation.upward = static_cast<ScreenOrientation::Side>(upward); | |
| 65 | |
| 66 Provider::GetInstance()->ScreenOrientationChanged(orientation); | |
| 67 } | |
| 68 | |
| 69 void SensorsSourceChromeos::OrientationChangedConnected( | |
| 70 const std::string& interface_name, | |
| 71 const std::string& signal_name, | |
| 72 bool success) { | |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 74 if (!success) | |
| 75 LOG(WARNING) << "Failed to connect to orientation changed signal."; | |
| 76 } | |
| 77 | |
| 78 } // namespace sensors | |
| OLD | NEW |