| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync_driver/glue/sync_backend_registrar.h" | 5 #include "components/sync_driver/glue/sync_backend_registrar.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 MaybeAddWorker(syncer::GROUP_UI); | 44 MaybeAddWorker(syncer::GROUP_UI); |
| 45 MaybeAddWorker(syncer::GROUP_PASSIVE); | 45 MaybeAddWorker(syncer::GROUP_PASSIVE); |
| 46 MaybeAddWorker(syncer::GROUP_HISTORY); | 46 MaybeAddWorker(syncer::GROUP_HISTORY); |
| 47 MaybeAddWorker(syncer::GROUP_PASSWORD); | 47 MaybeAddWorker(syncer::GROUP_PASSWORD); |
| 48 | 48 |
| 49 // Must have at least one worker for SyncBackendRegistrar to be destroyed | 49 // Must have at least one worker for SyncBackendRegistrar to be destroyed |
| 50 // correctly, as it is destroyed after the last worker dies. | 50 // correctly, as it is destroyed after the last worker dies. |
| 51 DCHECK_GT(workers_.size(), 0u); | 51 DCHECK_GT(workers_.size(), 0u); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SyncBackendRegistrar::RegisterNonBlockingType(syncer::ModelType type) { |
| 55 DCHECK(routing_info_.find(type) == routing_info_.end() || |
| 56 routing_info_[type] == syncer::GROUP_NON_BLOCKING); |
| 57 non_blocking_types_.Put(type); |
| 58 } |
| 59 |
| 54 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) { | 60 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) { |
| 55 base::AutoLock lock(lock_); | 61 base::AutoLock lock(lock_); |
| 56 | 62 |
| 57 // This function should be called only once, shortly after construction. The | 63 // This function should be called only once, shortly after construction. The |
| 58 // routing info at that point is expected to be empty. | 64 // routing info at that point is expected to be empty. |
| 59 DCHECK(routing_info_.empty()); | 65 DCHECK(routing_info_.empty()); |
| 60 | 66 |
| 61 // Set our initial state to reflect the current status of the sync directory. | 67 // Set our initial state to reflect the current status of the sync directory. |
| 62 // This will ensure that our calculations in ConfigureDataTypes() will always | 68 // This will ensure that our calculations in ConfigureDataTypes() will always |
| 63 // return correct results. | 69 // return correct results. |
| 64 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); it.Good(); | 70 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); it.Good(); |
| 65 it.Inc()) { | 71 it.Inc()) { |
| 66 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; | 72 routing_info_[it.Get()] = GetInitialGroupForType(it.Get()); |
| 67 } | 73 } |
| 68 | 74 |
| 69 if (!workers_.count(syncer::GROUP_HISTORY)) { | 75 if (!workers_.count(syncer::GROUP_HISTORY)) { |
| 70 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) | 76 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) |
| 71 << "History store disabled, cannot sync Omnibox History"; | 77 << "History store disabled, cannot sync Omnibox History"; |
| 72 routing_info_.erase(syncer::TYPED_URLS); | 78 routing_info_.erase(syncer::TYPED_URLS); |
| 73 } | 79 } |
| 74 | 80 |
| 75 if (!workers_.count(syncer::GROUP_PASSWORD)) { | 81 if (!workers_.count(syncer::GROUP_PASSWORD)) { |
| 76 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) | 82 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 101 filtered_types_to_add.Remove(syncer::PASSWORDS); | 107 filtered_types_to_add.Remove(syncer::PASSWORDS); |
| 102 } | 108 } |
| 103 | 109 |
| 104 base::AutoLock lock(lock_); | 110 base::AutoLock lock(lock_); |
| 105 syncer::ModelTypeSet newly_added_types; | 111 syncer::ModelTypeSet newly_added_types; |
| 106 for (syncer::ModelTypeSet::Iterator it = filtered_types_to_add.First(); | 112 for (syncer::ModelTypeSet::Iterator it = filtered_types_to_add.First(); |
| 107 it.Good(); it.Inc()) { | 113 it.Good(); it.Inc()) { |
| 108 // Add a newly specified data type as syncer::GROUP_PASSIVE into the | 114 // Add a newly specified data type as syncer::GROUP_PASSIVE into the |
| 109 // routing_info, if it does not already exist. | 115 // routing_info, if it does not already exist. |
| 110 if (routing_info_.count(it.Get()) == 0) { | 116 if (routing_info_.count(it.Get()) == 0) { |
| 111 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; | 117 routing_info_[it.Get()] = GetInitialGroupForType(it.Get()); |
| 112 newly_added_types.Put(it.Get()); | 118 newly_added_types.Put(it.Get()); |
| 113 } | 119 } |
| 114 } | 120 } |
| 115 for (syncer::ModelTypeSet::Iterator it = types_to_remove.First(); it.Good(); | 121 for (syncer::ModelTypeSet::Iterator it = types_to_remove.First(); it.Good(); |
| 116 it.Inc()) { | 122 it.Inc()) { |
| 117 routing_info_.erase(it.Get()); | 123 routing_info_.erase(it.Get()); |
| 118 } | 124 } |
| 119 | 125 |
| 120 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. | 126 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. |
| 121 DVLOG(1) << name_ << ": Adding types " | 127 DVLOG(1) << name_ << ": Adding types " |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 it->second->UnregisterForLoopDestruction( | 350 it->second->UnregisterForLoopDestruction( |
| 345 base::Bind(&SyncBackendRegistrar::OnWorkerUnregistrationDone, | 351 base::Bind(&SyncBackendRegistrar::OnWorkerUnregistrationDone, |
| 346 base::Unretained(this))); | 352 base::Unretained(this))); |
| 347 } | 353 } |
| 348 } | 354 } |
| 349 | 355 |
| 350 base::Thread* SyncBackendRegistrar::sync_thread() { | 356 base::Thread* SyncBackendRegistrar::sync_thread() { |
| 351 return sync_thread_.get(); | 357 return sync_thread_.get(); |
| 352 } | 358 } |
| 353 | 359 |
| 360 syncer::ModelSafeGroup SyncBackendRegistrar::GetInitialGroupForType( |
| 361 syncer::ModelType type) const { |
| 362 if (non_blocking_types_.Has(type)) |
| 363 return syncer::GROUP_NON_BLOCKING; |
| 364 else |
| 365 return syncer::GROUP_PASSIVE; |
| 366 } |
| 367 |
| 354 } // namespace browser_sync | 368 } // namespace browser_sync |
| OLD | NEW |