| 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 11 matching lines...) Expand all Loading... |
| 22 #include "sync/internal_api/public/engine/passive_model_worker.h" | 22 #include "sync/internal_api/public/engine/passive_model_worker.h" |
| 23 | 23 |
| 24 using content::BrowserThread; | 24 using content::BrowserThread; |
| 25 | 25 |
| 26 namespace browser_sync { | 26 namespace browser_sync { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Returns true if the current thread is the native thread for the | 30 // Returns true if the current thread is the native thread for the |
| 31 // given group (or if it is undeterminable). | 31 // given group (or if it is undeterminable). |
| 32 bool IsOnThreadForGroup(syncer::ModelSafeGroup group) { | 32 bool IsOnThreadForGroup(syncer::ModelType type, syncer::ModelSafeGroup group) { |
| 33 switch (group) { | 33 switch (group) { |
| 34 case syncer::GROUP_PASSIVE: | 34 case syncer::GROUP_PASSIVE: |
| 35 return false; | 35 return IsControlType(type); |
| 36 case syncer::GROUP_UI: | 36 case syncer::GROUP_UI: |
| 37 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 37 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 38 case syncer::GROUP_DB: | 38 case syncer::GROUP_DB: |
| 39 return BrowserThread::CurrentlyOn(BrowserThread::DB); | 39 return BrowserThread::CurrentlyOn(BrowserThread::DB); |
| 40 case syncer::GROUP_FILE: | 40 case syncer::GROUP_FILE: |
| 41 return BrowserThread::CurrentlyOn(BrowserThread::FILE); | 41 return BrowserThread::CurrentlyOn(BrowserThread::FILE); |
| 42 case syncer::GROUP_HISTORY: | 42 case syncer::GROUP_HISTORY: |
| 43 // TODO(ncarter): How to determine this? | 43 // TODO(sync): How to check we're on the right thread? |
| 44 return true; | 44 return type == syncer::TYPED_URLS; |
| 45 case syncer::GROUP_PASSWORD: | 45 case syncer::GROUP_PASSWORD: |
| 46 // TODO(ncarter): How to determine this? | 46 // TODO(sync): How to check we're on the right thread? |
| 47 return true; | 47 return type == syncer::PASSWORDS; |
| 48 case syncer::MODEL_SAFE_GROUP_COUNT: | 48 case syncer::MODEL_SAFE_GROUP_COUNT: |
| 49 default: | 49 default: |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 SyncBackendRegistrar::SyncBackendRegistrar( | 56 SyncBackendRegistrar::SyncBackendRegistrar( |
| 57 const std::string& name, Profile* profile, | 57 const std::string& name, Profile* profile, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 void SyncBackendRegistrar::OnSyncerShutdownComplete() { | 178 void SyncBackendRegistrar::OnSyncerShutdownComplete() { |
| 179 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 179 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 180 ui_worker_->OnSyncerShutdownComplete(); | 180 ui_worker_->OnSyncerShutdownComplete(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SyncBackendRegistrar::ActivateDataType( | 183 void SyncBackendRegistrar::ActivateDataType( |
| 184 syncer::ModelType type, | 184 syncer::ModelType type, |
| 185 syncer::ModelSafeGroup group, | 185 syncer::ModelSafeGroup group, |
| 186 ChangeProcessor* change_processor, | 186 ChangeProcessor* change_processor, |
| 187 syncer::UserShare* user_share) { | 187 syncer::UserShare* user_share) { |
| 188 CHECK(IsOnThreadForGroup(group)); | 188 CHECK(IsOnThreadForGroup(type, group)); |
| 189 base::AutoLock lock(lock_); | 189 base::AutoLock lock(lock_); |
| 190 // Ensure that the given data type is in the PASSIVE group. | 190 // Ensure that the given data type is in the PASSIVE group. |
| 191 syncer::ModelSafeRoutingInfo::iterator i = routing_info_.find(type); | 191 syncer::ModelSafeRoutingInfo::iterator i = routing_info_.find(type); |
| 192 DCHECK(i != routing_info_.end()); | 192 DCHECK(i != routing_info_.end()); |
| 193 DCHECK_EQ(i->second, syncer::GROUP_PASSIVE); | 193 DCHECK_EQ(i->second, syncer::GROUP_PASSIVE); |
| 194 routing_info_[type] = group; | 194 routing_info_[type] = group; |
| 195 CHECK(IsCurrentThreadSafeForModel(type)); | 195 CHECK(IsCurrentThreadSafeForModel(type)); |
| 196 | 196 |
| 197 // Add the data type's change processor to the list of change | 197 // Add the data type's change processor to the list of change |
| 198 // processors so it can receive updates. | 198 // processors so it can receive updates. |
| 199 DCHECK_EQ(processors_.count(type), 0U); | 199 DCHECK_EQ(processors_.count(type), 0U); |
| 200 processors_[type] = change_processor; | 200 processors_[type] = change_processor; |
| 201 | 201 |
| 202 // Start the change processor. | 202 // Start the change processor. |
| 203 change_processor->Start(profile_, user_share); | 203 change_processor->Start(profile_, user_share); |
| 204 DCHECK(GetProcessorUnsafe(type)); | 204 DCHECK(GetProcessorUnsafe(type)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void SyncBackendRegistrar::DeactivateDataType(syncer::ModelType type) { | 207 void SyncBackendRegistrar::DeactivateDataType(syncer::ModelType type) { |
| 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || IsControlType(type)); |
| 209 base::AutoLock lock(lock_); | 209 base::AutoLock lock(lock_); |
| 210 | 210 |
| 211 routing_info_.erase(type); | 211 routing_info_.erase(type); |
| 212 ignore_result(processors_.erase(type)); | 212 ignore_result(processors_.erase(type)); |
| 213 DCHECK(!GetProcessorUnsafe(type)); | 213 DCHECK(!GetProcessorUnsafe(type)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool SyncBackendRegistrar::IsTypeActivatedForTest( | 216 bool SyncBackendRegistrar::IsTypeActivatedForTest( |
| 217 syncer::ModelType type) const { | 217 syncer::ModelType type) const { |
| 218 return GetProcessor(type) != NULL; | 218 return GetProcessor(type) != NULL; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // |processors_| list. | 285 // |processors_| list. |
| 286 if (it == processors_.end()) | 286 if (it == processors_.end()) |
| 287 return NULL; | 287 return NULL; |
| 288 | 288 |
| 289 return it->second; | 289 return it->second; |
| 290 } | 290 } |
| 291 | 291 |
| 292 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 292 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
| 293 syncer::ModelType model_type) const { | 293 syncer::ModelType model_type) const { |
| 294 lock_.AssertAcquired(); | 294 lock_.AssertAcquired(); |
| 295 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); | 295 return IsOnThreadForGroup(model_type, |
| 296 GetGroupForModelType(model_type, routing_info_)); |
| 296 } | 297 } |
| 297 | 298 |
| 298 } // namespace browser_sync | 299 } // namespace browser_sync |
| OLD | NEW |