OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <map> | 8 #include <map> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <set> | 10 #include <set> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/string16.h" | 20 #include "base/string16.h" |
21 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
22 #include "base/task.h" | 22 #include "base/task.h" |
23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "chrome/browser/net/chrome_cookie_notification_details.h" | |
25 #include "chrome/browser/net/gaia/token_service.h" | 24 #include "chrome/browser/net/gaia/token_service.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/sync/backend_migrator.h" | 27 #include "chrome/browser/sync/backend_migrator.h" |
29 #include "chrome/browser/sync/engine/configure_reason.h" | 28 #include "chrome/browser/sync/engine/configure_reason.h" |
30 #include "chrome/browser/sync/engine/syncapi.h" | 29 #include "chrome/browser/sync/engine/syncapi.h" |
31 #include "chrome/browser/sync/glue/change_processor.h" | 30 #include "chrome/browser/sync/glue/change_processor.h" |
32 #include "chrome/browser/sync/glue/data_type_controller.h" | 31 #include "chrome/browser/sync/glue/data_type_controller.h" |
33 #include "chrome/browser/sync/glue/data_type_manager.h" | 32 #include "chrome/browser/sync/glue/data_type_manager.h" |
34 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 33 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
35 #include "chrome/browser/sync/js_arg_list.h" | 34 #include "chrome/browser/sync/js_arg_list.h" |
36 #include "chrome/browser/sync/js_event_details.h" | 35 #include "chrome/browser/sync/js_event_details.h" |
37 #include "chrome/browser/sync/profile_sync_factory.h" | 36 #include "chrome/browser/sync/profile_sync_factory.h" |
38 #include "chrome/browser/sync/signin_manager.h" | 37 #include "chrome/browser/sync/signin_manager.h" |
39 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
40 #include "chrome/browser/ui/browser_list.h" | 39 #include "chrome/browser/ui/browser_list.h" |
41 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
42 #include "chrome/common/chrome_version_info.h" | 41 #include "chrome/common/chrome_version_info.h" |
43 #include "chrome/common/net/gaia/gaia_constants.h" | 42 #include "chrome/common/net/gaia/gaia_constants.h" |
44 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
45 #include "chrome/common/time_format.h" | 44 #include "chrome/common/time_format.h" |
46 #include "chrome/common/url_constants.h" | 45 #include "chrome/common/url_constants.h" |
47 #include "content/common/notification_details.h" | 46 #include "content/common/notification_details.h" |
48 #include "content/common/notification_source.h" | 47 #include "content/common/notification_source.h" |
49 #include "content/common/notification_type.h" | 48 #include "content/common/notification_type.h" |
50 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
51 #include "net/base/cookie_monster.h" | |
52 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
53 | 51 |
54 using browser_sync::ChangeProcessor; | 52 using browser_sync::ChangeProcessor; |
55 using browser_sync::DataTypeController; | 53 using browser_sync::DataTypeController; |
56 using browser_sync::DataTypeManager; | 54 using browser_sync::DataTypeManager; |
57 using browser_sync::SyncBackendHost; | 55 using browser_sync::SyncBackendHost; |
58 using sync_api::SyncCredentials; | 56 using sync_api::SyncCredentials; |
59 | 57 |
60 typedef GoogleServiceAuthError AuthError; | 58 typedef GoogleServiceAuthError AuthError; |
61 | 59 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 Source<TokenService>(profile_->GetTokenService())); | 166 Source<TokenService>(profile_->GetTokenService())); |
169 registrar_.Add(this, | 167 registrar_.Add(this, |
170 NotificationType::TOKEN_LOADING_FINISHED, | 168 NotificationType::TOKEN_LOADING_FINISHED, |
171 Source<TokenService>(profile_->GetTokenService())); | 169 Source<TokenService>(profile_->GetTokenService())); |
172 registrar_.Add(this, | 170 registrar_.Add(this, |
173 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, | 171 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, |
174 Source<Profile>(profile_)); | 172 Source<Profile>(profile_)); |
175 registrar_.Add(this, | 173 registrar_.Add(this, |
176 NotificationType::GOOGLE_SIGNIN_FAILED, | 174 NotificationType::GOOGLE_SIGNIN_FAILED, |
177 Source<Profile>(profile_)); | 175 Source<Profile>(profile_)); |
178 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSyncOAuth)) { | |
179 registrar_.Add(this, | |
180 NotificationType::COOKIE_CHANGED, | |
181 Source<Profile>(profile_)); | |
182 } | |
183 } | 176 } |
184 | 177 |
185 void ProfileSyncService::RegisterDataTypeController( | 178 void ProfileSyncService::RegisterDataTypeController( |
186 DataTypeController* data_type_controller) { | 179 DataTypeController* data_type_controller) { |
187 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 180 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
188 data_type_controllers_[data_type_controller->type()] = | 181 data_type_controllers_[data_type_controller->type()] = |
189 data_type_controller; | 182 data_type_controller; |
190 } | 183 } |
191 | 184 |
192 browser_sync::SessionModelAssociator* | 185 browser_sync::SessionModelAssociator* |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 ConfigureDataTypeManager(); | 552 ConfigureDataTypeManager(); |
560 } else if (SetupInProgress()) { | 553 } else if (SetupInProgress()) { |
561 wizard_.Step(SyncSetupWizard::SYNC_EVERYTHING); | 554 wizard_.Step(SyncSetupWizard::SYNC_EVERYTHING); |
562 } else { | 555 } else { |
563 // This should only be hit during integration tests, but there's no good | 556 // This should only be hit during integration tests, but there's no good |
564 // way to assert this. | 557 // way to assert this. |
565 DVLOG(1) << "Setup not complete, no wizard - integration tests?"; | 558 DVLOG(1) << "Setup not complete, no wizard - integration tests?"; |
566 } | 559 } |
567 } | 560 } |
568 | 561 |
569 namespace { | |
570 const char* CauseName(net::CookieMonster::Delegate::ChangeCause cause) { | |
571 switch (cause) { | |
572 case net::CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT: | |
573 return "CHANGE_COOKIE_EXPLICIT"; | |
574 case net::CookieMonster::Delegate::CHANGE_COOKIE_OVERWRITE: | |
575 return "CHANGE_COOKIE_OVERWRITE"; | |
576 case net::CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED: | |
577 return "CHANGE_COOKIE_EXPIRED"; | |
578 case net::CookieMonster::Delegate::CHANGE_COOKIE_EVICTED: | |
579 return "CHANGE_COOKIE_EVICTED"; | |
580 case net::CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE: | |
581 return "CHANGE_COOKIE_EXPIRED_OVERWRITE"; | |
582 default: | |
583 return "<unknown>"; | |
584 } | |
585 } | |
586 } | |
587 | |
588 void ProfileSyncService::OnCookieChanged(Profile* profile, | |
589 ChromeCookieDetails* cookie_details) { | |
590 const net::CookieMonster::CanonicalCookie* canonical_cookie = | |
591 cookie_details->cookie; | |
592 if (canonical_cookie->Name() == "oauth_token") { | |
593 net::CookieMonster::Delegate::ChangeCause cause = cookie_details->cause; | |
594 LOG(INFO) << "COOKIE_CHANGED: removed=" | |
595 << (cookie_details->removed ? "true" : "false") | |
596 << ", cause=" << CauseName(cause) | |
597 << ", Source=" << canonical_cookie->Source() | |
598 << ", Name=" << canonical_cookie->Name() | |
599 << ", Value=" << canonical_cookie->Value() | |
600 << ", Domain=" << canonical_cookie->Domain() | |
601 << ", Path=" << canonical_cookie->Path() | |
602 << ", DoesExpire=" | |
603 << (canonical_cookie->DoesExpire() ? "true" : "false") | |
604 << ", IsPersistent=" | |
605 << (canonical_cookie->IsPersistent() ? "true" : "false") | |
606 << ", IsSecure=" | |
607 << (canonical_cookie->IsSecure() ? "true" : "false") | |
608 << ", IsHttpOnly=" | |
609 << (canonical_cookie->IsHttpOnly() ? "true" : "false") | |
610 << ", IsDomainCookie=" | |
611 << (canonical_cookie->IsDomainCookie() ? "true" : "false") | |
612 << ", IsHostCookie=" | |
613 << (canonical_cookie->IsHostCookie() ? "true" : "false") | |
614 << ", IsExpired=" | |
615 << (const_cast<net::CookieMonster::CanonicalCookie*>( | |
616 canonical_cookie)->IsExpired( | |
617 base::Time::NowFromSystemTime()) | |
618 ? "true" : "false"); | |
619 } | |
620 } | |
621 | |
622 void ProfileSyncService::OnSyncCycleCompleted() { | 562 void ProfileSyncService::OnSyncCycleCompleted() { |
623 UpdateLastSyncedTime(); | 563 UpdateLastSyncedTime(); |
624 VLOG(2) << "Notifying observers sync cycle completed"; | 564 VLOG(2) << "Notifying observers sync cycle completed"; |
625 NotifyObservers(); | 565 NotifyObservers(); |
626 } | 566 } |
627 | 567 |
628 void ProfileSyncService::UpdateAuthErrorState( | 568 void ProfileSyncService::UpdateAuthErrorState( |
629 const GoogleServiceAuthError& error) { | 569 const GoogleServiceAuthError& error) { |
630 last_auth_error_ = error; | 570 last_auth_error_ = error; |
631 // Protect against the in-your-face dialogs that pop out of nowhere. | 571 // Protect against the in-your-face dialogs that pop out of nowhere. |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 case NotificationType::TOKEN_LOADING_FINISHED: { | 1300 case NotificationType::TOKEN_LOADING_FINISHED: { |
1361 // If not in Chrome OS, and we have a username without tokens, | 1301 // If not in Chrome OS, and we have a username without tokens, |
1362 // the user will need to signin again, so sign out. | 1302 // the user will need to signin again, so sign out. |
1363 if (cros_user_.empty() && | 1303 if (cros_user_.empty() && |
1364 !signin_->GetUsername().empty() && | 1304 !signin_->GetUsername().empty() && |
1365 !AreCredentialsAvailable()) { | 1305 !AreCredentialsAvailable()) { |
1366 DisableForUser(); | 1306 DisableForUser(); |
1367 } | 1307 } |
1368 break; | 1308 break; |
1369 } | 1309 } |
1370 case NotificationType::COOKIE_CHANGED: { | |
1371 OnCookieChanged(Source<Profile>(source).ptr(), | |
1372 Details<ChromeCookieDetails>(details).ptr()); | |
1373 break; | |
1374 } | |
1375 default: { | 1310 default: { |
1376 NOTREACHED(); | 1311 NOTREACHED(); |
1377 } | 1312 } |
1378 } | 1313 } |
1379 } | 1314 } |
1380 | 1315 |
1381 void ProfileSyncService::AddObserver(Observer* observer) { | 1316 void ProfileSyncService::AddObserver(Observer* observer) { |
1382 observers_.AddObserver(observer); | 1317 observers_.AddObserver(observer); |
1383 } | 1318 } |
1384 | 1319 |
(...skipping 30 matching lines...) Expand all Loading... |
1415 // is initialized, all enabled data types are consistent with one | 1350 // is initialized, all enabled data types are consistent with one |
1416 // another, and no unrecoverable error has transpired. | 1351 // another, and no unrecoverable error has transpired. |
1417 if (unrecoverable_error_detected_) | 1352 if (unrecoverable_error_detected_) |
1418 return false; | 1353 return false; |
1419 | 1354 |
1420 if (!data_type_manager_.get()) | 1355 if (!data_type_manager_.get()) |
1421 return false; | 1356 return false; |
1422 | 1357 |
1423 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1358 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1424 } | 1359 } |
OLD | NEW |