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

Side by Side Diff: chromeos/dbus/upstart_client.cc

Issue 2791983004: DBus MediaAnalyticsClient and media_perception pb. (Closed)
Patch Set: Changing the type of a couple vars to const. Created 3 years, 7 months 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
« no previous file with comments | « chromeos/dbus/upstart_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/upstart_client.h" 5 #include "chromeos/dbus/upstart_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "dbus/bus.h" 9 #include "dbus/bus.h"
10 #include "dbus/message.h" 10 #include "dbus/message.h"
11 #include "dbus/object_proxy.h" 11 #include "dbus/object_proxy.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 namespace { 15 namespace {
16 16
17 const char kUpstartServiceName[] = "com.ubuntu.Upstart"; 17 const char kUpstartServiceName[] = "com.ubuntu.Upstart";
18 const char kUpstartJobInterface[] = "com.ubuntu.Upstart0_6.Job"; 18 const char kUpstartJobInterface[] = "com.ubuntu.Upstart0_6.Job";
19 const char kUpstartStartMethod[] = "Start"; 19 const char kUpstartStartMethod[] = "Start";
20 const char kUpstartRestartMethod[] = "Restart"; 20 const char kUpstartRestartMethod[] = "Restart";
21 const char kUpstartStopMethod[] = "Stop";
21 22
22 const char kUpstartAuthPolicyPath[] = "/com/ubuntu/Upstart/jobs/authpolicyd"; 23 const char kUpstartAuthPolicyPath[] = "/com/ubuntu/Upstart/jobs/authpolicyd";
24 const char kUpstartMediaAnalyticsPath[] =
25 "/com/ubuntu/Upstart/jobs/rtanalytics";
23 26
24 class UpstartClientImpl : public UpstartClient { 27 class UpstartClientImpl : public UpstartClient {
25 public: 28 public:
26 UpstartClientImpl() : weak_ptr_factory_(this) {} 29 UpstartClientImpl() : weak_ptr_factory_(this) {}
27 30
28 ~UpstartClientImpl() override {} 31 ~UpstartClientImpl() override {}
29 32
30 // UpstartClient override. 33 // UpstartClient override.
31 void StartAuthPolicyService() override { 34 void StartAuthPolicyService() override {
32 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStartMethod); 35 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStartMethod);
(...skipping 10 matching lines...) Expand all
43 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartRestartMethod); 46 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartRestartMethod);
44 dbus::MessageWriter writer(&method_call); 47 dbus::MessageWriter writer(&method_call);
45 writer.AppendArrayOfStrings(std::vector<std::string>()); 48 writer.AppendArrayOfStrings(std::vector<std::string>());
46 writer.AppendBool(true); // Wait for response. 49 writer.AppendBool(true); // Wait for response.
47 auth_proxy_->CallMethod(&method_call, 50 auth_proxy_->CallMethod(&method_call,
48 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 51 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
49 base::Bind(&UpstartClientImpl::HandleAuthResponse, 52 base::Bind(&UpstartClientImpl::HandleAuthResponse,
50 weak_ptr_factory_.GetWeakPtr())); 53 weak_ptr_factory_.GetWeakPtr()));
51 } 54 }
52 55
56 void StartMediaAnalytics(const UpstartCallback& callback) override {
57 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStartMethod);
58 dbus::MessageWriter writer(&method_call);
59 writer.AppendArrayOfStrings(std::vector<std::string>());
60 writer.AppendBool(true); // Wait for response.
61 ma_proxy_->CallMethod(
62 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
63 base::Bind(&UpstartClientImpl::HandleStartMediaAnalyticsResponse,
64 weak_ptr_factory_.GetWeakPtr(), callback));
65 }
66
67 void StopMediaAnalytics() override {
68 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStopMethod);
69 dbus::MessageWriter writer(&method_call);
70 writer.AppendArrayOfStrings(std::vector<std::string>());
71 writer.AppendBool(true); // Wait for response.
72 ma_proxy_->CallMethod(
73 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
74 base::Bind(&UpstartClientImpl::HandleStopMediaAnalyticsResponse,
75 weak_ptr_factory_.GetWeakPtr()));
76 }
77
53 protected: 78 protected:
54 void Init(dbus::Bus* bus) override { 79 void Init(dbus::Bus* bus) override {
55 bus_ = bus; 80 bus_ = bus;
56 auth_proxy_ = bus_->GetObjectProxy( 81 auth_proxy_ = bus_->GetObjectProxy(
57 kUpstartServiceName, dbus::ObjectPath(kUpstartAuthPolicyPath)); 82 kUpstartServiceName, dbus::ObjectPath(kUpstartAuthPolicyPath));
83 ma_proxy_ = bus_->GetObjectProxy(
84 kUpstartServiceName, dbus::ObjectPath(kUpstartMediaAnalyticsPath));
58 } 85 }
59 86
60 private: 87 private:
61 void HandleAuthResponse(dbus::Response* response) { 88 void HandleAuthResponse(dbus::Response* response) {
62 LOG_IF(ERROR, !response) << "Failed to signal Upstart, response is null"; 89 LOG_IF(ERROR, !response) << "Failed to signal Upstart, response is null";
63 } 90 }
64 91
92 void HandleStartMediaAnalyticsResponse(const UpstartCallback& callback,
93 dbus::Response* response) {
94 if (!response) {
95 LOG(ERROR) << "Failed to signal Upstart, response is null.";
96 callback.Run(false);
97 return;
98 }
99 callback.Run(true);
100 }
101
102 void HandleStopMediaAnalyticsResponse(dbus::Response* response) {
103 LOG_IF(ERROR, !response) << "Failed to signal Upstart, response is null";
104 }
105
65 dbus::Bus* bus_ = nullptr; 106 dbus::Bus* bus_ = nullptr;
66 dbus::ObjectProxy* auth_proxy_ = nullptr; 107 dbus::ObjectProxy* auth_proxy_ = nullptr;
108 dbus::ObjectProxy* ma_proxy_ = nullptr;
67 109
68 // Note: This should remain the last member so it'll be destroyed and 110 // Note: This should remain the last member so it'll be destroyed and
69 // invalidate its weak pointers before any other members are destroyed. 111 // invalidate its weak pointers before any other members are destroyed.
70 base::WeakPtrFactory<UpstartClientImpl> weak_ptr_factory_; 112 base::WeakPtrFactory<UpstartClientImpl> weak_ptr_factory_;
71 113
72 DISALLOW_COPY_AND_ASSIGN(UpstartClientImpl); 114 DISALLOW_COPY_AND_ASSIGN(UpstartClientImpl);
73 }; 115 };
74 116
75 } // namespace 117 } // namespace
76 118
77 UpstartClient::UpstartClient() {} 119 UpstartClient::UpstartClient() {}
78 120
79 UpstartClient::~UpstartClient() {} 121 UpstartClient::~UpstartClient() {}
80 122
81 // static 123 // static
82 UpstartClient* UpstartClient::Create() { 124 UpstartClient* UpstartClient::Create() {
83 return new UpstartClientImpl(); 125 return new UpstartClientImpl();
84 } 126 }
85 127
86 } // namespace chromeos 128 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/upstart_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698