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) |
|
gambard
2016/12/06 17:02:22
What is the purpose of this? Can you add a comment
Olivier
2016/12/06 17:16:21
Done.
| |
| 332 distilled_state_ = std::move(other.distilled_state_); | 333 std::unique_ptr<sync_pb::ReadingListSpecifics> old_this_pb( |
| 333 backoff_ = std::move(other.backoff_); | 334 AsReadingListSpecifics()); |
| 334 failed_download_counter_ = std::move(other.failed_download_counter_); | 335 std::unique_ptr<sync_pb::ReadingListSpecifics> other_pb( |
| 336 other.AsReadingListSpecifics()); | |
| 337 #endif | |
| 338 if (other.UpdateTime() >= UpdateTime()) { | |
| 339 url_ = std::move(other.url_); | |
| 340 title_ = std::move(other.title_); | |
| 341 creation_time_us_ = std::move(other.creation_time_us_); | |
| 342 update_time_us_ = std::move(other.update_time_us_); | |
| 343 if (other.state_ != UNSEEN) { | |
| 344 state_ = std::move(other.state_); | |
| 345 } | |
| 346 } | |
| 347 #if !defined(NDEBUG) | |
| 348 std::unique_ptr<sync_pb::ReadingListSpecifics> new_this_pb( | |
| 349 AsReadingListSpecifics()); | |
| 350 DCHECK(ReadingListStore::CompareEntriesForSync(*old_this_pb, *new_this_pb)); | |
| 351 DCHECK(ReadingListStore::CompareEntriesForSync(*other_pb, *new_this_pb)); | |
| 352 #endif | |
| 335 } | 353 } |
| 336 | 354 |
| 337 std::unique_ptr<reading_list::ReadingListLocal> | 355 std::unique_ptr<reading_list::ReadingListLocal> |
| 338 ReadingListEntry::AsReadingListLocal() const { | 356 ReadingListEntry::AsReadingListLocal() const { |
| 339 std::unique_ptr<reading_list::ReadingListLocal> pb_entry = | 357 std::unique_ptr<reading_list::ReadingListLocal> pb_entry = |
| 340 base::MakeUnique<reading_list::ReadingListLocal>(); | 358 base::MakeUnique<reading_list::ReadingListLocal>(); |
| 341 | 359 |
| 342 // URL is used as the key for the database and sync as there is only one entry | 360 // URL is used as the key for the database and sync as there is only one entry |
| 343 // per URL. | 361 // per URL. |
| 344 pb_entry->set_entry_id(URL().spec()); | 362 pb_entry->set_entry_id(URL().spec()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 case UNREAD: | 434 case UNREAD: |
| 417 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); | 435 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
| 418 break; | 436 break; |
| 419 case UNSEEN: | 437 case UNSEEN: |
| 420 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); | 438 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); |
| 421 break; | 439 break; |
| 422 } | 440 } |
| 423 | 441 |
| 424 return pb_entry; | 442 return pb_entry; |
| 425 } | 443 } |
| 426 | |
| 427 bool ReadingListEntry::CompareEntryUpdateTime(const ReadingListEntry& lhs, | |
| 428 const ReadingListEntry& rhs) { | |
| 429 return lhs.UpdateTime() > rhs.UpdateTime(); | |
| 430 } | |
| OLD | NEW |