Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: components/reading_list/ios/reading_list_entry.cc

Issue 2553143002: Create a strict order in ReadingListSpecifics (Closed)
Patch Set: order by field Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 respects the sync order.
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 DCHECK(url_ == other.url_);
340 if (title_.compare(other.title_) < 0) {
341 // Take the last in alphabetical order or the longer one.
342 // This ensure empty string is replaced.
343 title_ = std::move(other.title_);
344 }
345 if (creation_time_us_ < other.creation_time_us_) {
346 creation_time_us_ = std::move(other.creation_time_us_);
347 }
348 if (state_ == UNSEEN) {
349 state_ = std::move(other.state_);
350 } else if (other.state_ != UNSEEN) {
351 // Both are not UNSEEN, take the newer one.
352 if (update_time_us_ < other.update_time_us_) {
353 state_ = std::move(other.state_);
354 } else if (update_time_us_ == other.update_time_us_) {
355 // Both states are likely the same, but if they are not, READ should wim.
pavely 2016/12/07 19:16:06 typo: wim => win.
Olivier 2016/12/08 08:04:07 Done.
356 if (other.state_ == READ) {
357 state_ = std::move(other.state_);
358 }
359 }
360 }
361 if (update_time_us_ < other.update_time_us_) {
362 update_time_us_ = std::move(other.update_time_us_);
363 }
364 #if !defined(NDEBUG)
365 std::unique_ptr<sync_pb::ReadingListSpecifics> new_this_pb(
366 AsReadingListSpecifics());
367 DCHECK(ReadingListStore::CompareEntriesForSync(*old_this_pb, *new_this_pb));
368 DCHECK(ReadingListStore::CompareEntriesForSync(*other_pb, *new_this_pb));
369 #endif
335 } 370 }
336 371
337 std::unique_ptr<reading_list::ReadingListLocal> 372 std::unique_ptr<reading_list::ReadingListLocal>
338 ReadingListEntry::AsReadingListLocal() const { 373 ReadingListEntry::AsReadingListLocal() const {
339 std::unique_ptr<reading_list::ReadingListLocal> pb_entry = 374 std::unique_ptr<reading_list::ReadingListLocal> pb_entry =
340 base::MakeUnique<reading_list::ReadingListLocal>(); 375 base::MakeUnique<reading_list::ReadingListLocal>();
341 376
342 // URL is used as the key for the database and sync as there is only one entry 377 // URL is used as the key for the database and sync as there is only one entry
343 // per URL. 378 // per URL.
344 pb_entry->set_entry_id(URL().spec()); 379 pb_entry->set_entry_id(URL().spec());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 case UNREAD: 451 case UNREAD:
417 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); 452 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD);
418 break; 453 break;
419 case UNSEEN: 454 case UNSEEN:
420 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); 455 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN);
421 break; 456 break;
422 } 457 }
423 458
424 return pb_entry; 459 return pb_entry;
425 } 460 }
426
427 bool ReadingListEntry::CompareEntryUpdateTime(const ReadingListEntry& lhs,
428 const ReadingListEntry& rhs) {
429 return lhs.UpdateTime() > rhs.UpdateTime();
430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698