| 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/test_profile_sync_service.h" | 5 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/signin/signin_manager.h" | 7 #include "chrome/browser/signin/signin_manager.h" |
| 8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 9 #include "chrome/browser/sync/glue/data_type_controller.h" | 9 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 10 #include "chrome/browser/sync/glue/sync_backend_host.h" | 10 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 11 #include "chrome/browser/sync/profile_sync_components_factory.h" | 11 #include "chrome/browser/sync/profile_sync_components_factory.h" |
| 12 #include "chrome/browser/sync/test/test_http_bridge_factory.h" | 12 #include "chrome/browser/sync/test/test_http_bridge_factory.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
| 15 #include "sync/internal_api/public/user_share.h" | 15 #include "sync/internal_api/public/user_share.h" |
| 16 #include "sync/js/js_reply_handler.h" | 16 #include "sync/js/js_reply_handler.h" |
| 17 #include "sync/protocol/encryption.pb.h" | 17 #include "sync/protocol/encryption.pb.h" |
| 18 #include "sync/syncable/directory.h" | 18 #include "sync/syncable/directory.h" |
| 19 | 19 |
| 20 using csync::ModelSafeRoutingInfo; | 20 using syncer::ModelSafeRoutingInfo; |
| 21 using csync::sessions::ModelNeutralState; | 21 using syncer::sessions::ModelNeutralState; |
| 22 using csync::sessions::SyncSessionSnapshot; | 22 using syncer::sessions::SyncSessionSnapshot; |
| 23 using csync::sessions::SyncSourceInfo; | 23 using syncer::sessions::SyncSourceInfo; |
| 24 using csync::UserShare; | 24 using syncer::UserShare; |
| 25 using syncable::Directory; | 25 using syncable::Directory; |
| 26 | 26 |
| 27 namespace browser_sync { | 27 namespace browser_sync { |
| 28 | 28 |
| 29 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( | 29 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
| 30 Profile* profile, | 30 Profile* profile, |
| 31 const base::WeakPtr<SyncPrefs>& sync_prefs, | 31 const base::WeakPtr<SyncPrefs>& sync_prefs, |
| 32 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, | 32 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, |
| 33 bool set_initial_sync_ended_on_init, | 33 bool set_initial_sync_ended_on_init, |
| 34 bool synchronous_init, | 34 bool synchronous_init, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 syncable::ModelTypePayloadMap download_progress_markers; | 51 syncable::ModelTypePayloadMap download_progress_markers; |
| 52 HandleSyncCycleCompletedOnFrontendLoop( | 52 HandleSyncCycleCompletedOnFrontendLoop( |
| 53 SyncSessionSnapshot( | 53 SyncSessionSnapshot( |
| 54 ModelNeutralState(), false, sync_ended, download_progress_markers, | 54 ModelNeutralState(), false, sync_ended, download_progress_markers, |
| 55 false, false, 0, 0, 0, 0, SyncSourceInfo(), false, 0, | 55 false, false, 0, 0, 0, 0, SyncSourceInfo(), false, 0, |
| 56 base::Time::Now(), false)); | 56 base::Time::Now(), false)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 | 60 |
| 61 csync::HttpPostProviderFactory* MakeTestHttpBridgeFactory() { | 61 syncer::HttpPostProviderFactory* MakeTestHttpBridgeFactory() { |
| 62 return new browser_sync::TestHttpBridgeFactory(); | 62 return new browser_sync::TestHttpBridgeFactory(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 void SyncBackendHostForProfileSyncTest::InitCore( | 67 void SyncBackendHostForProfileSyncTest::InitCore( |
| 68 const DoInitializeOptions& options) { | 68 const DoInitializeOptions& options) { |
| 69 DoInitializeOptions test_options = options; | 69 DoInitializeOptions test_options = options; |
| 70 test_options.make_http_bridge_factory_fn = | 70 test_options.make_http_bridge_factory_fn = |
| 71 base::Bind(&MakeTestHttpBridgeFactory); | 71 base::Bind(&MakeTestHttpBridgeFactory); |
| 72 test_options.credentials.email = "testuser@gmail.com"; | 72 test_options.credentials.email = "testuser@gmail.com"; |
| 73 test_options.credentials.sync_token = "token"; | 73 test_options.credentials.sync_token = "token"; |
| 74 test_options.restored_key_for_bootstrapping = ""; | 74 test_options.restored_key_for_bootstrapping = ""; |
| 75 test_options.testing_mode = | 75 test_options.testing_mode = |
| 76 use_real_database_ ? csync::SyncManager::TEST_ON_DISK | 76 use_real_database_ ? syncer::SyncManager::TEST_ON_DISK |
| 77 : csync::SyncManager::TEST_IN_MEMORY; | 77 : syncer::SyncManager::TEST_IN_MEMORY; |
| 78 SyncBackendHost::InitCore(test_options); | 78 SyncBackendHost::InitCore(test_options); |
| 79 // TODO(akalin): Figure out a better way to do this. | 79 // TODO(akalin): Figure out a better way to do this. |
| 80 if (synchronous_init_) { | 80 if (synchronous_init_) { |
| 81 // The SyncBackend posts a task to the current loop when | 81 // The SyncBackend posts a task to the current loop when |
| 82 // initialization completes. | 82 // initialization completes. |
| 83 MessageLoop::current()->Run(); | 83 MessageLoop::current()->Run(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void SyncBackendHostForProfileSyncTest::StartConfiguration( | 87 void SyncBackendHostForProfileSyncTest::StartConfiguration( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations( | 104 void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations( |
| 105 ProfileMock* profile) { | 105 ProfileMock* profile) { |
| 106 EXPECT_CALL(*profile, GetHistoryService(testing::_)). | 106 EXPECT_CALL(*profile, GetHistoryService(testing::_)). |
| 107 WillOnce(testing::Return((HistoryService*)NULL)); | 107 WillOnce(testing::Return((HistoryService*)NULL)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace browser_sync | 110 } // namespace browser_sync |
| 111 | 111 |
| 112 csync::TestIdFactory* TestProfileSyncService::id_factory() { | 112 syncer::TestIdFactory* TestProfileSyncService::id_factory() { |
| 113 return &id_factory_; | 113 return &id_factory_; |
| 114 } | 114 } |
| 115 | 115 |
| 116 browser_sync::SyncBackendHostForProfileSyncTest* | 116 browser_sync::SyncBackendHostForProfileSyncTest* |
| 117 TestProfileSyncService::GetBackendForTest() { | 117 TestProfileSyncService::GetBackendForTest() { |
| 118 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( | 118 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( |
| 119 ProfileSyncService::GetBackendForTest()); | 119 ProfileSyncService::GetBackendForTest()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 TestProfileSyncService::TestProfileSyncService( | 122 TestProfileSyncService::TestProfileSyncService( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 148 Directory* directory = user_share->directory.get(); | 148 Directory* directory = user_share->directory.get(); |
| 149 | 149 |
| 150 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 150 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 151 i < syncable::MODEL_TYPE_COUNT; ++i) { | 151 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 152 directory->set_initial_sync_ended_for_type( | 152 directory->set_initial_sync_ended_for_type( |
| 153 syncable::ModelTypeFromInt(i), true); | 153 syncable::ModelTypeFromInt(i), true); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 void TestProfileSyncService::OnBackendInitialized( | 157 void TestProfileSyncService::OnBackendInitialized( |
| 158 const csync::WeakHandle<csync::JsBackend>& backend, | 158 const syncer::WeakHandle<syncer::JsBackend>& backend, |
| 159 bool success) { | 159 bool success) { |
| 160 bool send_passphrase_required = false; | 160 bool send_passphrase_required = false; |
| 161 if (success) { | 161 if (success) { |
| 162 // Set this so below code can access GetUserShare(). | 162 // Set this so below code can access GetUserShare(). |
| 163 backend_initialized_ = true; | 163 backend_initialized_ = true; |
| 164 | 164 |
| 165 // Set up any nodes the test wants around before model association. | 165 // Set up any nodes the test wants around before model association. |
| 166 if (!callback_.is_null()) { | 166 if (!callback_.is_null()) { |
| 167 callback_.Run(); | 167 callback_.Run(); |
| 168 callback_.Reset(); | 168 callback_.Reset(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 183 // syncer) is a decryption attempt, which will fail the first time. | 183 // syncer) is a decryption attempt, which will fail the first time. |
| 184 send_passphrase_required = true; | 184 send_passphrase_required = true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 SetInitialSyncEndedForAllTypes(); | 187 SetInitialSyncEndedForAllTypes(); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 ProfileSyncService::OnBackendInitialized(backend, success); | 191 ProfileSyncService::OnBackendInitialized(backend, success); |
| 192 if (success && send_passphrase_required) | 192 if (success && send_passphrase_required) |
| 193 OnPassphraseRequired(csync::REASON_DECRYPTION, sync_pb::EncryptedData()); | 193 OnPassphraseRequired(syncer::REASON_DECRYPTION, sync_pb::EncryptedData()); |
| 194 | 194 |
| 195 // TODO(akalin): Figure out a better way to do this. | 195 // TODO(akalin): Figure out a better way to do this. |
| 196 if (synchronous_backend_initialization_) { | 196 if (synchronous_backend_initialization_) { |
| 197 MessageLoop::current()->Quit(); | 197 MessageLoop::current()->Quit(); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 void TestProfileSyncService::Observe( | 201 void TestProfileSyncService::Observe( |
| 202 int type, | 202 int type, |
| 203 const content::NotificationSource& source, | 203 const content::NotificationSource& source, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 225 void TestProfileSyncService::CreateBackend() { | 225 void TestProfileSyncService::CreateBackend() { |
| 226 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | 226 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
| 227 profile(), | 227 profile(), |
| 228 sync_prefs_.AsWeakPtr(), | 228 sync_prefs_.AsWeakPtr(), |
| 229 invalidator_storage_.AsWeakPtr(), | 229 invalidator_storage_.AsWeakPtr(), |
| 230 set_initial_sync_ended_on_init_, | 230 set_initial_sync_ended_on_init_, |
| 231 synchronous_backend_initialization_, | 231 synchronous_backend_initialization_, |
| 232 fail_initial_download_, | 232 fail_initial_download_, |
| 233 use_real_database_)); | 233 use_real_database_)); |
| 234 } | 234 } |
| OLD | NEW |