OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/sync/driver/glue/sync_backend_host_core.h" | 5 #include "components/sync/driver/glue/sync_backend_host_core.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 DoDestroySyncManager(STOP_SYNC); | 107 DoDestroySyncManager(STOP_SYNC); |
108 host_.Call(FROM_HERE, | 108 host_.Call(FROM_HERE, |
109 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); | 109 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); |
110 return; | 110 return; |
111 } | 111 } |
112 | 112 |
113 // Register for encryption related changes now. We have to do this before | 113 // Register for encryption related changes now. We have to do this before |
114 // the initializing downloading control types or initializing the encryption | 114 // the initializing downloading control types or initializing the encryption |
115 // handler in order to receive notifications triggered during encryption | 115 // handler in order to receive notifications triggered during encryption |
116 // startup. | 116 // startup. |
117 sync_manager_->GetEncryptionHandler()->AddObserver(this); | 117 DCHECK(encryption_observer_proxy_); |
| 118 sync_manager_->GetEncryptionHandler()->AddObserver( |
| 119 encryption_observer_proxy_.get()); |
118 | 120 |
119 // Sync manager initialization is complete, so we can schedule recurring | 121 // Sync manager initialization is complete, so we can schedule recurring |
120 // SaveChanges. | 122 // SaveChanges. |
121 base::ThreadTaskRunnerHandle::Get()->PostTask( | 123 base::ThreadTaskRunnerHandle::Get()->PostTask( |
122 FROM_HERE, base::Bind(&SyncBackendHostCore::StartSavingChanges, | 124 FROM_HERE, base::Bind(&SyncBackendHostCore::StartSavingChanges, |
123 weak_ptr_factory_.GetWeakPtr())); | 125 weak_ptr_factory_.GetWeakPtr())); |
124 | 126 |
125 // Hang on to these for a while longer. We're not ready to hand them back to | 127 // Hang on to these for a while longer. We're not ready to hand them back to |
126 // the UI thread yet. | 128 // the UI thread yet. |
127 js_backend_ = js_backend; | 129 js_backend_ = js_backend; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 base::Closure()); | 170 base::Closure()); |
169 } | 171 } |
170 | 172 |
171 void SyncBackendHostCore::OnConnectionStatusChange(ConnectionStatus status) { | 173 void SyncBackendHostCore::OnConnectionStatusChange(ConnectionStatus status) { |
172 DCHECK(thread_checker_.CalledOnValidThread()); | 174 DCHECK(thread_checker_.CalledOnValidThread()); |
173 host_.Call(FROM_HERE, | 175 host_.Call(FROM_HERE, |
174 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, | 176 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, |
175 status); | 177 status); |
176 } | 178 } |
177 | 179 |
178 void SyncBackendHostCore::OnPassphraseRequired( | |
179 PassphraseRequiredReason reason, | |
180 const sync_pb::EncryptedData& pending_keys) { | |
181 DCHECK(thread_checker_.CalledOnValidThread()); | |
182 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseRequired, reason, | |
183 pending_keys); | |
184 } | |
185 | |
186 void SyncBackendHostCore::OnPassphraseAccepted() { | |
187 DCHECK(thread_checker_.CalledOnValidThread()); | |
188 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseAccepted); | |
189 } | |
190 | |
191 void SyncBackendHostCore::OnBootstrapTokenUpdated( | |
192 const std::string& bootstrap_token, | |
193 BootstrapTokenType type) { | |
194 DCHECK(thread_checker_.CalledOnValidThread()); | |
195 host_.Call(FROM_HERE, &SyncBackendHostImpl::PersistEncryptionBootstrapToken, | |
196 bootstrap_token, type); | |
197 } | |
198 | |
199 void SyncBackendHostCore::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | |
200 bool encrypt_everything) { | |
201 DCHECK(thread_checker_.CalledOnValidThread()); | |
202 // NOTE: We're in a transaction. | |
203 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptedTypesChanged, | |
204 encrypted_types, encrypt_everything); | |
205 } | |
206 | |
207 void SyncBackendHostCore::OnEncryptionComplete() { | |
208 DCHECK(thread_checker_.CalledOnValidThread()); | |
209 // NOTE: We're in a transaction. | |
210 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptionComplete); | |
211 } | |
212 | |
213 void SyncBackendHostCore::OnCryptographerStateChanged( | |
214 Cryptographer* cryptographer) { | |
215 DCHECK(thread_checker_.CalledOnValidThread()); | |
216 // Do nothing. | |
217 } | |
218 | |
219 void SyncBackendHostCore::OnPassphraseTypeChanged(PassphraseType type, | |
220 base::Time passphrase_time) { | |
221 DCHECK(thread_checker_.CalledOnValidThread()); | |
222 host_.Call(FROM_HERE, | |
223 &SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop, | |
224 type, passphrase_time); | |
225 } | |
226 | |
227 void SyncBackendHostCore::OnLocalSetPassphraseEncryption( | |
228 const SyncEncryptionHandler::NigoriState& nigori_state) { | |
229 DCHECK(thread_checker_.CalledOnValidThread()); | |
230 host_.Call( | |
231 FROM_HERE, | |
232 &SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop, | |
233 nigori_state); | |
234 } | |
235 | |
236 void SyncBackendHostCore::OnCommitCountersUpdated( | 180 void SyncBackendHostCore::OnCommitCountersUpdated( |
237 ModelType type, | 181 ModelType type, |
238 const CommitCounters& counters) { | 182 const CommitCounters& counters) { |
239 DCHECK(thread_checker_.CalledOnValidThread()); | 183 DCHECK(thread_checker_.CalledOnValidThread()); |
240 host_.Call( | 184 host_.Call( |
241 FROM_HERE, | 185 FROM_HERE, |
242 &SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop, | 186 &SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop, |
243 type, counters); | 187 type, counters); |
244 } | 188 } |
245 | 189 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // Make sure that the directory exists before initializing the backend. | 286 // Make sure that the directory exists before initializing the backend. |
343 // If it already exists, this will do no harm. | 287 // If it already exists, this will do no harm. |
344 if (!base::CreateDirectory(sync_data_folder_)) { | 288 if (!base::CreateDirectory(sync_data_folder_)) { |
345 DLOG(FATAL) << "Sync Data directory creation failed."; | 289 DLOG(FATAL) << "Sync Data directory creation failed."; |
346 } | 290 } |
347 | 291 |
348 // Load the previously persisted set of invalidation versions into memory. | 292 // Load the previously persisted set of invalidation versions into memory. |
349 last_invalidation_versions_ = params.invalidation_versions; | 293 last_invalidation_versions_ = params.invalidation_versions; |
350 | 294 |
351 DCHECK(!registrar_); | 295 DCHECK(!registrar_); |
| 296 DCHECK(params.registrar); |
352 registrar_ = std::move(params.registrar); | 297 registrar_ = std::move(params.registrar); |
353 DCHECK(registrar_); | 298 |
| 299 DCHECK(!encryption_observer_proxy_); |
| 300 DCHECK(params.encryption_observer_proxy); |
| 301 encryption_observer_proxy_ = std::move(params.encryption_observer_proxy); |
354 | 302 |
355 sync_manager_ = params.sync_manager_factory->CreateSyncManager(name_); | 303 sync_manager_ = params.sync_manager_factory->CreateSyncManager(name_); |
356 sync_manager_->AddObserver(this); | 304 sync_manager_->AddObserver(this); |
357 | 305 |
358 SyncManager::InitArgs args; | 306 SyncManager::InitArgs args; |
359 args.database_location = sync_data_folder_; | 307 args.database_location = sync_data_folder_; |
360 args.event_handler = params.event_handler; | 308 args.event_handler = params.event_handler; |
361 args.service_url = params.service_url; | 309 args.service_url = params.service_url; |
362 args.enable_local_sync_backend = params.enable_local_sync_backend; | 310 args.enable_local_sync_backend = params.enable_local_sync_backend; |
363 args.local_sync_backend_folder = params.local_sync_backend_folder; | 311 args.local_sync_backend_folder = params.local_sync_backend_folder; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 } | 592 } |
645 | 593 |
646 void SyncBackendHostCore::ClearServerDataDone( | 594 void SyncBackendHostCore::ClearServerDataDone( |
647 const base::Closure& frontend_callback) { | 595 const base::Closure& frontend_callback) { |
648 DCHECK(thread_checker_.CalledOnValidThread()); | 596 DCHECK(thread_checker_.CalledOnValidThread()); |
649 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, | 597 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, |
650 frontend_callback); | 598 frontend_callback); |
651 } | 599 } |
652 | 600 |
653 } // namespace syncer | 601 } // namespace syncer |
OLD | NEW |