Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/chromeos/dbus/sensors_source.cc

Issue 8400034: chromeos: Add a stub implementation for SensorsSource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "chrome/browser/chromeos/dbus/sensors_source.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 // 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
25 SensorsSource::SensorsSource()
26 : sensors_proxy_(NULL),
27 weak_ptr_factory_(this) {
28 }
29
30 void SensorsSource::Init(dbus::Bus* bus) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
32
33 sensors_proxy_ = bus->GetObjectProxy(chromeos::kSensorsServiceName,
34 chromeos::kSensorsServicePath);
35 sensors_proxy_->ConnectToSignal(chromeos::kSensorsServiceInterface,
36 chromeos::kScreenOrientationChanged,
37 base::Bind(&SensorsSource::OrientationChangedReceived,
38 weak_ptr_factory_.GetWeakPtr()),
39 base::Bind(&SensorsSource::OrientationChangedConnected,
40 weak_ptr_factory_.GetWeakPtr()));
41 }
42
43 SensorsSource::~SensorsSource() {
44 }
45
46 void SensorsSource::OrientationChangedReceived(dbus::Signal* signal) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48
49 sensors::ScreenOrientation orientation;
50
51 dbus::MessageReader reader(signal);
52 int32 upward = 0;
53 if (!reader.PopInt32(&upward)) {
54 LOG(WARNING) << "Orientation changed signal had incorrect parameters: "
55 << signal->ToString();
56 return;
57 }
58 VLOG(1) << "Orientation changed to upward " << upward;
59 orientation.upward = static_cast<sensors::ScreenOrientation::Side>(upward);
60
61 sensors::Provider::GetInstance()->ScreenOrientationChanged(orientation);
62 }
63
64 void SensorsSource::OrientationChangedConnected(
65 const std::string& interface_name,
66 const std::string& signal_name,
67 bool success) {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
69 if (!success)
70 LOG(WARNING) << "Failed to connect to orientation changed signal.";
71 }
72
73 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/sensors_source.h ('k') | chrome/browser/chromeos/dbus/speech_synthesizer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698