Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/threading/worker_pool.h" | |
|
hashimoto
2016/10/27 02:26:07
nit: Please remove unused include.
Roman Sorokin (ftl)
2016/10/27 13:10:46
Done.
| |
| 9 #include "dbus/bus.h" | |
| 10 #include "dbus/message.h" | |
| 11 #include "dbus/object_proxy.h" | |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class AuthPolicyClientImpl : public AuthPolicyClient { | |
| 19 public: | |
| 20 AuthPolicyClientImpl() : bus_(nullptr), weak_ptr_factory_(this) {} | |
|
xiyuan
2016/10/26 22:03:17
nit: move |bus_| initializer to line 73 where it i
Roman Sorokin (ftl)
2016/10/27 13:10:46
Done.
| |
| 21 | |
| 22 ~AuthPolicyClientImpl() override {} | |
| 23 | |
| 24 void JoinADDomain(const std::string& machine_name, | |
|
xiyuan
2016/10/26 22:03:16
nit: // AuthPolicyClient:
Roman Sorokin (ftl)
2016/10/27 13:10:46
Done.
| |
| 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 void OnPipeReadComplete(int error_code) { | |
|
xiyuan
2016/10/26 22:03:17
Is this used anywhere?
Roman Sorokin (ftl)
2016/10/27 13:10:46
Done.
| |
| 68 if (error_code != 0) { | |
| 69 LOG(ERROR) << "Failed to stream password to AuthPolicy: " << error_code; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 dbus::Bus* bus_; | |
| 74 | |
| 75 // Note: This should remain the last member so it'll be destroyed and | |
| 76 // invalidate its weak pointers before any other members are destroyed. | |
| 77 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl); | |
| 80 }; | |
| 81 | |
| 82 } // namespace | |
| 83 | |
| 84 AuthPolicyClient::AuthPolicyClient() {} | |
| 85 | |
| 86 AuthPolicyClient::~AuthPolicyClient() {} | |
| 87 | |
| 88 // static | |
| 89 AuthPolicyClient* AuthPolicyClient::Create() { | |
| 90 return new AuthPolicyClientImpl(); | |
| 91 } | |
| 92 | |
| 93 } // namespace chromeos | |
| OLD | NEW |