Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: chrome/browser/sync/glue/shared_change_processor.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 csync::SyncableService stop's syncing (datatype 30 // thread), or when the syncer::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<csync::SyncableService> SharedChangeProcessor::Connect( 48 base::WeakPtr<syncer::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<csync::SyncableService>(); 60 return base::WeakPtr<syncer::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<csync::SyncableService> local_service = 64 base::WeakPtr<syncer::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<csync::SyncableService>(); 69 return base::WeakPtr<syncer::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 csync::SyncError SharedChangeProcessor::GetSyncData( 88 syncer::SyncError SharedChangeProcessor::GetSyncData(
89 csync::SyncDataList* current_sync_data) { 89 syncer::SyncDataList* current_sync_data) {
90 DCHECK(backend_loop_.get()); 90 DCHECK(backend_loop_.get());
91 DCHECK(backend_loop_->BelongsToCurrentThread()); 91 DCHECK(backend_loop_->BelongsToCurrentThread());
92 AutoLock lock(monitor_lock_); 92 AutoLock lock(monitor_lock_);
93 if (disconnected_) { 93 if (disconnected_) {
94 csync::SyncError error(FROM_HERE, "Change processor disconnected.", type_); 94 syncer::SyncError error(FROM_HERE, "Change processor disconnected.", type_);
95 return error; 95 return error;
96 } 96 }
97 return generic_change_processor_->GetSyncDataForType(type_, 97 return generic_change_processor_->GetSyncDataForType(type_,
98 current_sync_data); 98 current_sync_data);
99 } 99 }
100 100
101 csync::SyncError SharedChangeProcessor::ProcessSyncChanges( 101 syncer::SyncError SharedChangeProcessor::ProcessSyncChanges(
102 const tracked_objects::Location& from_here, 102 const tracked_objects::Location& from_here,
103 const csync::SyncChangeList& list_of_changes) { 103 const syncer::SyncChangeList& list_of_changes) {
104 DCHECK(backend_loop_.get()); 104 DCHECK(backend_loop_.get());
105 DCHECK(backend_loop_->BelongsToCurrentThread()); 105 DCHECK(backend_loop_->BelongsToCurrentThread());
106 AutoLock lock(monitor_lock_); 106 AutoLock lock(monitor_lock_);
107 if (disconnected_) { 107 if (disconnected_) {
108 // 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.
109 // 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.
110 csync::SyncError error(FROM_HERE, "Change processor disconnected.", type_); 110 syncer::SyncError error(FROM_HERE, "Change processor disconnected.", type_);
111 return error; 111 return error;
112 } 112 }
113 return generic_change_processor_->ProcessSyncChanges( 113 return generic_change_processor_->ProcessSyncChanges(
114 from_here, list_of_changes); 114 from_here, list_of_changes);
115 } 115 }
116 116
117 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) { 117 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) {
118 DCHECK(backend_loop_.get()); 118 DCHECK(backend_loop_.get());
119 DCHECK(backend_loop_->BelongsToCurrentThread()); 119 DCHECK(backend_loop_->BelongsToCurrentThread());
120 AutoLock lock(monitor_lock_); 120 AutoLock lock(monitor_lock_);
(...skipping 10 matching lines...) Expand all
131 DCHECK(backend_loop_->BelongsToCurrentThread()); 131 DCHECK(backend_loop_->BelongsToCurrentThread());
132 AutoLock lock(monitor_lock_); 132 AutoLock lock(monitor_lock_);
133 if (disconnected_) { 133 if (disconnected_) {
134 LOG(ERROR) << "Change processor disconnected."; 134 LOG(ERROR) << "Change processor disconnected.";
135 return true; // Otherwise we get into infinite spin waiting. 135 return true; // Otherwise we get into infinite spin waiting.
136 } 136 }
137 return generic_change_processor_->CryptoReadyIfNecessary(type_); 137 return generic_change_processor_->CryptoReadyIfNecessary(type_);
138 } 138 }
139 139
140 void SharedChangeProcessor::ActivateDataType( 140 void SharedChangeProcessor::ActivateDataType(
141 csync::ModelSafeGroup model_safe_group) { 141 syncer::ModelSafeGroup model_safe_group) {
142 DCHECK(backend_loop_.get()); 142 DCHECK(backend_loop_.get());
143 DCHECK(backend_loop_->BelongsToCurrentThread()); 143 DCHECK(backend_loop_->BelongsToCurrentThread());
144 AutoLock lock(monitor_lock_); 144 AutoLock lock(monitor_lock_);
145 if (disconnected_) { 145 if (disconnected_) {
146 LOG(ERROR) << "Change processor disconnected."; 146 LOG(ERROR) << "Change processor disconnected.";
147 return; 147 return;
148 } 148 }
149 sync_service_->ActivateDataType(type_, 149 sync_service_->ActivateDataType(type_,
150 model_safe_group, 150 model_safe_group,
151 generic_change_processor_); 151 generic_change_processor_);
152 } 152 }
153 153
154 csync::SyncError SharedChangeProcessor::CreateAndUploadError( 154 syncer::SyncError SharedChangeProcessor::CreateAndUploadError(
155 const tracked_objects::Location& location, 155 const tracked_objects::Location& location,
156 const std::string& message) { 156 const std::string& message) {
157 AutoLock lock(monitor_lock_); 157 AutoLock lock(monitor_lock_);
158 if (!disconnected_) { 158 if (!disconnected_) {
159 return error_handler_->CreateAndUploadError(location, message, type_); 159 return error_handler_->CreateAndUploadError(location, message, type_);
160 } else { 160 } else {
161 return csync::SyncError(location, message, type_); 161 return syncer::SyncError(location, message, type_);
162 } 162 }
163 } 163 }
164 164
165 } // namespace browser_sync 165 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/shared_change_processor.h ('k') | chrome/browser/sync/glue/shared_change_processor_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698