| 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/glue/sync_backend_registrar.h" | 5 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace browser_sync { | 25 namespace browser_sync { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Returns true if the current thread is the native thread for the | 29 // Returns true if the current thread is the native thread for the |
| 30 // given group (or if it is undeterminable). | 30 // given group (or if it is undeterminable). |
| 31 bool IsOnThreadForGroup(csync::ModelSafeGroup group) { | 31 bool IsOnThreadForGroup(csync::ModelSafeGroup group) { |
| 32 switch (group) { | 32 switch (group) { |
| 33 case csync::GROUP_PASSIVE: | 33 case csync::GROUP_PASSIVE: |
| 34 return false; | 34 return false; |
| 35 case csync::GROUP_CONTROL: |
| 36 return false; |
| 35 case csync::GROUP_UI: | 37 case csync::GROUP_UI: |
| 36 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 38 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 37 case csync::GROUP_DB: | 39 case csync::GROUP_DB: |
| 38 return BrowserThread::CurrentlyOn(BrowserThread::DB); | 40 return BrowserThread::CurrentlyOn(BrowserThread::DB); |
| 39 case csync::GROUP_FILE: | 41 case csync::GROUP_FILE: |
| 40 return BrowserThread::CurrentlyOn(BrowserThread::FILE); | 42 return BrowserThread::CurrentlyOn(BrowserThread::FILE); |
| 41 case csync::GROUP_HISTORY: | 43 case csync::GROUP_HISTORY: |
| 42 // TODO(ncarter): How to determine this? | 44 // TODO(ncarter): How to determine this? |
| 43 return true; | 45 return true; |
| 44 case csync::GROUP_PASSWORD: | 46 case csync::GROUP_PASSWORD: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 61 sync_loop_(sync_loop), | 63 sync_loop_(sync_loop), |
| 62 ui_worker_(new UIModelWorker()), | 64 ui_worker_(new UIModelWorker()), |
| 63 stopped_on_ui_thread_(false) { | 65 stopped_on_ui_thread_(false) { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 65 CHECK(profile_); | 67 CHECK(profile_); |
| 66 DCHECK(sync_loop_); | 68 DCHECK(sync_loop_); |
| 67 workers_[csync::GROUP_DB] = new DatabaseModelWorker(); | 69 workers_[csync::GROUP_DB] = new DatabaseModelWorker(); |
| 68 workers_[csync::GROUP_FILE] = new FileModelWorker(); | 70 workers_[csync::GROUP_FILE] = new FileModelWorker(); |
| 69 workers_[csync::GROUP_UI] = ui_worker_; | 71 workers_[csync::GROUP_UI] = ui_worker_; |
| 70 workers_[csync::GROUP_PASSIVE] = new csync::PassiveModelWorker(sync_loop_); | 72 workers_[csync::GROUP_PASSIVE] = new csync::PassiveModelWorker(sync_loop_); |
| 73 workers_[csync::GROUP_CONTROL] = new csync::PassiveModelWorker(sync_loop_); |
| 71 | 74 |
| 72 // Any datatypes that we want the syncer to pull down must be in the | 75 // Any datatypes that we want the syncer to pull down must be in the |
| 73 // routing_info map. We set them to group passive, meaning that | 76 // routing_info map. We set them to group passive, meaning that |
| 74 // updates will be applied to sync, but not dispatched to the native | 77 // updates will be applied to sync, but not dispatched to the native |
| 75 // models. | 78 // models. |
| 76 for (syncable::ModelTypeSet::Iterator it = initial_types.First(); | 79 for (syncable::ModelTypeSet::Iterator it = initial_types.First(); |
| 77 it.Good(); it.Inc()) { | 80 it.Good(); it.Inc()) { |
| 78 routing_info_[it.Get()] = csync::GROUP_PASSIVE; | 81 if (IsInternalType(it.Get())) { |
| 82 routing_info_[it.Get()] = csync::GROUP_CONTROL; |
| 83 } else { |
| 84 routing_info_[it.Get()] = csync::GROUP_PASSIVE; |
| 85 } |
| 79 } | 86 } |
| 80 | 87 |
| 81 HistoryService* history_service = profile->GetHistoryService( | 88 HistoryService* history_service = profile->GetHistoryService( |
| 82 Profile::IMPLICIT_ACCESS); | 89 Profile::IMPLICIT_ACCESS); |
| 83 if (history_service) { | 90 if (history_service) { |
| 84 workers_[csync::GROUP_HISTORY] = new HistoryModelWorker(history_service); | 91 workers_[csync::GROUP_HISTORY] = new HistoryModelWorker(history_service); |
| 85 } else { | 92 } else { |
| 86 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS)) | 93 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS)) |
| 87 << "History store disabled, cannot sync Omnibox History"; | 94 << "History store disabled, cannot sync Omnibox History"; |
| 88 routing_info_.erase(syncable::TYPED_URLS); | 95 routing_info_.erase(syncable::TYPED_URLS); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 133 } |
| 127 | 134 |
| 128 base::AutoLock lock(lock_); | 135 base::AutoLock lock(lock_); |
| 129 syncable::ModelTypeSet newly_added_types; | 136 syncable::ModelTypeSet newly_added_types; |
| 130 for (syncable::ModelTypeSet::Iterator it = | 137 for (syncable::ModelTypeSet::Iterator it = |
| 131 filtered_types_to_add.First(); | 138 filtered_types_to_add.First(); |
| 132 it.Good(); it.Inc()) { | 139 it.Good(); it.Inc()) { |
| 133 // Add a newly specified data type as csync::GROUP_PASSIVE into the | 140 // Add a newly specified data type as csync::GROUP_PASSIVE into the |
| 134 // routing_info, if it does not already exist. | 141 // routing_info, if it does not already exist. |
| 135 if (routing_info_.count(it.Get()) == 0) { | 142 if (routing_info_.count(it.Get()) == 0) { |
| 136 routing_info_[it.Get()] = csync::GROUP_PASSIVE; | 143 if (IsInternalType(it.Get())) { |
| 144 routing_info_[it.Get()] = csync::GROUP_CONTROL; |
| 145 } else { |
| 146 routing_info_[it.Get()] = csync::GROUP_PASSIVE; |
| 147 } |
| 137 newly_added_types.Put(it.Get()); | 148 newly_added_types.Put(it.Get()); |
| 138 } | 149 } |
| 139 } | 150 } |
| 140 for (syncable::ModelTypeSet::Iterator it = types_to_remove.First(); | 151 for (syncable::ModelTypeSet::Iterator it = types_to_remove.First(); |
| 141 it.Good(); it.Inc()) { | 152 it.Good(); it.Inc()) { |
| 142 routing_info_.erase(it.Get()); | 153 routing_info_.erase(it.Get()); |
| 143 } | 154 } |
| 144 | 155 |
| 145 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. | 156 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. |
| 146 DVLOG(1) << name_ << ": Adding types " | 157 DVLOG(1) << name_ << ": Adding types " |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 return it->second; | 291 return it->second; |
| 281 } | 292 } |
| 282 | 293 |
| 283 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 294 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
| 284 syncable::ModelType model_type) const { | 295 syncable::ModelType model_type) const { |
| 285 lock_.AssertAcquired(); | 296 lock_.AssertAcquired(); |
| 286 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); | 297 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); |
| 287 } | 298 } |
| 288 | 299 |
| 289 } // namespace browser_sync | 300 } // namespace browser_sync |
| OLD | NEW |