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

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

Issue 2433363004: Chromad: added AD Join ui, authpolicy_client (Closed)
Patch Set: Adress authpolicy_client comments Created 4 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include "chromeos/dbus/authpolicy_client.h"
5
6 #include "base/bind.h"
7 #include "base/memory/weak_ptr.h"
8 #include "base/threading/worker_pool.h"
9 #include "chromeos/dbus/pipe_string_writer.h"
10 #include "dbus/bus.h"
11 #include "dbus/message.h"
12 #include "dbus/object_proxy.h"
13
14 namespace chromeos {
15
16 namespace {
17
18 // TODO(rsorokin): switch to service constants when it's landed (crbug/658655/)
hashimoto 2016/10/26 06:11:12 nit: crbug.com is the publicly accessible URL of o
Thiemo Nagel 2016/10/26 09:12:13 I think a nice way to write this would be: TODO(r
Roman Sorokin (ftl) 2016/10/26 18:45:35 Done.
Roman Sorokin (ftl) 2016/10/26 18:45:35 Done.
19 const char kAuthPolicyInterface[] = "org.chromium.AuthPolicy";
20 const char kAuthPolicyServicePath[] = "/org/chromium/AuthPolicy";
21 const char kAuthPolicyServiceName[] = "org.chromium.AuthPolicy";
22 // Method
23 const char kAuthPolicyJoinADDomain[] = "JoinADDomain";
24
25 class AuthPolicyClientImpl : public AuthPolicyClient {
26 public:
27 AuthPolicyClientImpl() : bus_(nullptr), weak_ptr_factory_(this) {}
28
29 ~AuthPolicyClientImpl() override {}
30
31 void JoinADDomain(const std::string& machine_name,
32 const std::string& user,
33 const std::string& password,
34 const JoinCallback& callback) override {
35 scoped_refptr<base::TaskRunner> task_runner =
36 base::WorkerPool::GetTaskRunner(true /* tasks_are_slow */);
hashimoto 2016/10/26 06:11:11 Generally speaking, you should avoid using WorkerP
Roman Sorokin (ftl) 2016/10/26 18:45:35 Done.
37 pipe_string_writer_.reset(new PipeStringWriter(
hashimoto 2016/10/26 06:11:12 Sorry for not being clear, please put the pipe rel
Roman Sorokin (ftl) 2016/10/26 18:45:35 Done.
38 password, task_runner,
39 base::Bind(&AuthPolicyClientImpl::OnPipeReadComplete,
40 weak_ptr_factory_.GetWeakPtr())));
41
42 dbus::ObjectPath objectPath(kAuthPolicyServicePath);
43 dbus::ObjectProxy* proxy =
44 bus_->GetObjectProxy(kAuthPolicyServiceName, objectPath);
45 dbus::MethodCall method_call(kAuthPolicyInterface, kAuthPolicyJoinADDomain);
46 dbus::MessageWriter writer(&method_call);
47 writer.AppendString(machine_name);
48 writer.AppendString(user);
49 writer.AppendFileDescriptor(pipe_string_writer_->StartIO().get());
50 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
51 base::Bind(&AuthPolicyClientImpl::HandleJoinCallback,
52 weak_ptr_factory_.GetWeakPtr(), callback));
53 }
54
55 protected:
56 void Init(dbus::Bus* bus) override { bus_ = bus; }
57
58 private:
59 void HandleJoinCallback(const JoinCallback& callback,
60 dbus::Response* response) {
61 if (!response) {
62 LOG(ERROR) << "Join: Couldn't call to authpolicy";
63 // TODO(rsorokin): make proper call, after defining possible errors codes.
hashimoto 2016/10/26 06:11:11 Before this change, can't you land error code cons
Roman Sorokin (ftl) 2016/10/26 18:45:35 Constants cl is in the pipeline, left TODO
64 callback.Run(1);
65 return;
66 }
67
68 dbus::MessageReader reader(response);
69 int res;
hashimoto 2016/10/26 06:11:12 Please don't leave a variable uninitialized.
Roman Sorokin (ftl) 2016/10/26 18:45:35 Done.
70 if (!reader.PopInt32(&res)) {
71 LOG(ERROR) << "Join: Couldn't get an error from the response";
72 // TODO(rsorokin): make proper call, after defining possible errors codes.
73 callback.Run(1);
74 return;
75 }
76
77 callback.Run(res);
78 }
79
80 void OnPipeReadComplete(int error_code) {
81 if (error_code != 0) {
82 LOG(ERROR) << "Failed to stream password to AuthPolicy: " << error_code;
83 }
84 }
85
86 dbus::Bus* bus_;
87
88 std::unique_ptr<PipeStringWriter> pipe_string_writer_;
89 // Note: This should remain the last member so it'll be destroyed and
90 // invalidate its weak pointers before any other members are destroyed.
91 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_;
92
93 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl);
94 };
95
96 } // namespace
97
98 AuthPolicyClient::AuthPolicyClient() {}
99
100 AuthPolicyClient::~AuthPolicyClient() {}
101
102 // static
103 AuthPolicyClient* AuthPolicyClient::Create() {
104 return new AuthPolicyClientImpl();
105 }
106
107 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698