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

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

Issue 2731253003: Add LoadComponent API in ImageLoader dbus adapter. (Closed)
Patch Set: fix parameters Created 3 years, 9 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/image_loader_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/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
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 LoadComponent(const std::string& name,
41 const StringDBusMethodCallback& callback) override {
42 dbus::MethodCall method_call(imageloader::kImageLoaderServiceInterface,
43 imageloader::kLoadComponent);
44 dbus::MessageWriter writer(&method_call);
45 writer.AppendString(name);
46 proxy_->CallMethod(
47 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
48 base::Bind(&ImageLoaderClientImpl::OnStringMethod, callback));
49 }
50
40 protected: 51 protected:
41 // DBusClient override. 52 // DBusClient override.
42 void Init(dbus::Bus* bus) override { 53 void Init(dbus::Bus* bus) override {
43 proxy_ = bus->GetObjectProxy( 54 proxy_ = bus->GetObjectProxy(
44 imageloader::kImageLoaderServiceName, 55 imageloader::kImageLoaderServiceName,
45 dbus::ObjectPath(imageloader::kImageLoaderServicePath)); 56 dbus::ObjectPath(imageloader::kImageLoaderServicePath));
46 } 57 }
47 58
48 private: 59 private:
49 static void OnBoolMethod(const BoolDBusMethodCallback& callback, 60 static void OnBoolMethod(const BoolDBusMethodCallback& callback,
50 dbus::Response* response) { 61 dbus::Response* response) {
51 if (!response) { 62 if (!response) {
52 callback.Run(DBUS_METHOD_CALL_FAILURE, false); 63 callback.Run(DBUS_METHOD_CALL_FAILURE, false);
53 return; 64 return;
54 } 65 }
55 dbus::MessageReader reader(response); 66 dbus::MessageReader reader(response);
56 bool result = false; 67 bool result = false;
57 if (!reader.PopBool(&result)) { 68 if (!reader.PopBool(&result)) {
58 callback.Run(DBUS_METHOD_CALL_FAILURE, false); 69 callback.Run(DBUS_METHOD_CALL_FAILURE, false);
59 LOG(ERROR) << "Invalid response: " << response->ToString(); 70 LOG(ERROR) << "Invalid response: " << response->ToString();
60 return; 71 return;
61 } 72 }
62 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); 73 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
63 } 74 }
64 75
76 static void OnStringMethod(const StringDBusMethodCallback& callback,
77 dbus::Response* response) {
78 if (!response) {
79 callback.Run(DBUS_METHOD_CALL_FAILURE, "");
80 return;
81 }
82 dbus::MessageReader reader(response);
83 std::string result = "";
Sorin Jianu 2017/03/06 19:33:17 doesn't need the "" initialization. The default ct
xiaochu 2017/03/06 20:28:24 Done.
84 if (!reader.PopString(&result)) {
85 callback.Run(DBUS_METHOD_CALL_FAILURE, "");
86 LOG(ERROR) << "Invalid response: " << response->ToString();
87 return;
88 }
89 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
90 }
91
65 dbus::ObjectProxy* proxy_ = nullptr; 92 dbus::ObjectProxy* proxy_ = nullptr;
66 93
67 DISALLOW_COPY_AND_ASSIGN(ImageLoaderClientImpl); 94 DISALLOW_COPY_AND_ASSIGN(ImageLoaderClientImpl);
68 }; 95 };
69 96
70 } // namespace 97 } // namespace
71 98
72 ImageLoaderClient::ImageLoaderClient() {} 99 ImageLoaderClient::ImageLoaderClient() {}
73 100
74 ImageLoaderClient::~ImageLoaderClient() {} 101 ImageLoaderClient::~ImageLoaderClient() {}
75 102
76 // static 103 // static
77 ImageLoaderClient* ImageLoaderClient::Create() { 104 ImageLoaderClient* ImageLoaderClient::Create() {
78 return new ImageLoaderClientImpl(); 105 return new ImageLoaderClientImpl();
79 } 106 }
80 107
81 } // namespace chromeos 108 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/image_loader_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698