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

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

Issue 2587993002: Chromad: Switch AuthPolicyClient to use cros_system_api enums. (Closed)
Patch Set: Move default to the end of switch. Created 3 years, 11 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/auth_policy_client.h ('k') | chromeos/dbus/fake_auth_policy_client.cc » ('j') | 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 #include "chromeos/dbus/auth_policy_client.h" 4 #include "chromeos/dbus/auth_policy_client.h"
5 5
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "components/signin/core/account_id/account_id.h" 8 #include "components/signin/core/account_id/account_id.h"
9 #include "dbus/bus.h" 9 #include "dbus/bus.h"
10 #include "dbus/message.h" 10 #include "dbus/message.h"
11 #include "dbus/object_proxy.h" 11 #include "dbus/object_proxy.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h"
13 12
14 namespace chromeos { 13 namespace chromeos {
15 14
16 namespace { 15 namespace {
17 16
17 authpolicy::ErrorType GetErrorFromReader(dbus::MessageReader* reader) {
18 int32_t int_error;
19 if (!reader->PopInt32(&int_error)) {
20 DLOG(ERROR) << "AuthPolicyClient: Failed to get an error from the response";
21 return authpolicy::ERROR_DBUS_FAILURE;
22 }
23 if (int_error < 0 || int_error >= authpolicy::ERROR_COUNT)
24 return authpolicy::ERROR_UNKNOWN;
25 return static_cast<authpolicy::ErrorType>(int_error);
26 }
27
18 class AuthPolicyClientImpl : public AuthPolicyClient { 28 class AuthPolicyClientImpl : public AuthPolicyClient {
19 public: 29 public:
20 AuthPolicyClientImpl() : weak_ptr_factory_(this) {} 30 AuthPolicyClientImpl() : weak_ptr_factory_(this) {}
21 31
22 ~AuthPolicyClientImpl() override {} 32 ~AuthPolicyClientImpl() override {}
23 33
24 // AuthPolicyClient override. 34 // AuthPolicyClient override.
25 void JoinAdDomain(const std::string& machine_name, 35 void JoinAdDomain(const std::string& machine_name,
26 const std::string& user_principal_name, 36 const std::string& user_principal_name,
27 int password_fd, 37 int password_fd,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 callback.Run(false); 97 callback.Run(false);
88 return; 98 return;
89 } 99 }
90 callback.Run(true); 100 callback.Run(true);
91 } 101 }
92 102
93 void HandleJoinCallback(const JoinCallback& callback, 103 void HandleJoinCallback(const JoinCallback& callback,
94 dbus::Response* response) { 104 dbus::Response* response) {
95 if (!response) { 105 if (!response) {
96 DLOG(ERROR) << "Join: Couldn't call to authpolicy"; 106 DLOG(ERROR) << "Join: Couldn't call to authpolicy";
97 // TODO(rsorokin): make proper call, after defining possible errors codes. 107 callback.Run(authpolicy::ERROR_DBUS_FAILURE);
98 callback.Run(authpolicy::types::AD_JOIN_ERROR_UNKNOWN);
99 return; 108 return;
100 } 109 }
101 110
102 dbus::MessageReader reader(response); 111 dbus::MessageReader reader(response);
103 int res = authpolicy::types::AD_JOIN_ERROR_UNKNOWN; 112 callback.Run(GetErrorFromReader(&reader));
104 if (!reader.PopInt32(&res)) {
105 DLOG(ERROR) << "Join: Couldn't get an error from the response";
106 // TODO(rsorokin): make proper call, after defining possible errors codes.
107 callback.Run(authpolicy::types::AD_JOIN_ERROR_DBUS_FAIL);
108 return;
109 }
110
111 callback.Run(res);
112 } 113 }
113 114
114 void HandleAuthCallback(const AuthCallback& callback, 115 void HandleAuthCallback(const AuthCallback& callback,
115 dbus::Response* response) { 116 dbus::Response* response) {
116 std::string user_id;
117 int32_t res = static_cast<int32_t>(authpolicy::AUTH_USER_ERROR_UNKNOWN);
118 if (!response) { 117 if (!response) {
119 DLOG(ERROR) << "Auth: Failed to call to authpolicy"; 118 DLOG(ERROR) << "Auth: Failed to call to authpolicy";
120 // TODO(rsorokin): make proper call, after defining possible errors codes. 119 callback.Run(authpolicy::ERROR_DBUS_FAILURE, std::string());
121 callback.Run(authpolicy::AUTH_USER_ERROR_DBUS_FAILURE, user_id);
122 return; 120 return;
123 } 121 }
124 dbus::MessageReader reader(response); 122 dbus::MessageReader reader(response);
125 if (!reader.PopInt32(&res)) { 123 const authpolicy::ErrorType error(GetErrorFromReader(&reader));
126 DLOG(ERROR) << "Auth: Failed to get an error from the response"; 124 std::string user_id;
127 // TODO(rsorokin): make proper call, after defining possible errors codes.
128 callback.Run(static_cast<authpolicy::AuthUserErrorType>(res), user_id);
129 return;
130 }
131 if (res < 0 || res >= authpolicy::AUTH_USER_ERROR_COUNT)
132 res = static_cast<int32_t>(authpolicy::AUTH_USER_ERROR_UNKNOWN);
133 if (!reader.PopString(&user_id)) 125 if (!reader.PopString(&user_id))
134 DLOG(ERROR) << "Auth: Failed to get user_id from the response"; 126 DLOG(ERROR) << "Auth: Failed to get user_id from the response";
135 callback.Run(static_cast<authpolicy::AuthUserErrorType>(res), user_id); 127 callback.Run(error, user_id);
136 } 128 }
137 129
138 dbus::Bus* bus_ = nullptr; 130 dbus::Bus* bus_ = nullptr;
139 dbus::ObjectProxy* proxy_ = nullptr; 131 dbus::ObjectProxy* proxy_ = nullptr;
140 132
141 // Note: This should remain the last member so it'll be destroyed and 133 // Note: This should remain the last member so it'll be destroyed and
142 // invalidate its weak pointers before any other members are destroyed. 134 // invalidate its weak pointers before any other members are destroyed.
143 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_; 135 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_;
144 136
145 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl); 137 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl);
146 }; 138 };
147 139
148 } // namespace 140 } // namespace
149 141
150 AuthPolicyClient::AuthPolicyClient() {} 142 AuthPolicyClient::AuthPolicyClient() {}
151 143
152 AuthPolicyClient::~AuthPolicyClient() {} 144 AuthPolicyClient::~AuthPolicyClient() {}
153 145
154 // static 146 // static
155 AuthPolicyClient* AuthPolicyClient::Create() { 147 AuthPolicyClient* AuthPolicyClient::Create() {
156 return new AuthPolicyClientImpl(); 148 return new AuthPolicyClientImpl();
157 } 149 }
158 150
159 } // namespace chromeos 151 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/auth_policy_client.h ('k') | chromeos/dbus/fake_auth_policy_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698