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 | |
| 15 static const char kSensorsServiceName[] = "org.chromium.Sensors"; | |
|
satorux1
2011/09/12 19:46:38
D-Bus constants should be defined in system_api.gi
tfarina
2011/09/12 20:07:12
static is not necessary here. const has implicit i
cwolfe
2011/09/12 21:17:36
Forgot about system_api.
Unfortunately that would
| |
| 16 static const char kSensorsPath[] = "/"; | |
|
satorux1
2011/09/12 19:46:38
Using "/" as object path is not correct: crosbug.
cwolfe
2011/09/12 21:17:36
Done.
satorux1
2011/09/12 21:55:14
I take it back. You should keep it as "/" for now,
| |
| 17 static const char kSensorsInterface[] = "org.chromium.Sensors"; | |
| 18 static const char kSensorsOrientationChanged[] = "ScreenOrientationChanged"; | |
| 19 | |
| 20 namespace sensors { | |
| 21 | |
| 22 SensorsSourceChromeos::SensorsSourceChromeos() : sensors_proxy_(NULL) { | |
| 23 } | |
| 24 | |
| 25 bool SensorsSourceChromeos::Init() { | |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 27 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); | |
| 28 | |
| 29 dbus::Bus::Options options; | |
| 30 options.bus_type = dbus::Bus::SYSTEM; | |
| 31 options.connection_type = dbus::Bus::PRIVATE; | |
| 32 options.dbus_thread_message_loop_proxy = | |
| 33 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | |
| 34 bus_ = new dbus::Bus(options); | |
| 35 | |
| 36 sensors_proxy_ = bus_->GetObjectProxy(kSensorsServiceName, kSensorsPath); | |
| 37 sensors_proxy_->ConnectToSignal(kSensorsInterface, kSensorsOrientationChanged, | |
| 38 base::Bind(&SensorsSourceChromeos::OrientationChangedReceived, this), | |
| 39 base::Bind(&SensorsSourceChromeos::OrientationChangedConnected, this)); | |
| 40 return true; | |
| 41 } | |
| 42 | |
| 43 void SensorsSourceChromeos::Stop() { | |
|
satorux1
2011/09/12 19:46:38
You might want to add
DCHECK(BrowserThread::Curre
cwolfe
2011/09/12 21:17:36
Done.
Come to think of it, isn't there a which-th
| |
| 44 if (bus_) | |
| 45 bus_->ShutdownAndBlock(); | |
|
satorux1
2011/09/12 19:46:38
Shutdown is a bit tricky. Since you are using the
cwolfe
2011/09/12 21:17:36
Done.
| |
| 46 } | |
| 47 | |
| 48 SensorsSourceChromeos::~SensorsSourceChromeos() { | |
| 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; | |
|
satorux1
2011/09/12 19:46:38
initialize with 0? Uninitialized variable can be l
cwolfe
2011/09/12 21:17:36
Done.
| |
| 59 if (!reader.PopInt32(&upward)) { | |
| 60 LOG(WARNING) << "Orientation changed signal had incorrect parameters."; | |
|
satorux1
2011/09/12 19:46:38
Let's add << signal->ToString() in the warning. Th
cwolfe
2011/09/12 21:17:36
Done.
| |
| 61 return; | |
| 62 } | |
| 63 orientation.upward = static_cast<ScreenOrientation::Side>(upward); | |
| 64 | |
| 65 Provider::GetInstance()->ScreenOrientationChanged(orientation); | |
| 66 } | |
| 67 | |
| 68 void SensorsSourceChromeos::OrientationChangedConnected( | |
| 69 const std::string& iface_name, | |
| 70 const std::string& signal_name, | |
| 71 bool success) { | |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 73 if (!success) | |
| 74 LOG(WARNING) << "Failed to connect to orientation changed signal."; | |
| 75 } | |
| 76 | |
| 77 } // namespace sensors | |
| OLD | NEW |