| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/history/delete_directive_handler.h" | 5 #include "chrome/browser/history/delete_directive_handler.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 syncer::SyncError error = ProcessLocalDeleteDirective(delete_directive); | 337 syncer::SyncError error = ProcessLocalDeleteDirective(delete_directive); |
| 338 return !error.IsSet(); | 338 return !error.IsSet(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 syncer::SyncError DeleteDirectiveHandler::ProcessLocalDeleteDirective( | 341 syncer::SyncError DeleteDirectiveHandler::ProcessLocalDeleteDirective( |
| 342 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | 342 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { |
| 343 DCHECK(thread_checker_.CalledOnValidThread()); | 343 DCHECK(thread_checker_.CalledOnValidThread()); |
| 344 if (!sync_processor_) { | 344 if (!sync_processor_) { |
| 345 return syncer::SyncError( | 345 return syncer::SyncError( |
| 346 FROM_HERE, | 346 FROM_HERE, |
| 347 syncer::SyncError::DATATYPE_ERROR, |
| 347 "Cannot send local delete directive to sync", | 348 "Cannot send local delete directive to sync", |
| 348 syncer::HISTORY_DELETE_DIRECTIVES); | 349 syncer::HISTORY_DELETE_DIRECTIVES); |
| 349 } | 350 } |
| 350 #if !defined(NDEBUG) | 351 #if !defined(NDEBUG) |
| 351 CheckDeleteDirectiveValid(delete_directive); | 352 CheckDeleteDirectiveValid(delete_directive); |
| 352 #endif | 353 #endif |
| 353 | 354 |
| 354 // Generate a random sync tag since history delete directives don't | 355 // Generate a random sync tag since history delete directives don't |
| 355 // have a 'built-in' ID. 8 bytes should suffice. | 356 // have a 'built-in' ID. 8 bytes should suffice. |
| 356 std::string sync_tag = base::RandBytesAsString(8); | 357 std::string sync_tag = base::RandBytesAsString(8); |
| 357 sync_pb::EntitySpecifics entity_specifics; | 358 sync_pb::EntitySpecifics entity_specifics; |
| 358 entity_specifics.mutable_history_delete_directive()->CopyFrom( | 359 entity_specifics.mutable_history_delete_directive()->CopyFrom( |
| 359 delete_directive); | 360 delete_directive); |
| 360 syncer::SyncData sync_data = | 361 syncer::SyncData sync_data = |
| 361 syncer::SyncData::CreateLocalData( | 362 syncer::SyncData::CreateLocalData( |
| 362 sync_tag, sync_tag, entity_specifics); | 363 sync_tag, sync_tag, entity_specifics); |
| 363 syncer::SyncChange change( | 364 syncer::SyncChange change( |
| 364 FROM_HERE, syncer::SyncChange::ACTION_ADD, sync_data); | 365 FROM_HERE, syncer::SyncChange::ACTION_ADD, sync_data); |
| 365 syncer::SyncChangeList changes(1, change); | 366 syncer::SyncChangeList changes(1, change); |
| 366 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 367 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 367 } | 368 } |
| 368 | 369 |
| 369 syncer::SyncError DeleteDirectiveHandler::ProcessSyncChanges( | 370 syncer::SyncError DeleteDirectiveHandler::ProcessSyncChanges( |
| 370 HistoryService* history_service, | 371 HistoryService* history_service, |
| 371 const syncer::SyncChangeList& change_list) { | 372 const syncer::SyncChangeList& change_list) { |
| 372 DCHECK(thread_checker_.CalledOnValidThread()); | 373 DCHECK(thread_checker_.CalledOnValidThread()); |
| 373 if (!sync_processor_) { | 374 if (!sync_processor_) { |
| 374 return syncer::SyncError( | 375 return syncer::SyncError( |
| 375 FROM_HERE, "Sync is disabled.", syncer::HISTORY_DELETE_DIRECTIVES); | 376 FROM_HERE, |
| 377 syncer::SyncError::DATATYPE_ERROR, |
| 378 "Sync is disabled.", |
| 379 syncer::HISTORY_DELETE_DIRECTIVES); |
| 376 } | 380 } |
| 377 | 381 |
| 378 syncer::SyncDataList delete_directives; | 382 syncer::SyncDataList delete_directives; |
| 379 for (syncer::SyncChangeList::const_iterator it = change_list.begin(); | 383 for (syncer::SyncChangeList::const_iterator it = change_list.begin(); |
| 380 it != change_list.end(); ++it) { | 384 it != change_list.end(); ++it) { |
| 381 switch (it->change_type()) { | 385 switch (it->change_type()) { |
| 382 case syncer::SyncChange::ACTION_ADD: | 386 case syncer::SyncChange::ACTION_ADD: |
| 383 delete_directives.push_back(it->sync_data()); | 387 delete_directives.push_back(it->sync_data()); |
| 384 break; | 388 break; |
| 385 case syncer::SyncChange::ACTION_DELETE: | 389 case syncer::SyncChange::ACTION_DELETE: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 416 for (size_t i = 0; i < delete_directives.size(); ++i) { | 420 for (size_t i = 0; i < delete_directives.size(); ++i) { |
| 417 change_list.push_back( | 421 change_list.push_back( |
| 418 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_DELETE, | 422 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_DELETE, |
| 419 delete_directives[i])); | 423 delete_directives[i])); |
| 420 } | 424 } |
| 421 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); | 425 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); |
| 422 } | 426 } |
| 423 } | 427 } |
| 424 | 428 |
| 425 } // namespace history | 429 } // namespace history |
| OLD | NEW |