OLD | NEW |
---|---|
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/image_loader_client.h" | 5 #include "chromeos/dbus/image_loader_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "dbus/bus.h" | 9 #include "dbus/bus.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 imageloader::kRegisterComponent); | 30 imageloader::kRegisterComponent); |
31 dbus::MessageWriter writer(&method_call); | 31 dbus::MessageWriter writer(&method_call); |
32 writer.AppendString(name); | 32 writer.AppendString(name); |
33 writer.AppendString(version); | 33 writer.AppendString(version); |
34 writer.AppendString(component_folder_abs_path); | 34 writer.AppendString(component_folder_abs_path); |
35 proxy_->CallMethod( | 35 proxy_->CallMethod( |
36 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 36 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
37 base::Bind(&ImageLoaderClientImpl::OnBoolMethod, callback)); | 37 base::Bind(&ImageLoaderClientImpl::OnBoolMethod, callback)); |
38 } | 38 } |
39 | 39 |
40 void RegisterComponent(const std::string& name, | |
41 const std::string& version, | |
42 const std::string& component_folder_abs_path, | |
43 const BoolDBusMethodCallbackPm& callback) override { | |
44 dbus::MethodCall method_call(imageloader::kImageLoaderServiceInterface, | |
45 imageloader::kRegisterComponent); | |
46 dbus::MessageWriter writer(&method_call); | |
47 writer.AppendString(name); | |
48 writer.AppendString(version); | |
49 writer.AppendString(component_folder_abs_path); | |
50 proxy_->CallMethod( | |
51 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
52 base::Bind(&ImageLoaderClientImpl::OnBoolPmMethod, callback, name)); | |
hashimoto
2017/03/10 04:27:22
You should just use OnBoolMethod here.
If you want
xiaochu
2017/03/10 16:49:00
Done.
| |
53 } | |
54 | |
40 void LoadComponent(const std::string& name, | 55 void LoadComponent(const std::string& name, |
41 const StringDBusMethodCallback& callback) override { | 56 const StringDBusMethodCallback& callback) override { |
42 dbus::MethodCall method_call(imageloader::kImageLoaderServiceInterface, | 57 dbus::MethodCall method_call(imageloader::kImageLoaderServiceInterface, |
43 imageloader::kLoadComponent); | 58 imageloader::kLoadComponent); |
44 dbus::MessageWriter writer(&method_call); | 59 dbus::MessageWriter writer(&method_call); |
45 writer.AppendString(name); | 60 writer.AppendString(name); |
46 proxy_->CallMethod( | 61 proxy_->CallMethod( |
47 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 62 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
48 base::Bind(&ImageLoaderClientImpl::OnStringMethod, callback)); | 63 base::Bind(&ImageLoaderClientImpl::OnStringMethod, callback)); |
49 } | 64 } |
(...skipping 16 matching lines...) Expand all Loading... | |
66 dbus::MessageReader reader(response); | 81 dbus::MessageReader reader(response); |
67 bool result = false; | 82 bool result = false; |
68 if (!reader.PopBool(&result)) { | 83 if (!reader.PopBool(&result)) { |
69 callback.Run(DBUS_METHOD_CALL_FAILURE, false); | 84 callback.Run(DBUS_METHOD_CALL_FAILURE, false); |
70 LOG(ERROR) << "Invalid response: " << response->ToString(); | 85 LOG(ERROR) << "Invalid response: " << response->ToString(); |
71 return; | 86 return; |
72 } | 87 } |
73 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); | 88 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); |
74 } | 89 } |
75 | 90 |
91 static void OnBoolPmMethod(const BoolDBusMethodCallbackPm& callback, | |
92 const std::string& msg, | |
93 dbus::Response* response) { | |
94 if (!response) { | |
95 callback.Run(DBUS_METHOD_CALL_FAILURE, false, ""); | |
96 return; | |
97 } | |
98 dbus::MessageReader reader(response); | |
99 bool result = false; | |
100 if (!reader.PopBool(&result)) { | |
101 callback.Run(DBUS_METHOD_CALL_FAILURE, false, ""); | |
102 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
103 return; | |
104 } | |
105 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, msg); | |
106 } | |
107 | |
76 static void OnStringMethod(const StringDBusMethodCallback& callback, | 108 static void OnStringMethod(const StringDBusMethodCallback& callback, |
77 dbus::Response* response) { | 109 dbus::Response* response) { |
78 if (!response) { | 110 if (!response) { |
79 callback.Run(DBUS_METHOD_CALL_FAILURE, ""); | 111 callback.Run(DBUS_METHOD_CALL_FAILURE, ""); |
80 return; | 112 return; |
81 } | 113 } |
82 dbus::MessageReader reader(response); | 114 dbus::MessageReader reader(response); |
83 std::string result; | 115 std::string result; |
84 if (!reader.PopString(&result)) { | 116 if (!reader.PopString(&result)) { |
85 callback.Run(DBUS_METHOD_CALL_FAILURE, ""); | 117 callback.Run(DBUS_METHOD_CALL_FAILURE, ""); |
(...skipping 13 matching lines...) Expand all Loading... | |
99 ImageLoaderClient::ImageLoaderClient() {} | 131 ImageLoaderClient::ImageLoaderClient() {} |
100 | 132 |
101 ImageLoaderClient::~ImageLoaderClient() {} | 133 ImageLoaderClient::~ImageLoaderClient() {} |
102 | 134 |
103 // static | 135 // static |
104 ImageLoaderClient* ImageLoaderClient::Create() { | 136 ImageLoaderClient* ImageLoaderClient::Create() { |
105 return new ImageLoaderClientImpl(); | 137 return new ImageLoaderClientImpl(); |
106 } | 138 } |
107 | 139 |
108 } // namespace chromeos | 140 } // namespace chromeos |
OLD | NEW |