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

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

Issue 2433363004: Chromad: added AD Join ui, authpolicy_client (Closed)
Patch Set: nit 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/auth_policy_client.h"
5
6 #include "base/bind.h"
7 #include "base/memory/weak_ptr.h"
8 #include "dbus/bus.h"
9 #include "dbus/message.h"
10 #include "dbus/object_proxy.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h"
12
13 namespace chromeos {
14
15 namespace {
16
17 class AuthPolicyClientImpl : public AuthPolicyClient {
18 public:
19 AuthPolicyClientImpl() : weak_ptr_factory_(this) {}
20
21 ~AuthPolicyClientImpl() override {}
22
23 // AuthPolicyClient override.
24 void JoinAdDomain(const std::string& machine_name,
25 const std::string& user,
26 int password_fd,
27 const JoinCallback& callback) override {
28 dbus::ObjectPath objectPath(authpolicy::kAuthPolicyServicePath);
29 dbus::ObjectProxy* proxy =
30 bus_->GetObjectProxy(authpolicy::kAuthPolicyServiceName, objectPath);
31 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
32 authpolicy::kAuthPolicyJoinADDomain);
33 dbus::MessageWriter writer(&method_call);
34 writer.AppendString(machine_name);
35 writer.AppendString(user);
36 writer.AppendFileDescriptor(password_fd);
37 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
38 base::Bind(&AuthPolicyClientImpl::HandleJoinCallback,
39 weak_ptr_factory_.GetWeakPtr(), callback));
40 }
41
42 protected:
43 void Init(dbus::Bus* bus) override { bus_ = bus; }
44
45 private:
46 void HandleJoinCallback(const JoinCallback& callback,
47 dbus::Response* response) {
48 if (!response) {
49 LOG(ERROR) << "Join: Couldn't call to authpolicy";
50 // TODO(rsorokin): make proper call, after defining possible errors codes.
51 callback.Run(authpolicy::AD_JOIN_ERROR_UNKNOWN);
52 return;
53 }
54
55 dbus::MessageReader reader(response);
56 int res = authpolicy::AD_JOIN_ERROR_UNKNOWN;
57 if (!reader.PopInt32(&res)) {
58 LOG(ERROR) << "Join: Couldn't get an error from the response";
59 // TODO(rsorokin): make proper call, after defining possible errors codes.
60 callback.Run(authpolicy::AD_JOIN_ERROR_DBUS_FAIL);
61 return;
62 }
63
64 callback.Run(res);
65 }
66
67 dbus::Bus* bus_ = nullptr;
68
69 // Note: This should remain the last member so it'll be destroyed and
70 // invalidate its weak pointers before any other members are destroyed.
71 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_;
72
73 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl);
74 };
75
76 } // namespace
77
78 AuthPolicyClient::AuthPolicyClient() {}
79
80 AuthPolicyClient::~AuthPolicyClient() {}
81
82 // static
83 AuthPolicyClient* AuthPolicyClient::Create() {
84 return new AuthPolicyClientImpl();
85 }
86
87 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698