OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/sync/glue/change_processor.h" | 13 #include "chrome/browser/sync/glue/change_processor.h" |
14 #include "chrome/browser/sync/glue/database_model_worker.h" | 14 #include "chrome/browser/sync/glue/browser_thread_model_worker.h" |
15 #include "chrome/browser/sync/glue/history_model_worker.h" | 15 #include "chrome/browser/sync/glue/history_model_worker.h" |
16 #include "chrome/browser/sync/glue/password_model_worker.h" | 16 #include "chrome/browser/sync/glue/password_model_worker.h" |
17 #include "chrome/browser/sync/glue/ui_model_worker.h" | 17 #include "chrome/browser/sync/glue/ui_model_worker.h" |
18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
19 | 19 |
20 namespace browser_sync { | 20 namespace browser_sync { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Returns true if the current thread is the native thread for the | 24 // Returns true if the current thread is the native thread for the |
25 // given group (or if it is undeterminable). | 25 // given group (or if it is undeterminable). |
26 bool IsOnThreadForGroup(ModelSafeGroup group) { | 26 bool IsOnThreadForGroup(ModelSafeGroup group) { |
27 switch (group) { | 27 switch (group) { |
28 case GROUP_PASSIVE: | 28 case GROUP_PASSIVE: |
29 return false; | 29 return false; |
30 case GROUP_UI: | 30 case GROUP_UI: |
31 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 31 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
32 case GROUP_DB: | 32 case GROUP_DB: |
33 return BrowserThread::CurrentlyOn(BrowserThread::DB); | 33 return BrowserThread::CurrentlyOn(BrowserThread::DB); |
| 34 case GROUP_FILE: |
| 35 return BrowserThread::CurrentlyOn(BrowserThread::FILE); |
34 case GROUP_HISTORY: | 36 case GROUP_HISTORY: |
35 // TODO(ncarter): How to determine this? | 37 // TODO(ncarter): How to determine this? |
36 return true; | 38 return true; |
37 case GROUP_PASSWORD: | 39 case GROUP_PASSWORD: |
38 // TODO(ncarter): How to determine this? | 40 // TODO(ncarter): How to determine this? |
39 return true; | 41 return true; |
40 case MODEL_SAFE_GROUP_COUNT: | 42 case MODEL_SAFE_GROUP_COUNT: |
41 default: | 43 default: |
42 return false; | 44 return false; |
43 } | 45 } |
44 } | 46 } |
45 | 47 |
46 } // namespace | 48 } // namespace |
47 | 49 |
48 SyncBackendRegistrar::SyncBackendRegistrar( | 50 SyncBackendRegistrar::SyncBackendRegistrar( |
49 const syncable::ModelTypeSet& initial_types, | 51 const syncable::ModelTypeSet& initial_types, |
50 const std::string& name, Profile* profile, | 52 const std::string& name, Profile* profile, |
51 MessageLoop* sync_loop) : | 53 MessageLoop* sync_loop) : |
52 name_(name), | 54 name_(name), |
53 profile_(profile), | 55 profile_(profile), |
54 sync_loop_(sync_loop), | 56 sync_loop_(sync_loop), |
55 ui_worker_(new UIModelWorker()), | 57 ui_worker_(new UIModelWorker()), |
56 stopped_on_ui_thread_(false) { | 58 stopped_on_ui_thread_(false) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 CHECK(profile_); | 60 CHECK(profile_); |
59 DCHECK(sync_loop_); | 61 DCHECK(sync_loop_); |
60 workers_[GROUP_DB] = new DatabaseModelWorker(); | 62 workers_[GROUP_DB] = |
| 63 new BrowserThreadModelWorker(BrowserThread::DB, GROUP_DB); |
| 64 workers_[GROUP_FILE] = |
| 65 new BrowserThreadModelWorker(BrowserThread::FILE, GROUP_FILE); |
61 workers_[GROUP_UI] = ui_worker_; | 66 workers_[GROUP_UI] = ui_worker_; |
62 workers_[GROUP_PASSIVE] = new ModelSafeWorker(); | 67 workers_[GROUP_PASSIVE] = new ModelSafeWorker(); |
63 | 68 |
64 // Any datatypes that we want the syncer to pull down must be in the | 69 // Any datatypes that we want the syncer to pull down must be in the |
65 // routing_info map. We set them to group passive, meaning that | 70 // routing_info map. We set them to group passive, meaning that |
66 // updates will be applied to sync, but not dispatched to the native | 71 // updates will be applied to sync, but not dispatched to the native |
67 // models. | 72 // models. |
68 for (syncable::ModelTypeSet::const_iterator it = initial_types.begin(); | 73 for (syncable::ModelTypeSet::const_iterator it = initial_types.begin(); |
69 it != initial_types.end(); ++it) { | 74 it != initial_types.end(); ++it) { |
70 routing_info_[*it] = GROUP_PASSIVE; | 75 routing_info_[*it] = GROUP_PASSIVE; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 256 } |
252 | 257 |
253 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 258 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
254 syncable::ModelType model_type) const { | 259 syncable::ModelType model_type) const { |
255 lock_.AssertAcquired(); | 260 lock_.AssertAcquired(); |
256 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); | 261 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); |
257 } | 262 } |
258 | 263 |
259 } // namespace browser_sync | 264 } // namespace browser_sync |
260 | 265 |
OLD | NEW |