OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <unistd.h> | 6 #include <unistd.h> |
7 | 7 |
8 #include "chromeos/dbus/debug_daemon_client.h" | 8 #include "chromeos/dbus/debug_daemon_client.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 weak_ptr_factory_(this), | 143 weak_ptr_factory_(this), |
144 pipe_reader_(NULL) { | 144 pipe_reader_(NULL) { |
145 debugdaemon_proxy_ = bus->GetObjectProxy( | 145 debugdaemon_proxy_ = bus->GetObjectProxy( |
146 debugd::kDebugdServiceName, | 146 debugd::kDebugdServiceName, |
147 dbus::ObjectPath(debugd::kDebugdServicePath)); | 147 dbus::ObjectPath(debugd::kDebugdServicePath)); |
148 } | 148 } |
149 | 149 |
150 virtual ~DebugDaemonClientImpl() {} | 150 virtual ~DebugDaemonClientImpl() {} |
151 | 151 |
152 // DebugDaemonClient override. | 152 // DebugDaemonClient override. |
| 153 virtual void SetDebugMode(const std::string& subsystem, |
| 154 const SetDebugModeCallback& callback) OVERRIDE { |
| 155 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 156 debugd::kSetDebugMode); |
| 157 dbus::MessageWriter writer(&method_call); |
| 158 writer.AppendString(subsystem); |
| 159 debugdaemon_proxy_->CallMethod( |
| 160 &method_call, |
| 161 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 162 base::Bind(&DebugDaemonClientImpl::OnSetDebugMode, |
| 163 weak_ptr_factory_.GetWeakPtr(), |
| 164 callback)); |
| 165 } |
| 166 |
153 virtual void StartSystemTracing() OVERRIDE { | 167 virtual void StartSystemTracing() OVERRIDE { |
154 dbus::MethodCall method_call( | 168 dbus::MethodCall method_call( |
155 debugd::kDebugdInterface, | 169 debugd::kDebugdInterface, |
156 debugd::kSystraceStart); | 170 debugd::kSystraceStart); |
157 dbus::MessageWriter writer(&method_call); | 171 dbus::MessageWriter writer(&method_call); |
158 writer.AppendString("all"); // TODO(sleffler) parameterize category list | 172 writer.AppendString("all"); // TODO(sleffler) parameterize category list |
159 | 173 |
160 DVLOG(1) << "Requesting a systrace start"; | 174 DVLOG(1) << "Requesting a systrace start"; |
161 debugdaemon_proxy_->CallMethod( | 175 debugdaemon_proxy_->CallMethod( |
162 &method_call, | 176 &method_call, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 216 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
203 base::Bind(&DebugDaemonClientImpl::OnRequestStopSystemTracing, | 217 base::Bind(&DebugDaemonClientImpl::OnRequestStopSystemTracing, |
204 weak_ptr_factory_.GetWeakPtr())); | 218 weak_ptr_factory_.GetWeakPtr())); |
205 | 219 |
206 pipe_reader_->CloseWriteFD(); // close our copy of fd after send | 220 pipe_reader_->CloseWriteFD(); // close our copy of fd after send |
207 | 221 |
208 return true; | 222 return true; |
209 } | 223 } |
210 | 224 |
211 private: | 225 private: |
| 226 // Called when a response for SetDebugMode() is received. |
| 227 void OnSetDebugMode(const SetDebugModeCallback& callback, |
| 228 dbus::Response* response) { |
| 229 if (!response) { |
| 230 LOG(ERROR) << "Failed to change debug mode"; |
| 231 callback.Run(false); |
| 232 } else { |
| 233 callback.Run(true); |
| 234 } |
| 235 } |
| 236 |
212 // Called when a response for StartSystemTracing() is received. | 237 // Called when a response for StartSystemTracing() is received. |
213 void OnStartSystemTracing(dbus::Response* response) { | 238 void OnStartSystemTracing(dbus::Response* response) { |
214 if (!response) { | 239 if (!response) { |
215 LOG(ERROR) << "Failed to request systrace start"; | 240 LOG(ERROR) << "Failed to request systrace start"; |
216 return; | 241 return; |
217 } | 242 } |
218 } | 243 } |
219 | 244 |
220 // Called when a response for RequestStopSystemTracing() is received. | 245 // Called when a response for RequestStopSystemTracing() is received. |
221 void OnRequestStopSystemTracing(dbus::Response* response) { | 246 void OnRequestStopSystemTracing(dbus::Response* response) { |
(...skipping 15 matching lines...) Expand all Loading... |
237 scoped_ptr<PipeReader> pipe_reader_; | 262 scoped_ptr<PipeReader> pipe_reader_; |
238 StopSystemTracingCallback callback_; | 263 StopSystemTracingCallback callback_; |
239 | 264 |
240 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); | 265 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); |
241 }; | 266 }; |
242 | 267 |
243 // The DebugDaemonClient implementation used on Linux desktop, | 268 // The DebugDaemonClient implementation used on Linux desktop, |
244 // which does nothing. | 269 // which does nothing. |
245 class DebugDaemonClientStubImpl : public DebugDaemonClient { | 270 class DebugDaemonClientStubImpl : public DebugDaemonClient { |
246 // DebugDaemonClient overrides. | 271 // DebugDaemonClient overrides. |
| 272 virtual void SetDebugMode(const std::string& subsystem, |
| 273 const SetDebugModeCallback& callback) OVERRIDE { |
| 274 callback.Run(false); |
| 275 } |
247 virtual void StartSystemTracing() OVERRIDE {} | 276 virtual void StartSystemTracing() OVERRIDE {} |
248 virtual bool RequestStopSystemTracing(const StopSystemTracingCallback& | 277 virtual bool RequestStopSystemTracing(const StopSystemTracingCallback& |
249 callback) OVERRIDE { | 278 callback) OVERRIDE { |
250 std::string no_data; | 279 std::string no_data; |
251 callback.Run(base::RefCountedString::TakeString(&no_data)); | 280 callback.Run(base::RefCountedString::TakeString(&no_data)); |
252 return true; | 281 return true; |
253 } | 282 } |
254 }; | 283 }; |
255 | 284 |
256 DebugDaemonClient::DebugDaemonClient() { | 285 DebugDaemonClient::DebugDaemonClient() { |
(...skipping 11 matching lines...) Expand all Loading... |
268 // static | 297 // static |
269 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, | 298 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, |
270 dbus::Bus* bus) { | 299 dbus::Bus* bus) { |
271 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 300 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
272 return new DebugDaemonClientImpl(bus); | 301 return new DebugDaemonClientImpl(bus); |
273 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 302 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
274 return new DebugDaemonClientStubImpl(); | 303 return new DebugDaemonClientStubImpl(); |
275 } | 304 } |
276 | 305 |
277 } // namespace chromeos | 306 } // namespace chromeos |
OLD | NEW |