OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <set> | 10 #include <set> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/base64.h" | 14 #include "base/base64.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
19 #include "base/location.h" | 19 #include "base/location.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
| 23 #include "chrome/browser/p2p_invalidation_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/signin/signin_manager.h" | 25 #include "chrome/browser/signin/signin_manager.h" |
25 #include "chrome/browser/sync/about_sync_util.h" | 26 #include "chrome/browser/sync/about_sync_util.h" |
26 #include "chrome/browser/sync/glue/data_type_controller.h" | 27 #include "chrome/browser/sync/glue/data_type_controller.h" |
27 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
29 #include "sync/internal_api/public/base/progress_marker_map.h" | 30 #include "sync/internal_api/public/base/progress_marker_map.h" |
30 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 31 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
31 #include "sync/internal_api/public/util/sync_string_conversions.h" | 32 #include "sync/internal_api/public/util/sync_string_conversions.h" |
32 | 33 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 95 } |
95 | 96 |
96 bool StateChangeTimeoutEvent::Abort() { | 97 bool StateChangeTimeoutEvent::Abort() { |
97 aborted_ = true; | 98 aborted_ = true; |
98 caller_ = NULL; | 99 caller_ = NULL; |
99 return !did_timeout_; | 100 return !did_timeout_; |
100 } | 101 } |
101 | 102 |
102 ProfileSyncServiceHarness::ProfileSyncServiceHarness( | 103 ProfileSyncServiceHarness::ProfileSyncServiceHarness( |
103 Profile* profile, | 104 Profile* profile, |
| 105 P2PInvalidationService* p2p_invalidation_service, |
104 const std::string& username, | 106 const std::string& username, |
105 const std::string& password) | 107 const std::string& password) |
106 : waiting_for_encryption_type_(syncer::UNSPECIFIED), | 108 : waiting_for_encryption_type_(syncer::UNSPECIFIED), |
107 wait_state_(INITIAL_WAIT_STATE), | 109 wait_state_(INITIAL_WAIT_STATE), |
108 profile_(profile), | 110 profile_(profile), |
109 service_(NULL), | 111 service_(NULL), |
| 112 p2p_invalidation_service_(p2p_invalidation_service), |
110 progress_marker_partner_(NULL), | 113 progress_marker_partner_(NULL), |
111 username_(username), | 114 username_(username), |
112 password_(password), | 115 password_(password), |
113 profile_debug_name_(profile->GetDebugName()), | 116 profile_debug_name_(profile->GetDebugName()), |
114 waiting_for_status_change_(false) { | 117 waiting_for_status_change_(false) { |
| 118 DCHECK(p2p_invalidation_service); |
115 if (IsSyncAlreadySetup()) { | 119 if (IsSyncAlreadySetup()) { |
116 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 120 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
117 profile_); | 121 profile_); |
118 service_->AddObserver(this); | 122 service_->AddObserver(this); |
119 ignore_result(TryListeningToMigrationEvents()); | 123 ignore_result(TryListeningToMigrationEvents()); |
120 wait_state_ = FULLY_SYNCED; | 124 wait_state_ = FULLY_SYNCED; |
121 } | 125 } |
122 } | 126 } |
123 | 127 |
124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { | 128 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { |
125 if (service_->HasObserver(this)) | 129 if (service_->HasObserver(this)) |
126 service_->RemoveObserver(this); | 130 service_->RemoveObserver(this); |
127 } | 131 } |
128 | 132 |
129 // static | 133 // static |
130 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( | 134 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( |
131 Profile* profile) { | 135 Profile* profile, P2PInvalidationService *p2p_invalidation_service) { |
132 ProfileSyncServiceFactory* f = ProfileSyncServiceFactory::GetInstance(); | 136 ProfileSyncServiceFactory* f = ProfileSyncServiceFactory::GetInstance(); |
133 if (!f->HasProfileSyncService(profile)) { | 137 if (!f->HasProfileSyncService(profile)) { |
134 NOTREACHED() << "Profile has never signed into sync."; | 138 NOTREACHED() << "Profile has never signed into sync."; |
135 return NULL; | 139 return NULL; |
136 } | 140 } |
137 return new ProfileSyncServiceHarness(profile, "", ""); | 141 return new ProfileSyncServiceHarness(profile, |
| 142 p2p_invalidation_service, |
| 143 "", |
| 144 ""); |
138 } | 145 } |
139 | 146 |
140 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, | 147 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, |
141 const std::string& password) { | 148 const std::string& password) { |
142 username_ = username; | 149 username_ = username; |
143 password_ = password; | 150 password_ = password; |
144 } | 151 } |
145 | 152 |
146 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { | 153 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { |
147 return ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 154 return ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // classes using the the UI message loop. Defer to their handling. | 464 // classes using the the UI message loop. Defer to their handling. |
458 break; | 465 break; |
459 } | 466 } |
460 return original_wait_state != wait_state_; | 467 return original_wait_state != wait_state_; |
461 } | 468 } |
462 | 469 |
463 void ProfileSyncServiceHarness::OnStateChanged() { | 470 void ProfileSyncServiceHarness::OnStateChanged() { |
464 RunStateChangeMachine(); | 471 RunStateChangeMachine(); |
465 } | 472 } |
466 | 473 |
| 474 void ProfileSyncServiceHarness::OnSyncCycleCompleted() { |
| 475 // Integration tests still use p2p notifications. |
| 476 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| 477 bool is_notifiable_commit = |
| 478 (snap.model_neutral_state().num_successful_commits > 0); |
| 479 if (is_notifiable_commit) { |
| 480 const syncer::ObjectIdInvalidationMap& invalidation_map = |
| 481 ModelTypeInvalidationMapToObjectIdInvalidationMap( |
| 482 snap.source().types); |
| 483 p2p_invalidation_service_->SendInvalidation(invalidation_map); |
| 484 } |
| 485 |
| 486 OnStateChanged(); |
| 487 } |
| 488 |
467 void ProfileSyncServiceHarness::OnMigrationStateChange() { | 489 void ProfileSyncServiceHarness::OnMigrationStateChange() { |
468 // Update migration state. | 490 // Update migration state. |
469 if (HasPendingBackendMigration()) { | 491 if (HasPendingBackendMigration()) { |
470 // Merge current pending migration types into | 492 // Merge current pending migration types into |
471 // |pending_migration_types_|. | 493 // |pending_migration_types_|. |
472 pending_migration_types_.PutAll( | 494 pending_migration_types_.PutAll( |
473 service()->GetBackendMigratorForTest()-> | 495 service()->GetBackendMigratorForTest()-> |
474 GetPendingMigrationTypesForTest()); | 496 GetPendingMigrationTypesForTest()); |
475 DVLOG(1) << profile_debug_name_ << ": new pending migration types " | 497 DVLOG(1) << profile_debug_name_ << ": new pending migration types " |
476 << syncer::ModelTypeSetToString(pending_migration_types_); | 498 << syncer::ModelTypeSetToString(pending_migration_types_); |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 | 1154 |
1133 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1155 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
1134 scoped_ptr<DictionaryValue> value( | 1156 scoped_ptr<DictionaryValue> value( |
1135 sync_ui_util::ConstructAboutInformation(service_)); | 1157 sync_ui_util::ConstructAboutInformation(service_)); |
1136 std::string service_status; | 1158 std::string service_status; |
1137 base::JSONWriter::WriteWithOptions(value.get(), | 1159 base::JSONWriter::WriteWithOptions(value.get(), |
1138 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1160 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
1139 &service_status); | 1161 &service_status); |
1140 return service_status; | 1162 return service_status; |
1141 } | 1163 } |
OLD | NEW |