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

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

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

Powered by Google App Engine
This is Rietveld 408576698