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

Side by Side Diff: chrome/browser/sync/engine/authenticator.cc

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 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
5 #include "chrome/browser/sync/engine/authenticator.h"
6
7 #include "chrome/browser/sync/engine/net/gaia_authenticator.h"
8 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
9 #include "chrome/browser/sync/engine/syncproto.h"
10 #include "chrome/browser/sync/protocol/sync.pb.h"
11 #include "chrome/browser/sync/util/event_sys-inl.h"
12 #include "chrome/browser/sync/util/user_settings.h"
13
14 namespace browser_sync {
15
16 using std::string;
17
18 Authenticator::Authenticator(ServerConnectionManager *manager,
19 UserSettings* settings)
20 : server_connection_manager_(manager), settings_(settings) {
21 }
22
23 Authenticator::Authenticator(ServerConnectionManager *manager)
24 : server_connection_manager_(manager), settings_(NULL) {
25 }
26
27 Authenticator::AuthenticationResult Authenticator::Authenticate() {
28 // TODO(sync): Pull and work with saved credentials.
29 return NO_SAVED_CREDENTIALS;
30 }
31
32 Authenticator::AuthenticationResult Authenticator::Authenticate(
33 string username, string password, bool save_credentials) {
34 // TODO(scrub): need to figure out if this routine is used anywhere other than
35 // the test code.
36 GaiaAuthenticator auth_service("ChromiumBrowser", "chromiumsync",
37 "https://www.google.com:443/accounts/ClientLogin");
38 const SignIn signin_type =
39 settings_->RecallSigninType(username, GMAIL_SIGNIN);
40 if (!auth_service.Authenticate(username, password, SAVE_IN_MEMORY_ONLY,
41 true, signin_type)) {
42 return UNSPECIFIC_ERROR_RETURN;
43 }
44 CHECK(!auth_service.auth_token().empty());
45 return AuthenticateToken(auth_service.auth_token());
46 }
47
48 COMPILE_ASSERT(sync_pb::ClientToServerResponse::ERROR_TYPE_MAX == 6,
49 client_to_server_response_errors_changed);
50
51 Authenticator::AuthenticationResult Authenticator::HandleSuccessfulTokenRequest(
52 const sync_pb::UserIdentification* user) {
53 display_email_ = user->has_email() ? user->email() : "";
54 display_name_ = user->has_display_name() ? user->display_name() : "";
55 obfuscated_id_ = user->has_obfuscated_id() ? user->obfuscated_id() : "";
56 return SUCCESS;
57 }
58
59 Authenticator::AuthenticationResult Authenticator::AuthenticateToken(
60 string auth_token) {
61 ClientToServerMessage client_to_server_message;
62 // Used to be required for all requests.
63 client_to_server_message.set_share("");
64 client_to_server_message.set_message_contents(
65 ClientToServerMessage::AUTHENTICATE);
66
67 string tx, rx;
68 client_to_server_message.SerializeToString(&tx);
69 HttpResponse http_response;
70
71 ServerConnectionManager::PostBufferParams params =
72 { tx, &rx, &http_response };
73 if (!server_connection_manager_->PostBufferWithAuth(&params, auth_token)) {
74 LOG(WARNING) << "Error posting from authenticator:" << http_response;
75 return SERVICE_DOWN;
76 }
77 sync_pb::ClientToServerResponse response;
78 if (!response.ParseFromString(rx))
79 return CORRUPT_SERVER_RESPONSE;
80
81 switch (response.error_code()) {
82 case sync_pb::ClientToServerResponse::SUCCESS:
83 if (response.has_authenticate() && response.authenticate().has_user())
84 return HandleSuccessfulTokenRequest(&response.authenticate().user());
85 // TODO:(sync) make this CORRUPT_SERVER_RESPONSE when all servers are
86 // returning user identification at login time.
87 return SUCCESS;
88 case sync_pb::ClientToServerResponse::USER_NOT_ACTIVATED:
89 return USER_NOT_ACTIVATED;
90 case sync_pb::ClientToServerResponse::AUTH_INVALID:
91 case sync_pb::ClientToServerResponse::AUTH_EXPIRED:
92 return BAD_AUTH_TOKEN;
93 // should never happen (no birthday in this request).
94 case sync_pb::ClientToServerResponse::NOT_MY_BIRTHDAY:
95 // should never happen (auth isn't throttled).
96 case sync_pb::ClientToServerResponse::THROTTLED:
97 // should never happen (only for stores).
98 case sync_pb::ClientToServerResponse::ACCESS_DENIED:
99 default:
100 LOG(ERROR) << "Corrupt Server packet received by auth, error code " <<
101 response.error_code();
102 return CORRUPT_SERVER_RESPONSE;
103 }
104 }
105
106 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698