OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 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 | 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 | 4 |
5 #include "chrome/browser/sync/engine/auth_watcher.h" | 5 #include "chrome/browser/sync/engine/auth_watcher.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/sync/engine/all_status.h" | 9 #include "chrome/browser/sync/engine/all_status.h" |
10 #include "chrome/browser/sync/engine/authenticator.h" | 10 #include "chrome/browser/sync/engine/authenticator.h" |
11 #include "chrome/browser/sync/engine/net/gaia_authenticator.h" | 11 #include "chrome/browser/sync/engine/net/gaia_authenticator.h" |
12 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 12 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
13 #include "chrome/browser/sync/notifier/listener/talk_mediator.h" | 13 #include "chrome/browser/sync/notifier/listener/talk_mediator.h" |
14 #include "chrome/browser/sync/syncable/directory_manager.h" | 14 #include "chrome/browser/sync/syncable/directory_manager.h" |
15 #include "chrome/browser/sync/syncable/syncable.h" | 15 #include "chrome/browser/sync/syncable/syncable.h" |
16 #include "chrome/browser/sync/util/character_set_converters.h" | |
17 #include "chrome/browser/sync/util/event_sys-inl.h" | 16 #include "chrome/browser/sync/util/event_sys-inl.h" |
18 #include "chrome/browser/sync/util/user_settings.h" | 17 #include "chrome/browser/sync/util/user_settings.h" |
19 | 18 |
20 // How authentication happens: | 19 // How authentication happens: |
21 // | 20 // |
22 // Kick Off: | 21 // Kick Off: |
23 // The sync API looks to see if the user's name and | 22 // The sync API looks to see if the user's name and |
24 // password are stored. If so, it calls authwatcher.Authenticate() with | 23 // password are stored. If so, it calls authwatcher.Authenticate() with |
25 // them. Otherwise it fires an error event. | 24 // them. Otherwise it fires an error event. |
26 // | 25 // |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 gaia_email; | 114 gaia_email; |
116 } | 115 } |
117 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; | 116 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; |
118 gaia_->SetUsername(email); | 117 gaia_->SetUsername(email); |
119 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY); | 118 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY); |
120 const bool was_authenticated = NOT_AUTHENTICATED != status_; | 119 const bool was_authenticated = NOT_AUTHENTICATED != status_; |
121 switch (result) { | 120 switch (result) { |
122 case Authenticator::SUCCESS: | 121 case Authenticator::SUCCESS: |
123 { | 122 { |
124 status_ = GAIA_AUTHENTICATED; | 123 status_ = GAIA_AUTHENTICATED; |
125 PathString share_name; | 124 const PathString& share_name = email; |
126 CHECK(AppendUTF8ToPathString(email.data(), email.size(), &share_name)); | |
127 user_settings_->SwitchUser(email); | 125 user_settings_->SwitchUser(email); |
128 | 126 |
129 // Set the authentication token for notifications | 127 // Set the authentication token for notifications |
130 talk_mediator_->SetAuthToken(email, auth_token); | 128 talk_mediator_->SetAuthToken(email, auth_token); |
131 scm_->set_auth_token(auth_token); | 129 scm_->set_auth_token(auth_token); |
132 | 130 |
133 if (!was_authenticated) | 131 if (!was_authenticated) |
134 LoadDirectoryListAndOpen(share_name); | 132 LoadDirectoryListAndOpen(share_name); |
135 NotifyAuthSucceeded(email); | 133 NotifyAuthSucceeded(email); |
136 return; | 134 return; |
(...skipping 21 matching lines...) Expand all Loading... |
158 NotifyListeners(&event); | 156 NotifyListeners(&event); |
159 } | 157 } |
160 | 158 |
161 bool AuthWatcher::AuthenticateLocally(string email) { | 159 bool AuthWatcher::AuthenticateLocally(string email) { |
162 DCHECK_EQ(MessageLoop::current(), message_loop()); | 160 DCHECK_EQ(MessageLoop::current(), message_loop()); |
163 user_settings_->GetEmailForSignin(&email); | 161 user_settings_->GetEmailForSignin(&email); |
164 if (file_util::PathExists(FilePath(dirman_->GetSyncDataDatabasePath()))) { | 162 if (file_util::PathExists(FilePath(dirman_->GetSyncDataDatabasePath()))) { |
165 gaia_->SetUsername(email); | 163 gaia_->SetUsername(email); |
166 status_ = LOCALLY_AUTHENTICATED; | 164 status_ = LOCALLY_AUTHENTICATED; |
167 user_settings_->SwitchUser(email); | 165 user_settings_->SwitchUser(email); |
168 PathString share_name; | 166 const PathString& share_name = email; |
169 CHECK(AppendUTF8ToPathString(email.data(), email.size(), &share_name)); | |
170 LoadDirectoryListAndOpen(share_name); | 167 LoadDirectoryListAndOpen(share_name); |
171 NotifyAuthSucceeded(email); | 168 NotifyAuthSucceeded(email); |
172 return true; | 169 return true; |
173 } else { | 170 } else { |
174 return false; | 171 return false; |
175 } | 172 } |
176 } | 173 } |
177 | 174 |
178 bool AuthWatcher::AuthenticateLocally(string email, const string& password) { | 175 bool AuthWatcher::AuthenticateLocally(string email, const string& password) { |
179 DCHECK_EQ(MessageLoop::current(), message_loop()); | 176 DCHECK_EQ(MessageLoop::current(), message_loop()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 string AuthWatcher::email() const { | 326 string AuthWatcher::email() const { |
330 return gaia_->email(); | 327 return gaia_->email(); |
331 } | 328 } |
332 | 329 |
333 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { | 330 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { |
334 event->trigger = current_attempt_trigger_; | 331 event->trigger = current_attempt_trigger_; |
335 channel_->NotifyListeners(*event); | 332 channel_->NotifyListeners(*event); |
336 } | 333 } |
337 | 334 |
338 } // namespace browser_sync | 335 } // namespace browser_sync |
OLD | NEW |