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" |
11 #include "chrome/browser/history/history_backend.h" | 11 #include "chrome/browser/history/history_backend.h" |
12 #include "chrome/browser/history/history_db_task.h" | 12 #include "chrome/browser/history/history_db_task.h" |
13 #include "chrome/browser/history/history_service.h" | 13 #include "chrome/browser/history/history_service.h" |
14 #include "sync/api/sync_change.h" | 14 #include "sync/api/sync_change.h" |
15 #include "sync/protocol/history_delete_directive_specifics.pb.h" | 15 #include "sync/protocol/history_delete_directive_specifics.pb.h" |
16 #include "sync/protocol/proto_value_conversions.h" | 16 #include "sync/protocol/proto_value_conversions.h" |
17 #include "sync/protocol/sync.pb.h" | 17 #include "sync/protocol/sync.pb.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
| 21 std::string RandASCIIString(size_t length) { |
| 22 std::string result; |
| 23 const int kMin = static_cast<int>(' '); |
| 24 const int kMax = static_cast<int>('~'); |
| 25 for (size_t i = 0; i < length; ++i) |
| 26 result.push_back(static_cast<char>(base::RandInt(kMin, kMax))); |
| 27 return result; |
| 28 } |
| 29 |
21 std::string DeleteDirectiveToString( | 30 std::string DeleteDirectiveToString( |
22 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | 31 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { |
23 scoped_ptr<base::DictionaryValue> value( | 32 scoped_ptr<base::DictionaryValue> value( |
24 syncer::HistoryDeleteDirectiveSpecificsToValue(delete_directive)); | 33 syncer::HistoryDeleteDirectiveSpecificsToValue(delete_directive)); |
25 std::string str; | 34 std::string str; |
26 base::JSONWriter::Write(value.get(), &str); | 35 base::JSONWriter::Write(value.get(), &str); |
27 return str; | 36 return str; |
28 } | 37 } |
29 | 38 |
30 // Compare time range directives first by start time, then by end time. | 39 // Compare time range directives first by start time, then by end time. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 syncer::SyncError::DATATYPE_ERROR, | 356 syncer::SyncError::DATATYPE_ERROR, |
348 "Cannot send local delete directive to sync", | 357 "Cannot send local delete directive to sync", |
349 syncer::HISTORY_DELETE_DIRECTIVES); | 358 syncer::HISTORY_DELETE_DIRECTIVES); |
350 } | 359 } |
351 #if !defined(NDEBUG) | 360 #if !defined(NDEBUG) |
352 CheckDeleteDirectiveValid(delete_directive); | 361 CheckDeleteDirectiveValid(delete_directive); |
353 #endif | 362 #endif |
354 | 363 |
355 // Generate a random sync tag since history delete directives don't | 364 // Generate a random sync tag since history delete directives don't |
356 // have a 'built-in' ID. 8 bytes should suffice. | 365 // have a 'built-in' ID. 8 bytes should suffice. |
357 std::string sync_tag = base::RandBytesAsString(8); | 366 std::string sync_tag = RandASCIIString(8); |
358 sync_pb::EntitySpecifics entity_specifics; | 367 sync_pb::EntitySpecifics entity_specifics; |
359 entity_specifics.mutable_history_delete_directive()->CopyFrom( | 368 entity_specifics.mutable_history_delete_directive()->CopyFrom( |
360 delete_directive); | 369 delete_directive); |
361 syncer::SyncData sync_data = | 370 syncer::SyncData sync_data = |
362 syncer::SyncData::CreateLocalData( | 371 syncer::SyncData::CreateLocalData( |
363 sync_tag, sync_tag, entity_specifics); | 372 sync_tag, sync_tag, entity_specifics); |
364 syncer::SyncChange change( | 373 syncer::SyncChange change( |
365 FROM_HERE, syncer::SyncChange::ACTION_ADD, sync_data); | 374 FROM_HERE, syncer::SyncChange::ACTION_ADD, sync_data); |
366 syncer::SyncChangeList changes(1, change); | 375 syncer::SyncChangeList changes(1, change); |
367 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 376 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 for (size_t i = 0; i < delete_directives.size(); ++i) { | 429 for (size_t i = 0; i < delete_directives.size(); ++i) { |
421 change_list.push_back( | 430 change_list.push_back( |
422 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_DELETE, | 431 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_DELETE, |
423 delete_directives[i])); | 432 delete_directives[i])); |
424 } | 433 } |
425 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); | 434 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); |
426 } | 435 } |
427 } | 436 } |
428 | 437 |
429 } // namespace history | 438 } // namespace history |
OLD | NEW |