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/generic_change_processor.h" | 5 #include "chrome/browser/sync/glue/generic_change_processor.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.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 #include "sync/api/sync_error.h" | 12 #include "sync/api/sync_error.h" |
13 #include "sync/api/syncable_service.h" | 13 #include "sync/api/syncable_service.h" |
14 #include "sync/internal_api/public/base_node.h" | 14 #include "sync/internal_api/public/base_node.h" |
15 #include "sync/internal_api/public/change_record.h" | 15 #include "sync/internal_api/public/change_record.h" |
16 #include "sync/internal_api/public/read_node.h" | 16 #include "sync/internal_api/public/read_node.h" |
17 #include "sync/internal_api/public/read_transaction.h" | 17 #include "sync/internal_api/public/read_transaction.h" |
18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
19 #include "sync/internal_api/public/write_node.h" | 19 #include "sync/internal_api/public/write_node.h" |
20 #include "sync/internal_api/public/write_transaction.h" | 20 #include "sync/internal_api/public/write_transaction.h" |
21 #include "sync/syncable/directory.h" | |
21 #include "sync/syncable/entry.h" // TODO(tim): Bug 123674. | 22 #include "sync/syncable/entry.h" // TODO(tim): Bug 123674. |
22 | 23 |
23 using content::BrowserThread; | 24 using content::BrowserThread; |
24 | 25 |
25 namespace browser_sync { | 26 namespace browser_sync { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 void SetNodeSpecifics(const sync_pb::EntitySpecifics& entity_specifics, | 30 void SetNodeSpecifics(const sync_pb::EntitySpecifics& entity_specifics, |
30 syncer::WriteNode* write_node) { | 31 syncer::WriteNode* write_node) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 syncer::ModelType type) const { | 147 syncer::ModelType type) const { |
147 // This is slow / memory intensive. Should be used sparingly by datatypes. | 148 // This is slow / memory intensive. Should be used sparingly by datatypes. |
148 syncer::SyncDataList data; | 149 syncer::SyncDataList data; |
149 GetAllSyncDataReturnError(type, &data); | 150 GetAllSyncDataReturnError(type, &data); |
150 return data; | 151 return data; |
151 } | 152 } |
152 | 153 |
153 syncer::SyncError GenericChangeProcessor::UpdateDataTypeContext( | 154 syncer::SyncError GenericChangeProcessor::UpdateDataTypeContext( |
154 syncer::ModelType type, | 155 syncer::ModelType type, |
155 const std::string& context) { | 156 const std::string& context) { |
156 NOTIMPLEMENTED(); | 157 syncer::WriteTransaction trans(FROM_HERE, share_handle()); |
158 sync_pb::DataTypeContext context_proto; | |
159 trans.GetDirectory()->GetDataTypeContext(type, &context_proto); | |
160 | |
161 if (context_proto.context() == context) | |
162 return syncer::SyncError(); // Context already matches. | |
rlarocque
2014/04/03 17:31:58
Why is this an error? It seems harmless.
Nicolas Zea
2014/04/03 22:56:47
default-initialized SyncError aren't errors.
| |
163 | |
164 if (context_proto.type() == 0) | |
165 context_proto.set_type(syncer::GetSpecificsFieldNumberFromModelType(type)); | |
166 DCHECK_EQ(syncer::GetSpecificsFieldNumberFromModelType(type), | |
167 context_proto.type()); | |
168 DCHECK_GE(context_proto.version(), 0); | |
169 context_proto.set_version(context_proto.version() + 1); | |
170 context_proto.set_context(context); | |
171 trans.GetDirectory()->SetDataTypeContext(type, context_proto); | |
157 return syncer::SyncError(); | 172 return syncer::SyncError(); |
158 } | 173 } |
159 | 174 |
160 syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( | 175 syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( |
161 syncer::ModelType type, | 176 syncer::ModelType type, |
162 syncer::SyncDataList* current_sync_data) const { | 177 syncer::SyncDataList* current_sync_data) const { |
163 DCHECK(CalledOnValidThread()); | 178 DCHECK(CalledOnValidThread()); |
164 std::string type_name = syncer::ModelTypeToString(type); | 179 std::string type_name = syncer::ModelTypeToString(type); |
165 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 180 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
166 syncer::ReadNode root(&trans); | 181 syncer::ReadNode root(&trans); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 void GenericChangeProcessor::StartImpl(Profile* profile) { | 618 void GenericChangeProcessor::StartImpl(Profile* profile) { |
604 DCHECK(CalledOnValidThread()); | 619 DCHECK(CalledOnValidThread()); |
605 } | 620 } |
606 | 621 |
607 syncer::UserShare* GenericChangeProcessor::share_handle() const { | 622 syncer::UserShare* GenericChangeProcessor::share_handle() const { |
608 DCHECK(CalledOnValidThread()); | 623 DCHECK(CalledOnValidThread()); |
609 return share_handle_; | 624 return share_handle_; |
610 } | 625 } |
611 | 626 |
612 } // namespace browser_sync | 627 } // namespace browser_sync |
OLD | NEW |