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/shared_change_processor.h" | 5 #include "chrome/browser/sync/glue/shared_change_processor.h" |
6 | 6 |
7 #include "chrome/browser/sync/glue/generic_change_processor.h" | 7 #include "chrome/browser/sync/glue/generic_change_processor.h" |
8 #include "chrome/browser/sync/profile_sync_components_factory.h" | 8 #include "chrome/browser/sync/profile_sync_components_factory.h" |
9 #include "chrome/browser/sync/profile_sync_service.h" | 9 #include "chrome/browser/sync/profile_sync_service.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "sync/api/sync_change.h" | 11 #include "sync/api/sync_change.h" |
12 | 12 |
13 using base::AutoLock; | 13 using base::AutoLock; |
14 using content::BrowserThread; | 14 using content::BrowserThread; |
15 | 15 |
16 namespace browser_sync { | 16 namespace browser_sync { |
17 | 17 |
18 SharedChangeProcessor::SharedChangeProcessor() | 18 SharedChangeProcessor::SharedChangeProcessor() |
19 : disconnected_(false), | 19 : disconnected_(false), |
20 type_(syncable::UNSPECIFIED), | 20 type_(syncable::UNSPECIFIED), |
21 sync_service_(NULL), | 21 sync_service_(NULL), |
22 generic_change_processor_(NULL), | 22 generic_change_processor_(NULL), |
23 error_handler_(NULL) { | 23 error_handler_(NULL) { |
24 // We're always created on the UI thread. | 24 // We're always created on the UI thread. |
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
26 } | 26 } |
27 | 27 |
28 SharedChangeProcessor::~SharedChangeProcessor() { | 28 SharedChangeProcessor::~SharedChangeProcessor() { |
29 // We can either be deleted when the DTC is destroyed (on UI | 29 // We can either be deleted when the DTC is destroyed (on UI |
30 // thread), or when the SyncableService stop's syncing (datatype | 30 // thread), or when the csync::SyncableService stop's syncing (datatype |
31 // thread). |generic_change_processor_|, if non-NULL, must be | 31 // thread). |generic_change_processor_|, if non-NULL, must be |
32 // deleted on |backend_loop_|. | 32 // deleted on |backend_loop_|. |
33 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 33 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
34 if (backend_loop_.get()) { | 34 if (backend_loop_.get()) { |
35 if (!backend_loop_->DeleteSoon(FROM_HERE, generic_change_processor_)) { | 35 if (!backend_loop_->DeleteSoon(FROM_HERE, generic_change_processor_)) { |
36 NOTREACHED(); | 36 NOTREACHED(); |
37 } | 37 } |
38 } else { | 38 } else { |
39 DCHECK(!generic_change_processor_); | 39 DCHECK(!generic_change_processor_); |
40 } | 40 } |
41 } else { | 41 } else { |
42 DCHECK(backend_loop_.get()); | 42 DCHECK(backend_loop_.get()); |
43 DCHECK(backend_loop_->BelongsToCurrentThread()); | 43 DCHECK(backend_loop_->BelongsToCurrentThread()); |
44 delete generic_change_processor_; | 44 delete generic_change_processor_; |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 base::WeakPtr<SyncableService> SharedChangeProcessor::Connect( | 48 base::WeakPtr<csync::SyncableService> SharedChangeProcessor::Connect( |
49 ProfileSyncComponentsFactory* sync_factory, | 49 ProfileSyncComponentsFactory* sync_factory, |
50 ProfileSyncService* sync_service, | 50 ProfileSyncService* sync_service, |
51 DataTypeErrorHandler* error_handler, | 51 DataTypeErrorHandler* error_handler, |
52 syncable::ModelType type) { | 52 syncable::ModelType type) { |
53 DCHECK(sync_factory); | 53 DCHECK(sync_factory); |
54 DCHECK(sync_service); | 54 DCHECK(sync_service); |
55 DCHECK(error_handler); | 55 DCHECK(error_handler); |
56 DCHECK_NE(type, syncable::UNSPECIFIED); | 56 DCHECK_NE(type, syncable::UNSPECIFIED); |
57 backend_loop_ = base::MessageLoopProxy::current(); | 57 backend_loop_ = base::MessageLoopProxy::current(); |
58 AutoLock lock(monitor_lock_); | 58 AutoLock lock(monitor_lock_); |
59 if (disconnected_) | 59 if (disconnected_) |
60 return base::WeakPtr<SyncableService>(); | 60 return base::WeakPtr<csync::SyncableService>(); |
61 type_ = type; | 61 type_ = type; |
62 sync_service_ = sync_service; | 62 sync_service_ = sync_service; |
63 error_handler_ = error_handler; | 63 error_handler_ = error_handler; |
64 base::WeakPtr<SyncableService> local_service = | 64 base::WeakPtr<csync::SyncableService> local_service = |
65 sync_factory->GetSyncableServiceForType(type); | 65 sync_factory->GetSyncableServiceForType(type); |
66 if (!local_service.get()) { | 66 if (!local_service.get()) { |
67 NOTREACHED() << "SyncableService destroyed before DTC was stopped."; | 67 NOTREACHED() << "SyncableService destroyed before DTC was stopped."; |
68 disconnected_ = true; | 68 disconnected_ = true; |
69 return base::WeakPtr<SyncableService>(); | 69 return base::WeakPtr<csync::SyncableService>(); |
70 } | 70 } |
71 generic_change_processor_ = | 71 generic_change_processor_ = |
72 sync_factory->CreateGenericChangeProcessor(sync_service_, | 72 sync_factory->CreateGenericChangeProcessor(sync_service_, |
73 error_handler, | 73 error_handler, |
74 local_service); | 74 local_service); |
75 return local_service; | 75 return local_service; |
76 } | 76 } |
77 | 77 |
78 bool SharedChangeProcessor::Disconnect() { | 78 bool SharedChangeProcessor::Disconnect() { |
79 // May be called from any thread. | 79 // May be called from any thread. |
80 DVLOG(1) << "Disconnecting change processor."; | 80 DVLOG(1) << "Disconnecting change processor."; |
81 AutoLock lock(monitor_lock_); | 81 AutoLock lock(monitor_lock_); |
82 bool was_connected = !disconnected_; | 82 bool was_connected = !disconnected_; |
83 disconnected_ = true; | 83 disconnected_ = true; |
84 error_handler_ = NULL; | 84 error_handler_ = NULL; |
85 return was_connected; | 85 return was_connected; |
86 } | 86 } |
87 | 87 |
88 SyncError SharedChangeProcessor::GetSyncData(SyncDataList* current_sync_data) { | 88 csync::SyncError SharedChangeProcessor::GetSyncData( |
| 89 csync::SyncDataList* current_sync_data) { |
89 DCHECK(backend_loop_.get()); | 90 DCHECK(backend_loop_.get()); |
90 DCHECK(backend_loop_->BelongsToCurrentThread()); | 91 DCHECK(backend_loop_->BelongsToCurrentThread()); |
91 AutoLock lock(monitor_lock_); | 92 AutoLock lock(monitor_lock_); |
92 if (disconnected_) { | 93 if (disconnected_) { |
93 SyncError error(FROM_HERE, "Change processor disconnected.", type_); | 94 csync::SyncError error(FROM_HERE, "Change processor disconnected.", type_); |
94 return error; | 95 return error; |
95 } | 96 } |
96 return generic_change_processor_->GetSyncDataForType(type_, | 97 return generic_change_processor_->GetSyncDataForType(type_, |
97 current_sync_data); | 98 current_sync_data); |
98 } | 99 } |
99 | 100 |
100 SyncError SharedChangeProcessor::ProcessSyncChanges( | 101 csync::SyncError SharedChangeProcessor::ProcessSyncChanges( |
101 const tracked_objects::Location& from_here, | 102 const tracked_objects::Location& from_here, |
102 const SyncChangeList& list_of_changes) { | 103 const csync::SyncChangeList& list_of_changes) { |
103 DCHECK(backend_loop_.get()); | 104 DCHECK(backend_loop_.get()); |
104 DCHECK(backend_loop_->BelongsToCurrentThread()); | 105 DCHECK(backend_loop_->BelongsToCurrentThread()); |
105 AutoLock lock(monitor_lock_); | 106 AutoLock lock(monitor_lock_); |
106 if (disconnected_) { | 107 if (disconnected_) { |
107 // The DTC that disconnects us must ensure it posts a StopSyncing task. | 108 // The DTC that disconnects us must ensure it posts a StopSyncing task. |
108 // If we reach this, it means it just hasn't executed yet. | 109 // If we reach this, it means it just hasn't executed yet. |
109 SyncError error(FROM_HERE, "Change processor disconnected.", type_); | 110 csync::SyncError error(FROM_HERE, "Change processor disconnected.", type_); |
110 return error; | 111 return error; |
111 } | 112 } |
112 return generic_change_processor_->ProcessSyncChanges( | 113 return generic_change_processor_->ProcessSyncChanges( |
113 from_here, list_of_changes); | 114 from_here, list_of_changes); |
114 } | 115 } |
115 | 116 |
116 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) { | 117 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) { |
117 DCHECK(backend_loop_.get()); | 118 DCHECK(backend_loop_.get()); |
118 DCHECK(backend_loop_->BelongsToCurrentThread()); | 119 DCHECK(backend_loop_->BelongsToCurrentThread()); |
119 AutoLock lock(monitor_lock_); | 120 AutoLock lock(monitor_lock_); |
(...skipping 23 matching lines...) Expand all Loading... |
143 AutoLock lock(monitor_lock_); | 144 AutoLock lock(monitor_lock_); |
144 if (disconnected_) { | 145 if (disconnected_) { |
145 LOG(ERROR) << "Change processor disconnected."; | 146 LOG(ERROR) << "Change processor disconnected."; |
146 return; | 147 return; |
147 } | 148 } |
148 sync_service_->ActivateDataType(type_, | 149 sync_service_->ActivateDataType(type_, |
149 model_safe_group, | 150 model_safe_group, |
150 generic_change_processor_); | 151 generic_change_processor_); |
151 } | 152 } |
152 | 153 |
153 SyncError SharedChangeProcessor::CreateAndUploadError( | 154 csync::SyncError SharedChangeProcessor::CreateAndUploadError( |
154 const tracked_objects::Location& location, | 155 const tracked_objects::Location& location, |
155 const std::string& message) { | 156 const std::string& message) { |
156 AutoLock lock(monitor_lock_); | 157 AutoLock lock(monitor_lock_); |
157 if (!disconnected_) { | 158 if (!disconnected_) { |
158 return error_handler_->CreateAndUploadError(location, message, type_); | 159 return error_handler_->CreateAndUploadError(location, message, type_); |
159 } else { | 160 } else { |
160 return SyncError(location, message, type_); | 161 return csync::SyncError(location, message, type_); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 } // namespace browser_sync | 165 } // namespace browser_sync |
OLD | NEW |