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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 AuthWatcher::AuthWatcher(DirectoryManager* dirman, | 44 AuthWatcher::AuthWatcher(DirectoryManager* dirman, |
45 ServerConnectionManager* scm, | 45 ServerConnectionManager* scm, |
46 AllStatus* allstatus, | 46 AllStatus* allstatus, |
47 const string& user_agent, | 47 const string& user_agent, |
48 const string& service_id, | 48 const string& service_id, |
49 const string& gaia_url, | 49 const string& gaia_url, |
50 UserSettings* user_settings, | 50 UserSettings* user_settings, |
51 GaiaAuthenticator* gaia_auth, | 51 GaiaAuthenticator* gaia_auth, |
52 TalkMediator* talk_mediator) | 52 TalkMediator* talk_mediator) |
53 : dirman_(dirman), | 53 : gaia_(gaia_auth), |
| 54 dirman_(dirman), |
54 scm_(scm), | 55 scm_(scm), |
55 allstatus_(allstatus), | 56 allstatus_(allstatus), |
56 status_(NOT_AUTHENTICATED), | 57 status_(NOT_AUTHENTICATED), |
| 58 user_settings_(user_settings), |
| 59 talk_mediator_(talk_mediator), |
57 thread_handle_valid_(false), | 60 thread_handle_valid_(false), |
58 authenticating_now_(false), | 61 authenticating_now_(false), |
59 current_attempt_trigger_(AuthWatcherEvent::USER_INITIATED), | 62 current_attempt_trigger_(AuthWatcherEvent::USER_INITIATED) { |
60 user_settings_(user_settings), | |
61 gaia_(gaia_auth), | |
62 talk_mediator_(talk_mediator) { | |
63 connmgr_hookup_.reset( | 63 connmgr_hookup_.reset( |
64 NewEventListenerHookup(scm->channel(), this, | 64 NewEventListenerHookup(scm->channel(), this, |
65 &AuthWatcher::HandleServerConnectionEvent)); | 65 &AuthWatcher::HandleServerConnectionEvent)); |
66 AuthWatcherEvent done = { AuthWatcherEvent::AUTHWATCHER_DESTROYED }; | 66 AuthWatcherEvent done = { AuthWatcherEvent::AUTHWATCHER_DESTROYED }; |
67 channel_.reset(new Channel(done)); | 67 channel_.reset(new Channel(done)); |
68 } | 68 } |
69 | 69 |
70 void* AuthWatcher::AuthenticationThreadStartRoutine(void* arg) { | 70 void* AuthWatcher::AuthenticationThreadStartRoutine(void* arg) { |
71 ThreadParams* args = reinterpret_cast<ThreadParams*>(arg); | 71 ThreadParams* args = reinterpret_cast<ThreadParams*>(arg); |
72 return args->self->AuthenticationThreadMain(args); | 72 return args->self->AuthenticationThreadMain(args); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened) | 183 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened) |
184 return true; | 184 return true; |
185 } | 185 } |
186 CHECK(event.what_happened != AuthWatcherEvent::ILLEGAL_VALUE); | 186 CHECK(event.what_happened != AuthWatcherEvent::ILLEGAL_VALUE); |
187 NotifyListeners(&event); | 187 NotifyListeners(&event); |
188 return true; | 188 return true; |
189 } | 189 } |
190 | 190 |
191 bool AuthWatcher::AuthenticateLocally(string email) { | 191 bool AuthWatcher::AuthenticateLocally(string email) { |
192 user_settings_->GetEmailForSignin(&email); | 192 user_settings_->GetEmailForSignin(&email); |
193 if (file_util::PathExists(dirman_->GetSyncDataDatabasePath())) { | 193 if (file_util::PathExists(FilePath(dirman_->GetSyncDataDatabasePath()))) { |
194 gaia_->SetUsername(email); | 194 gaia_->SetUsername(email); |
195 status_ = LOCALLY_AUTHENTICATED; | 195 status_ = LOCALLY_AUTHENTICATED; |
196 user_settings_->SwitchUser(email); | 196 user_settings_->SwitchUser(email); |
197 PathString share_name; | 197 PathString share_name; |
198 CHECK(AppendUTF8ToPathString(email.data(), email.size(), &share_name)); | 198 CHECK(AppendUTF8ToPathString(email.data(), email.size(), &share_name)); |
199 LoadDirectoryListAndOpen(share_name); | 199 LoadDirectoryListAndOpen(share_name); |
200 NotifyAuthSucceeded(email); | 200 NotifyAuthSucceeded(email); |
201 return true; | 201 return true; |
202 } else { | 202 } else { |
203 return false; | 203 return false; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 string AuthWatcher::email() const { | 410 string AuthWatcher::email() const { |
411 return gaia_->email(); | 411 return gaia_->email(); |
412 } | 412 } |
413 | 413 |
414 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { | 414 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { |
415 event->trigger = current_attempt_trigger_; | 415 event->trigger = current_attempt_trigger_; |
416 channel_->NotifyListeners(*event); | 416 channel_->NotifyListeners(*event); |
417 } | 417 } |
418 | 418 |
419 } // namespace browser_sync | 419 } // namespace browser_sync |
OLD | NEW |