| 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/entry.h" // TODO(tim): Bug 123674. | 21 #include "sync/syncable/entry.h" // TODO(tim): Bug 123674. |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 | 24 |
| 25 namespace browser_sync { | 25 namespace browser_sync { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const int kContextSizeLimit = 1024; // Datatype context size limit. |
| 30 |
| 29 void SetNodeSpecifics(const sync_pb::EntitySpecifics& entity_specifics, | 31 void SetNodeSpecifics(const sync_pb::EntitySpecifics& entity_specifics, |
| 30 syncer::WriteNode* write_node) { | 32 syncer::WriteNode* write_node) { |
| 31 if (syncer::GetModelTypeFromSpecifics(entity_specifics) == | 33 if (syncer::GetModelTypeFromSpecifics(entity_specifics) == |
| 32 syncer::PASSWORDS) { | 34 syncer::PASSWORDS) { |
| 33 write_node->SetPasswordSpecifics( | 35 write_node->SetPasswordSpecifics( |
| 34 entity_specifics.password().client_only_encrypted_data()); | 36 entity_specifics.password().client_only_encrypted_data()); |
| 35 } else { | 37 } else { |
| 36 write_node->SetEntitySpecifics(entity_specifics); | 38 write_node->SetEntitySpecifics(entity_specifics); |
| 37 } | 39 } |
| 38 } | 40 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 syncer::ModelType type) const { | 165 syncer::ModelType type) const { |
| 164 // This is slow / memory intensive. Should be used sparingly by datatypes. | 166 // This is slow / memory intensive. Should be used sparingly by datatypes. |
| 165 syncer::SyncDataList data; | 167 syncer::SyncDataList data; |
| 166 GetAllSyncDataReturnError(type, &data); | 168 GetAllSyncDataReturnError(type, &data); |
| 167 return data; | 169 return data; |
| 168 } | 170 } |
| 169 | 171 |
| 170 syncer::SyncError GenericChangeProcessor::UpdateDataTypeContext( | 172 syncer::SyncError GenericChangeProcessor::UpdateDataTypeContext( |
| 171 syncer::ModelType type, | 173 syncer::ModelType type, |
| 172 const std::string& context) { | 174 const std::string& context) { |
| 173 NOTIMPLEMENTED(); | 175 if (context.size() > static_cast<size_t>(kContextSizeLimit)) { |
| 176 return syncer::SyncError(FROM_HERE, |
| 177 syncer::SyncError::DATATYPE_ERROR, |
| 178 "Context size limit exceeded.", |
| 179 type); |
| 180 } |
| 181 |
| 182 syncer::WriteTransaction trans(FROM_HERE, share_handle()); |
| 183 trans.SetDataTypeContext(type, context); |
| 184 |
| 185 // TODO(zea): consider forcing a nudge? For we'll just use the context on |
| 186 // the next organically triggered sync cycle. |
| 174 return syncer::SyncError(); | 187 return syncer::SyncError(); |
| 175 } | 188 } |
| 176 | 189 |
| 177 syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( | 190 syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( |
| 178 syncer::ModelType type, | 191 syncer::ModelType type, |
| 179 syncer::SyncDataList* current_sync_data) const { | 192 syncer::SyncDataList* current_sync_data) const { |
| 180 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 181 std::string type_name = syncer::ModelTypeToString(type); | 194 std::string type_name = syncer::ModelTypeToString(type); |
| 182 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 195 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
| 183 syncer::ReadNode root(&trans); | 196 syncer::ReadNode root(&trans); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 void GenericChangeProcessor::StartImpl(Profile* profile) { | 639 void GenericChangeProcessor::StartImpl(Profile* profile) { |
| 627 DCHECK(CalledOnValidThread()); | 640 DCHECK(CalledOnValidThread()); |
| 628 } | 641 } |
| 629 | 642 |
| 630 syncer::UserShare* GenericChangeProcessor::share_handle() const { | 643 syncer::UserShare* GenericChangeProcessor::share_handle() const { |
| 631 DCHECK(CalledOnValidThread()); | 644 DCHECK(CalledOnValidThread()); |
| 632 return share_handle_; | 645 return share_handle_; |
| 633 } | 646 } |
| 634 | 647 |
| 635 } // namespace browser_sync | 648 } // namespace browser_sync |
| OLD | NEW |