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

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

Issue 23444057: Reduce chrome cras dbus call logs during device rebooting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename EnableLog Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/cras_audio_client.h ('k') | chromeos/dbus/cras_audio_client_stub_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/cras_audio_client.h" 5 #include "chromeos/dbus/cras_audio_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chromeos/dbus/cras_audio_client_stub_impl.h" 10 #include "chromeos/dbus/cras_audio_client_stub_impl.h"
11 #include "dbus/bus.h" 11 #include "dbus/bus.h"
12 #include "dbus/message.h" 12 #include "dbus/message.h"
13 #include "dbus/object_path.h" 13 #include "dbus/object_path.h"
14 #include "dbus/object_proxy.h" 14 #include "dbus/object_proxy.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 16
17 namespace chromeos { 17 namespace chromeos {
18 18
19 // Error name if cras dbus call fails with empty ErrorResponse.
20 const char kNoResponseError[] =
21 "org.chromium.cras.Error.NoResponse";
22
19 // The CrasAudioClient implementation used in production. 23 // The CrasAudioClient implementation used in production.
20 class CrasAudioClientImpl : public CrasAudioClient { 24 class CrasAudioClientImpl : public CrasAudioClient {
21 public: 25 public:
22 CrasAudioClientImpl() : cras_proxy_(NULL), weak_ptr_factory_(this) {} 26 CrasAudioClientImpl() : cras_proxy_(NULL), weak_ptr_factory_(this) {}
23 27
24 virtual ~CrasAudioClientImpl() { 28 virtual ~CrasAudioClientImpl() {
25 } 29 }
26 30
27 // CrasAudioClient overrides: 31 // CrasAudioClient overrides:
28 virtual void AddObserver(Observer* observer) OVERRIDE { 32 virtual void AddObserver(Observer* observer) OVERRIDE {
(...skipping 11 matching lines...) Expand all
40 virtual void GetVolumeState(const GetVolumeStateCallback& callback) OVERRIDE { 44 virtual void GetVolumeState(const GetVolumeStateCallback& callback) OVERRIDE {
41 dbus::MethodCall method_call(cras::kCrasControlInterface, 45 dbus::MethodCall method_call(cras::kCrasControlInterface,
42 cras::kGetVolumeState); 46 cras::kGetVolumeState);
43 cras_proxy_->CallMethod( 47 cras_proxy_->CallMethod(
44 &method_call, 48 &method_call,
45 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 49 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
46 base::Bind(&CrasAudioClientImpl::OnGetVolumeState, 50 base::Bind(&CrasAudioClientImpl::OnGetVolumeState,
47 weak_ptr_factory_.GetWeakPtr(), callback)); 51 weak_ptr_factory_.GetWeakPtr(), callback));
48 } 52 }
49 53
50 virtual void GetNodes(const GetNodesCallback& callback) OVERRIDE { 54 virtual void GetNodes(const GetNodesCallback& callback,
55 const ErrorCallback& error_callback) OVERRIDE {
51 dbus::MethodCall method_call(cras::kCrasControlInterface, 56 dbus::MethodCall method_call(cras::kCrasControlInterface,
52 cras::kGetNodes); 57 cras::kGetNodes);
53 cras_proxy_->CallMethod( 58 cras_proxy_->CallMethodWithErrorCallback(
54 &method_call, 59 &method_call,
55 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 60 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
56 base::Bind(&CrasAudioClientImpl::OnGetNodes, 61 base::Bind(&CrasAudioClientImpl::OnGetNodes,
57 weak_ptr_factory_.GetWeakPtr(), callback)); 62 weak_ptr_factory_.GetWeakPtr(), callback),
63 base::Bind(&CrasAudioClientImpl::OnError,
64 weak_ptr_factory_.GetWeakPtr(), error_callback));
58 } 65 }
59 66
60 virtual void SetOutputNodeVolume(uint64 node_id, int32 volume) OVERRIDE { 67 virtual void SetOutputNodeVolume(uint64 node_id, int32 volume) OVERRIDE {
61 dbus::MethodCall method_call(cras::kCrasControlInterface, 68 dbus::MethodCall method_call(cras::kCrasControlInterface,
62 cras::kSetOutputNodeVolume); 69 cras::kSetOutputNodeVolume);
63 dbus::MessageWriter writer(&method_call); 70 dbus::MessageWriter writer(&method_call);
64 writer.AppendUint64(node_id); 71 writer.AppendUint64(node_id);
65 writer.AppendInt32(volume); 72 writer.AppendInt32(volume);
66 cras_proxy_->CallMethod( 73 cras_proxy_->CallMethod(
67 &method_call, 74 &method_call,
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 LOG(WARNING) << "Error reading audio node data from cras: " 293 LOG(WARNING) << "Error reading audio node data from cras: "
287 << response->ToString(); 294 << response->ToString();
288 break; 295 break;
289 } 296 }
290 // Filter out the "UNKNOWN" type of audio devices. 297 // Filter out the "UNKNOWN" type of audio devices.
291 if (node.type != "UNKNOWN") 298 if (node.type != "UNKNOWN")
292 node_list.push_back(node); 299 node_list.push_back(node);
293 } 300 }
294 } 301 }
295 302
296 if (node_list.size() == 0) { 303 if (node_list.size() == 0)
297 success = false; 304 return;
298 LOG(ERROR) << "Error calling " << cras::kGetNodes;
299 }
300 305
301 callback.Run(node_list, success); 306 callback.Run(node_list, success);
302 } 307 }
303 308
309 void OnError(const ErrorCallback& error_callback,
310 dbus::ErrorResponse* response) {
311 // Error response has optional error message argument.
312 std::string error_name;
313 std::string error_message;
314 if (response) {
315 dbus::MessageReader reader(response);
316 error_name = response->GetErrorName();
317 reader.PopString(&error_message);
318 } else {
319 error_name = kNoResponseError;
320 error_message = "";
321 }
322 error_callback.Run(error_name, error_message);
323 }
324
304 bool GetAudioNode(dbus::Response* response, 325 bool GetAudioNode(dbus::Response* response,
305 dbus::MessageReader* array_reader, 326 dbus::MessageReader* array_reader,
306 AudioNode *node) { 327 AudioNode *node) {
307 while (array_reader->HasMoreData()) { 328 while (array_reader->HasMoreData()) {
308 dbus::MessageReader dict_entry_reader(response); 329 dbus::MessageReader dict_entry_reader(response);
309 dbus::MessageReader value_reader(response); 330 dbus::MessageReader value_reader(response);
310 std::string key; 331 std::string key;
311 if (!array_reader->PopDictEntry(&dict_entry_reader) || 332 if (!array_reader->PopDictEntry(&dict_entry_reader) ||
312 !dict_entry_reader.PopString(&key) || 333 !dict_entry_reader.PopString(&key) ||
313 !dict_entry_reader.PopVariant(&value_reader)) { 334 !dict_entry_reader.PopVariant(&value_reader)) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // static 402 // static
382 CrasAudioClient* CrasAudioClient::Create(DBusClientImplementationType type) { 403 CrasAudioClient* CrasAudioClient::Create(DBusClientImplementationType type) {
383 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { 404 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) {
384 return new CrasAudioClientImpl(); 405 return new CrasAudioClientImpl();
385 } 406 }
386 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 407 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
387 return new CrasAudioClientStubImpl(); 408 return new CrasAudioClientStubImpl();
388 } 409 }
389 410
390 } // namespace chromeos 411 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/cras_audio_client.h ('k') | chromeos/dbus/cras_audio_client_stub_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698