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" |
24 #include "chrome/browser/net/gaia/token_service.h" | 25 #include "chrome/browser/net/gaia/token_service.h" |
25 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/sync/backend_migrator.h" | 28 #include "chrome/browser/sync/backend_migrator.h" |
28 #include "chrome/browser/sync/engine/configure_reason.h" | 29 #include "chrome/browser/sync/engine/configure_reason.h" |
29 #include "chrome/browser/sync/engine/syncapi.h" | 30 #include "chrome/browser/sync/engine/syncapi.h" |
30 #include "chrome/browser/sync/glue/change_processor.h" | 31 #include "chrome/browser/sync/glue/change_processor.h" |
31 #include "chrome/browser/sync/glue/data_type_controller.h" | 32 #include "chrome/browser/sync/glue/data_type_controller.h" |
32 #include "chrome/browser/sync/glue/data_type_manager.h" | 33 #include "chrome/browser/sync/glue/data_type_manager.h" |
33 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 34 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
34 #include "chrome/browser/sync/js_arg_list.h" | 35 #include "chrome/browser/sync/js_arg_list.h" |
35 #include "chrome/browser/sync/js_event_details.h" | 36 #include "chrome/browser/sync/js_event_details.h" |
36 #include "chrome/browser/sync/profile_sync_factory.h" | 37 #include "chrome/browser/sync/profile_sync_factory.h" |
37 #include "chrome/browser/sync/signin_manager.h" | 38 #include "chrome/browser/sync/signin_manager.h" |
38 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
39 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
40 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
41 #include "chrome/common/chrome_version_info.h" | 42 #include "chrome/common/chrome_version_info.h" |
42 #include "chrome/common/net/gaia/gaia_constants.h" | 43 #include "chrome/common/net/gaia/gaia_constants.h" |
43 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
44 #include "chrome/common/time_format.h" | 45 #include "chrome/common/time_format.h" |
45 #include "chrome/common/url_constants.h" | 46 #include "chrome/common/url_constants.h" |
46 #include "content/common/notification_details.h" | 47 #include "content/common/notification_details.h" |
47 #include "content/common/notification_source.h" | 48 #include "content/common/notification_source.h" |
48 #include "content/common/notification_type.h" | 49 #include "content/common/notification_type.h" |
49 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
| 51 #include "net/base/cookie_monster.h" |
50 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
51 | 53 |
52 using browser_sync::ChangeProcessor; | 54 using browser_sync::ChangeProcessor; |
53 using browser_sync::DataTypeController; | 55 using browser_sync::DataTypeController; |
54 using browser_sync::DataTypeManager; | 56 using browser_sync::DataTypeManager; |
55 using browser_sync::SyncBackendHost; | 57 using browser_sync::SyncBackendHost; |
56 using sync_api::SyncCredentials; | 58 using sync_api::SyncCredentials; |
57 | 59 |
58 typedef GoogleServiceAuthError AuthError; | 60 typedef GoogleServiceAuthError AuthError; |
59 | 61 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 Source<TokenService>(profile_->GetTokenService())); | 168 Source<TokenService>(profile_->GetTokenService())); |
167 registrar_.Add(this, | 169 registrar_.Add(this, |
168 NotificationType::TOKEN_LOADING_FINISHED, | 170 NotificationType::TOKEN_LOADING_FINISHED, |
169 Source<TokenService>(profile_->GetTokenService())); | 171 Source<TokenService>(profile_->GetTokenService())); |
170 registrar_.Add(this, | 172 registrar_.Add(this, |
171 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, | 173 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, |
172 Source<Profile>(profile_)); | 174 Source<Profile>(profile_)); |
173 registrar_.Add(this, | 175 registrar_.Add(this, |
174 NotificationType::GOOGLE_SIGNIN_FAILED, | 176 NotificationType::GOOGLE_SIGNIN_FAILED, |
175 Source<Profile>(profile_)); | 177 Source<Profile>(profile_)); |
| 178 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSyncOAuth)) { |
| 179 registrar_.Add(this, |
| 180 NotificationType::COOKIE_CHANGED, |
| 181 Source<Profile>(profile_)); |
| 182 } |
176 } | 183 } |
177 | 184 |
178 void ProfileSyncService::RegisterDataTypeController( | 185 void ProfileSyncService::RegisterDataTypeController( |
179 DataTypeController* data_type_controller) { | 186 DataTypeController* data_type_controller) { |
180 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 187 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
181 data_type_controllers_[data_type_controller->type()] = | 188 data_type_controllers_[data_type_controller->type()] = |
182 data_type_controller; | 189 data_type_controller; |
183 } | 190 } |
184 | 191 |
185 browser_sync::SessionModelAssociator* | 192 browser_sync::SessionModelAssociator* |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 ConfigureDataTypeManager(); | 559 ConfigureDataTypeManager(); |
553 } else if (SetupInProgress()) { | 560 } else if (SetupInProgress()) { |
554 wizard_.Step(SyncSetupWizard::SYNC_EVERYTHING); | 561 wizard_.Step(SyncSetupWizard::SYNC_EVERYTHING); |
555 } else { | 562 } else { |
556 // This should only be hit during integration tests, but there's no good | 563 // This should only be hit during integration tests, but there's no good |
557 // way to assert this. | 564 // way to assert this. |
558 DVLOG(1) << "Setup not complete, no wizard - integration tests?"; | 565 DVLOG(1) << "Setup not complete, no wizard - integration tests?"; |
559 } | 566 } |
560 } | 567 } |
561 | 568 |
| 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 |
562 void ProfileSyncService::OnSyncCycleCompleted() { | 622 void ProfileSyncService::OnSyncCycleCompleted() { |
563 UpdateLastSyncedTime(); | 623 UpdateLastSyncedTime(); |
564 VLOG(2) << "Notifying observers sync cycle completed"; | 624 VLOG(2) << "Notifying observers sync cycle completed"; |
565 NotifyObservers(); | 625 NotifyObservers(); |
566 } | 626 } |
567 | 627 |
568 void ProfileSyncService::UpdateAuthErrorState( | 628 void ProfileSyncService::UpdateAuthErrorState( |
569 const GoogleServiceAuthError& error) { | 629 const GoogleServiceAuthError& error) { |
570 last_auth_error_ = error; | 630 last_auth_error_ = error; |
571 // Protect against the in-your-face dialogs that pop out of nowhere. | 631 // 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... |
1300 case NotificationType::TOKEN_LOADING_FINISHED: { | 1360 case NotificationType::TOKEN_LOADING_FINISHED: { |
1301 // If not in Chrome OS, and we have a username without tokens, | 1361 // If not in Chrome OS, and we have a username without tokens, |
1302 // the user will need to signin again, so sign out. | 1362 // the user will need to signin again, so sign out. |
1303 if (cros_user_.empty() && | 1363 if (cros_user_.empty() && |
1304 !signin_->GetUsername().empty() && | 1364 !signin_->GetUsername().empty() && |
1305 !AreCredentialsAvailable()) { | 1365 !AreCredentialsAvailable()) { |
1306 DisableForUser(); | 1366 DisableForUser(); |
1307 } | 1367 } |
1308 break; | 1368 break; |
1309 } | 1369 } |
| 1370 case NotificationType::COOKIE_CHANGED: { |
| 1371 OnCookieChanged(Source<Profile>(source).ptr(), |
| 1372 Details<ChromeCookieDetails>(details).ptr()); |
| 1373 break; |
| 1374 } |
1310 default: { | 1375 default: { |
1311 NOTREACHED(); | 1376 NOTREACHED(); |
1312 } | 1377 } |
1313 } | 1378 } |
1314 } | 1379 } |
1315 | 1380 |
1316 void ProfileSyncService::AddObserver(Observer* observer) { | 1381 void ProfileSyncService::AddObserver(Observer* observer) { |
1317 observers_.AddObserver(observer); | 1382 observers_.AddObserver(observer); |
1318 } | 1383 } |
1319 | 1384 |
(...skipping 30 matching lines...) Expand all Loading... |
1350 // is initialized, all enabled data types are consistent with one | 1415 // is initialized, all enabled data types are consistent with one |
1351 // another, and no unrecoverable error has transpired. | 1416 // another, and no unrecoverable error has transpired. |
1352 if (unrecoverable_error_detected_) | 1417 if (unrecoverable_error_detected_) |
1353 return false; | 1418 return false; |
1354 | 1419 |
1355 if (!data_type_manager_.get()) | 1420 if (!data_type_manager_.get()) |
1356 return false; | 1421 return false; |
1357 | 1422 |
1358 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1423 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1359 } | 1424 } |
OLD | NEW |