Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/reading_list/ios/reading_list_entry.h" | 5 #include "components/reading_list/ios/reading_list_entry.h" |
| 6 | 6 |
| 7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "components/reading_list/ios/offline_url_utils.h" | 9 #include "components/reading_list/ios/offline_url_utils.h" |
| 10 #include "components/reading_list/ios/proto/reading_list.pb.h" | 10 #include "components/reading_list/ios/proto/reading_list.pb.h" |
| 11 #include "components/reading_list/ios/reading_list_store.h" | |
| 11 #include "components/sync/protocol/reading_list_specifics.pb.h" | 12 #include "components/sync/protocol/reading_list_specifics.pb.h" |
| 12 #include "net/base/backoff_entry_serializer.h" | 13 #include "net/base/backoff_entry_serializer.h" |
| 13 | 14 |
| 14 // The backoff time is the following: 10min, 10min, 1h, 2h, 2h..., starting | 15 // The backoff time is the following: 10min, 10min, 1h, 2h, 2h..., starting |
| 15 // after the first failure. | 16 // after the first failure. |
| 16 const net::BackoffEntry::Policy ReadingListEntry::kBackoffPolicy = { | 17 const net::BackoffEntry::Policy ReadingListEntry::kBackoffPolicy = { |
| 17 // Number of initial errors (in sequence) to ignore before applying | 18 // Number of initial errors (in sequence) to ignore before applying |
| 18 // exponential back-off rules. | 19 // exponential back-off rules. |
| 19 2, | 20 2, |
| 20 | 21 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 state = UNSEEN; | 321 state = UNSEEN; |
| 321 break; | 322 break; |
| 322 } | 323 } |
| 323 } | 324 } |
| 324 | 325 |
| 325 return base::WrapUnique<ReadingListEntry>( | 326 return base::WrapUnique<ReadingListEntry>( |
| 326 new ReadingListEntry(url, title, state, creation_time_us, update_time_us, | 327 new ReadingListEntry(url, title, state, creation_time_us, update_time_us, |
| 327 WAITING, base::FilePath(), 0, nullptr)); | 328 WAITING, base::FilePath(), 0, nullptr)); |
| 328 } | 329 } |
| 329 | 330 |
| 330 void ReadingListEntry::MergeLocalStateFrom(ReadingListEntry& other) { | 331 void ReadingListEntry::MergeWithEntry(const ReadingListEntry& other) { |
| 331 distilled_path_ = std::move(other.distilled_path_); | 332 #if !defined(NDEBUG) |
| 332 distilled_state_ = std::move(other.distilled_state_); | 333 // Checks that the result entry respect the sync order. |
|
jif
2016/12/07 08:25:36
s/respect/respects/
Olivier
2016/12/07 12:00:21
Done.
| |
| 333 backoff_ = std::move(other.backoff_); | 334 std::unique_ptr<sync_pb::ReadingListSpecifics> old_this_pb( |
| 334 failed_download_counter_ = std::move(other.failed_download_counter_); | 335 AsReadingListSpecifics()); |
| 336 std::unique_ptr<sync_pb::ReadingListSpecifics> other_pb( | |
| 337 other.AsReadingListSpecifics()); | |
| 338 #endif | |
| 339 if (other.UpdateTime() >= UpdateTime()) { | |
| 340 url_ = std::move(other.url_); | |
| 341 title_ = std::move(other.title_); | |
| 342 creation_time_us_ = std::move(other.creation_time_us_); | |
| 343 update_time_us_ = std::move(other.update_time_us_); | |
| 344 if (other.state_ != UNSEEN) { | |
| 345 state_ = std::move(other.state_); | |
| 346 } | |
| 347 } | |
| 348 #if !defined(NDEBUG) | |
| 349 std::unique_ptr<sync_pb::ReadingListSpecifics> new_this_pb( | |
| 350 AsReadingListSpecifics()); | |
| 351 DCHECK(ReadingListStore::CompareEntriesForSync(*old_this_pb, *new_this_pb)); | |
| 352 DCHECK(ReadingListStore::CompareEntriesForSync(*other_pb, *new_this_pb)); | |
| 353 #endif | |
| 335 } | 354 } |
| 336 | 355 |
| 337 std::unique_ptr<reading_list::ReadingListLocal> | 356 std::unique_ptr<reading_list::ReadingListLocal> |
| 338 ReadingListEntry::AsReadingListLocal() const { | 357 ReadingListEntry::AsReadingListLocal() const { |
| 339 std::unique_ptr<reading_list::ReadingListLocal> pb_entry = | 358 std::unique_ptr<reading_list::ReadingListLocal> pb_entry = |
| 340 base::MakeUnique<reading_list::ReadingListLocal>(); | 359 base::MakeUnique<reading_list::ReadingListLocal>(); |
| 341 | 360 |
| 342 // URL is used as the key for the database and sync as there is only one entry | 361 // URL is used as the key for the database and sync as there is only one entry |
| 343 // per URL. | 362 // per URL. |
| 344 pb_entry->set_entry_id(URL().spec()); | 363 pb_entry->set_entry_id(URL().spec()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 case UNREAD: | 435 case UNREAD: |
| 417 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); | 436 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
| 418 break; | 437 break; |
| 419 case UNSEEN: | 438 case UNSEEN: |
| 420 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); | 439 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); |
| 421 break; | 440 break; |
| 422 } | 441 } |
| 423 | 442 |
| 424 return pb_entry; | 443 return pb_entry; |
| 425 } | 444 } |
| 426 | |
| 427 bool ReadingListEntry::CompareEntryUpdateTime(const ReadingListEntry& lhs, | |
| 428 const ReadingListEntry& rhs) { | |
| 429 return lhs.UpdateTime() > rhs.UpdateTime(); | |
| 430 } | |
| OLD | NEW |