| 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(ModelSafeGroup group) { | 31 bool IsOnThreadForGroup(ModelSafeGroup group) { |
| 32 switch (group) { | 32 switch (group) { |
| 33 case GROUP_PASSIVE: | 33 case GROUP_PASSIVE: |
| 34 return false; | 34 return false; |
| 35 case GROUP_INTERNAL: |
| 36 return false; |
| 35 case GROUP_UI: | 37 case GROUP_UI: |
| 36 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 38 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 37 case GROUP_DB: | 39 case GROUP_DB: |
| 38 return BrowserThread::CurrentlyOn(BrowserThread::DB); | 40 return BrowserThread::CurrentlyOn(BrowserThread::DB); |
| 39 case GROUP_FILE: | 41 case GROUP_FILE: |
| 40 return BrowserThread::CurrentlyOn(BrowserThread::FILE); | 42 return BrowserThread::CurrentlyOn(BrowserThread::FILE); |
| 41 case GROUP_HISTORY: | 43 case GROUP_HISTORY: |
| 42 // TODO(ncarter): How to determine this? | 44 // TODO(ncarter): How to determine this? |
| 43 return true; | 45 return true; |
| 44 case GROUP_PASSWORD: | 46 case 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_[GROUP_DB] = new DatabaseModelWorker(); | 69 workers_[GROUP_DB] = new DatabaseModelWorker(); |
| 68 workers_[GROUP_FILE] = new FileModelWorker(); | 70 workers_[GROUP_FILE] = new FileModelWorker(); |
| 69 workers_[GROUP_UI] = ui_worker_; | 71 workers_[GROUP_UI] = ui_worker_; |
| 70 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_); | 72 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_); |
| 73 workers_[GROUP_INTERNAL] = new 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()] = GROUP_PASSIVE; | 81 routing_info_[it.Get()] = GROUP_PASSIVE; |
| 79 } | 82 } |
| 80 | 83 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 129 } |
| 127 | 130 |
| 128 base::AutoLock lock(lock_); | 131 base::AutoLock lock(lock_); |
| 129 syncable::ModelTypeSet newly_added_types; | 132 syncable::ModelTypeSet newly_added_types; |
| 130 for (syncable::ModelTypeSet::Iterator it = | 133 for (syncable::ModelTypeSet::Iterator it = |
| 131 filtered_types_to_add.First(); | 134 filtered_types_to_add.First(); |
| 132 it.Good(); it.Inc()) { | 135 it.Good(); it.Inc()) { |
| 133 // Add a newly specified data type as GROUP_PASSIVE into the | 136 // Add a newly specified data type as GROUP_PASSIVE into the |
| 134 // routing_info, if it does not already exist. | 137 // routing_info, if it does not already exist. |
| 135 if (routing_info_.count(it.Get()) == 0) { | 138 if (routing_info_.count(it.Get()) == 0) { |
| 136 routing_info_[it.Get()] = GROUP_PASSIVE; | 139 if (IsInternalType(it.Get())) { |
| 140 routing_info_[it.Get()] = GROUP_INTERNAL; |
| 141 } else { |
| 142 routing_info_[it.Get()] = GROUP_PASSIVE; |
| 143 } |
| 137 newly_added_types.Put(it.Get()); | 144 newly_added_types.Put(it.Get()); |
| 138 } | 145 } |
| 139 } | 146 } |
| 140 for (syncable::ModelTypeSet::Iterator it = types_to_remove.First(); | 147 for (syncable::ModelTypeSet::Iterator it = types_to_remove.First(); |
| 141 it.Good(); it.Inc()) { | 148 it.Good(); it.Inc()) { |
| 142 routing_info_.erase(it.Get()); | 149 routing_info_.erase(it.Get()); |
| 143 } | 150 } |
| 144 | 151 |
| 145 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. | 152 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. |
| 146 DVLOG(1) << name_ << ": Adding types " | 153 DVLOG(1) << name_ << ": Adding types " |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 return it->second; | 287 return it->second; |
| 281 } | 288 } |
| 282 | 289 |
| 283 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 290 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
| 284 syncable::ModelType model_type) const { | 291 syncable::ModelType model_type) const { |
| 285 lock_.AssertAcquired(); | 292 lock_.AssertAcquired(); |
| 286 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); | 293 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); |
| 287 } | 294 } |
| 288 | 295 |
| 289 } // namespace browser_sync | 296 } // namespace browser_sync |
| OLD | NEW |