| 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 "components/history/core/browser/delete_directive_handler.h" | 5 #include "components/history/core/browser/delete_directive_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 8 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 9 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 #include "components/history/core/browser/history_backend.h" | 13 #include "components/history/core/browser/history_backend.h" |
| 12 #include "components/history/core/browser/history_db_task.h" | 14 #include "components/history/core/browser/history_db_task.h" |
| 13 #include "components/history/core/browser/history_service.h" | 15 #include "components/history/core/browser/history_service.h" |
| 14 #include "sync/api/sync_change.h" | 16 #include "sync/api/sync_change.h" |
| 15 #include "sync/protocol/history_delete_directive_specifics.pb.h" | 17 #include "sync/protocol/history_delete_directive_specifics.pb.h" |
| 16 #include "sync/protocol/proto_value_conversions.h" | 18 #include "sync/protocol/proto_value_conversions.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 44 const sync_pb::TimeRangeDirective& range2 = | 46 const sync_pb::TimeRangeDirective& range2 = |
| 45 data2.GetSpecifics().history_delete_directive().time_range_directive(); | 47 data2.GetSpecifics().history_delete_directive().time_range_directive(); |
| 46 if (range1.start_time_usec() < range2.start_time_usec()) | 48 if (range1.start_time_usec() < range2.start_time_usec()) |
| 47 return true; | 49 return true; |
| 48 if (range1.start_time_usec() > range2.start_time_usec()) | 50 if (range1.start_time_usec() > range2.start_time_usec()) |
| 49 return false; | 51 return false; |
| 50 return range1.end_time_usec() < range2.end_time_usec(); | 52 return range1.end_time_usec() < range2.end_time_usec(); |
| 51 } | 53 } |
| 52 | 54 |
| 53 // Converts a Unix timestamp in microseconds to a base::Time value. | 55 // Converts a Unix timestamp in microseconds to a base::Time value. |
| 54 base::Time UnixUsecToTime(int64 usec) { | 56 base::Time UnixUsecToTime(int64_t usec) { |
| 55 return base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(usec); | 57 return base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(usec); |
| 56 } | 58 } |
| 57 | 59 |
| 58 // Converts a base::Time value to a Unix timestamp in microseconds. | 60 // Converts a base::Time value to a Unix timestamp in microseconds. |
| 59 int64 TimeToUnixUsec(base::Time time) { | 61 int64_t TimeToUnixUsec(base::Time time) { |
| 60 DCHECK(!time.is_null()); | 62 DCHECK(!time.is_null()); |
| 61 return (time - base::Time::UnixEpoch()).InMicroseconds(); | 63 return (time - base::Time::UnixEpoch()).InMicroseconds(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 // Converts global IDs in |global_id_directive| to times. | 66 // Converts global IDs in |global_id_directive| to times. |
| 65 void GetTimesFromGlobalIds( | 67 void GetTimesFromGlobalIds( |
| 66 const sync_pb::GlobalIdDirective& global_id_directive, | 68 const sync_pb::GlobalIdDirective& global_id_directive, |
| 67 std::set<base::Time>* times) { | 69 std::set<base::Time>* times) { |
| 68 for (int i = 0; i < global_id_directive.global_id_size(); ++i) { | 70 for (int i = 0; i < global_id_directive.global_id_size(); ++i) { |
| 69 times->insert( | 71 times->insert( |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 &internal_tracker_); | 306 &internal_tracker_); |
| 305 } | 307 } |
| 306 } | 308 } |
| 307 | 309 |
| 308 void DeleteDirectiveHandler::Stop() { | 310 void DeleteDirectiveHandler::Stop() { |
| 309 DCHECK(thread_checker_.CalledOnValidThread()); | 311 DCHECK(thread_checker_.CalledOnValidThread()); |
| 310 sync_processor_.reset(); | 312 sync_processor_.reset(); |
| 311 } | 313 } |
| 312 | 314 |
| 313 bool DeleteDirectiveHandler::CreateDeleteDirectives( | 315 bool DeleteDirectiveHandler::CreateDeleteDirectives( |
| 314 const std::set<int64>& global_ids, | 316 const std::set<int64_t>& global_ids, |
| 315 base::Time begin_time, | 317 base::Time begin_time, |
| 316 base::Time end_time) { | 318 base::Time end_time) { |
| 317 base::Time now = base::Time::Now(); | 319 base::Time now = base::Time::Now(); |
| 318 sync_pb::HistoryDeleteDirectiveSpecifics delete_directive; | 320 sync_pb::HistoryDeleteDirectiveSpecifics delete_directive; |
| 319 | 321 |
| 320 // Delete directives require a non-null begin time, so use 1 if it's null. | 322 // Delete directives require a non-null begin time, so use 1 if it's null. |
| 321 int64 begin_time_usecs = | 323 int64_t begin_time_usecs = |
| 322 begin_time.is_null() ? 0 : TimeToUnixUsec(begin_time); | 324 begin_time.is_null() ? 0 : TimeToUnixUsec(begin_time); |
| 323 | 325 |
| 324 // Determine the actual end time -- it should not be null or in the future. | 326 // Determine the actual end time -- it should not be null or in the future. |
| 325 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's available. | 327 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's available. |
| 326 base::Time end = (end_time.is_null() || end_time > now) ? now : end_time; | 328 base::Time end = (end_time.is_null() || end_time > now) ? now : end_time; |
| 327 // -1 because end time in delete directives is inclusive. | 329 // -1 because end time in delete directives is inclusive. |
| 328 int64 end_time_usecs = TimeToUnixUsec(end) - 1; | 330 int64_t end_time_usecs = TimeToUnixUsec(end) - 1; |
| 329 | 331 |
| 330 if (global_ids.empty()) { | 332 if (global_ids.empty()) { |
| 331 sync_pb::TimeRangeDirective* time_range_directive = | 333 sync_pb::TimeRangeDirective* time_range_directive = |
| 332 delete_directive.mutable_time_range_directive(); | 334 delete_directive.mutable_time_range_directive(); |
| 333 time_range_directive->set_start_time_usec(begin_time_usecs); | 335 time_range_directive->set_start_time_usec(begin_time_usecs); |
| 334 time_range_directive->set_end_time_usec(end_time_usecs); | 336 time_range_directive->set_end_time_usec(end_time_usecs); |
| 335 } else { | 337 } else { |
| 336 for (std::set<int64>::const_iterator it = global_ids.begin(); | 338 for (std::set<int64_t>::const_iterator it = global_ids.begin(); |
| 337 it != global_ids.end(); ++it) { | 339 it != global_ids.end(); ++it) { |
| 338 sync_pb::GlobalIdDirective* global_id_directive = | 340 sync_pb::GlobalIdDirective* global_id_directive = |
| 339 delete_directive.mutable_global_id_directive(); | 341 delete_directive.mutable_global_id_directive(); |
| 340 global_id_directive->add_global_id(*it); | 342 global_id_directive->add_global_id(*it); |
| 341 global_id_directive->set_start_time_usec(begin_time_usecs); | 343 global_id_directive->set_start_time_usec(begin_time_usecs); |
| 342 global_id_directive->set_end_time_usec(end_time_usecs); | 344 global_id_directive->set_end_time_usec(end_time_usecs); |
| 343 } | 345 } |
| 344 } | 346 } |
| 345 syncer::SyncError error = ProcessLocalDeleteDirective(delete_directive); | 347 syncer::SyncError error = ProcessLocalDeleteDirective(delete_directive); |
| 346 return !error.IsSet(); | 348 return !error.IsSet(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 syncer::SyncChangeList change_list; | 425 syncer::SyncChangeList change_list; |
| 424 for (size_t i = 0; i < delete_directives.size(); ++i) { | 426 for (size_t i = 0; i < delete_directives.size(); ++i) { |
| 425 change_list.push_back(syncer::SyncChange( | 427 change_list.push_back(syncer::SyncChange( |
| 426 FROM_HERE, syncer::SyncChange::ACTION_DELETE, delete_directives[i])); | 428 FROM_HERE, syncer::SyncChange::ACTION_DELETE, delete_directives[i])); |
| 427 } | 429 } |
| 428 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); | 430 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); |
| 429 } | 431 } |
| 430 } | 432 } |
| 431 | 433 |
| 432 } // namespace history | 434 } // namespace history |
| OLD | NEW |