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" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 title = pb_entry.title(); | 317 title = pb_entry.title(); |
318 } | 318 } |
319 | 319 |
320 int64_t creation_time_us = 0; | 320 int64_t creation_time_us = 0; |
321 if (pb_entry.has_creation_time_us()) { | 321 if (pb_entry.has_creation_time_us()) { |
322 creation_time_us = pb_entry.creation_time_us(); | 322 creation_time_us = pb_entry.creation_time_us(); |
323 } | 323 } |
324 | 324 |
325 int64_t first_read_time_us = 0; | 325 int64_t first_read_time_us = 0; |
326 if (pb_entry.has_first_read_time_us()) { | 326 if (pb_entry.has_first_read_time_us()) { |
327 creation_time_us = pb_entry.first_read_time_us(); | 327 first_read_time_us = pb_entry.first_read_time_us(); |
328 } | 328 } |
329 | 329 |
330 int64_t update_time_us = 0; | 330 int64_t update_time_us = 0; |
331 if (pb_entry.has_update_time_us()) { | 331 if (pb_entry.has_update_time_us()) { |
332 update_time_us = pb_entry.update_time_us(); | 332 update_time_us = pb_entry.update_time_us(); |
333 } | 333 } |
334 | 334 |
335 State state = UNSEEN; | 335 State state = UNSEEN; |
336 if (pb_entry.has_status()) { | 336 if (pb_entry.has_status()) { |
337 switch (pb_entry.status()) { | 337 switch (pb_entry.status()) { |
(...skipping 23 matching lines...) Expand all Loading... |
361 other.AsReadingListSpecifics()); | 361 other.AsReadingListSpecifics()); |
362 #endif | 362 #endif |
363 DCHECK(url_ == other.url_); | 363 DCHECK(url_ == other.url_); |
364 if (title_.compare(other.title_) < 0) { | 364 if (title_.compare(other.title_) < 0) { |
365 // Take the last in alphabetical order or the longer one. | 365 // Take the last in alphabetical order or the longer one. |
366 // This ensure empty string is replaced. | 366 // This ensure empty string is replaced. |
367 title_ = std::move(other.title_); | 367 title_ = std::move(other.title_); |
368 } | 368 } |
369 if (creation_time_us_ < other.creation_time_us_) { | 369 if (creation_time_us_ < other.creation_time_us_) { |
370 creation_time_us_ = std::move(other.creation_time_us_); | 370 creation_time_us_ = std::move(other.creation_time_us_); |
371 } | 371 first_read_time_us_ = std::move(other.first_read_time_us_); |
372 if (state_ == UNSEEN) { | 372 } else if (creation_time_us_ == other.creation_time_us_) { |
373 state_ = std::move(other.state_); | 373 // The first_time_read_us from |other| is used if |
374 } else if (other.state_ != UNSEEN) { | 374 // - this.first_time_read_us == 0: the entry was never read in this device. |
375 // Both are not UNSEEN, take the newer one. | 375 // - this.first_time_read_us > other.first_time_read_us: the entry was |
376 if (update_time_us_ < other.update_time_us_) { | 376 // first read on another device. |
377 state_ = std::move(other.state_); | 377 if (first_read_time_us_ == 0 || |
378 } else if (update_time_us_ == other.update_time_us_) { | 378 (other.first_read_time_us_ != 0 && |
379 // Both states are likely the same, but if they are not, READ should win. | 379 other.first_read_time_us_ < first_read_time_us_)) { |
380 if (other.state_ == READ) { | 380 first_read_time_us_ = std::move(other.first_read_time_us_); |
381 state_ = std::move(other.state_); | |
382 } | |
383 } | 381 } |
384 } | 382 } |
385 if (update_time_us_ < other.update_time_us_) { | 383 if (update_time_us_ < other.update_time_us_) { |
386 update_time_us_ = std::move(other.update_time_us_); | 384 update_time_us_ = std::move(other.update_time_us_); |
| 385 state_ = std::move(other.state_); |
| 386 } else if (update_time_us_ == other.update_time_us_) { |
| 387 if (state_ == UNSEEN) { |
| 388 state_ = std::move(other.state_); |
| 389 } else if (other.state_ == READ) { |
| 390 state_ = std::move(other.state_); |
| 391 } |
387 } | 392 } |
388 #if !defined(NDEBUG) | 393 #if !defined(NDEBUG) |
389 std::unique_ptr<sync_pb::ReadingListSpecifics> new_this_pb( | 394 std::unique_ptr<sync_pb::ReadingListSpecifics> new_this_pb( |
390 AsReadingListSpecifics()); | 395 AsReadingListSpecifics()); |
391 DCHECK(ReadingListStore::CompareEntriesForSync(*old_this_pb, *new_this_pb)); | 396 DCHECK(ReadingListStore::CompareEntriesForSync(*old_this_pb, *new_this_pb)); |
392 DCHECK(ReadingListStore::CompareEntriesForSync(*other_pb, *new_this_pb)); | 397 DCHECK(ReadingListStore::CompareEntriesForSync(*other_pb, *new_this_pb)); |
393 #endif | 398 #endif |
394 } | 399 } |
395 | 400 |
396 std::unique_ptr<reading_list::ReadingListLocal> | 401 std::unique_ptr<reading_list::ReadingListLocal> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 case UNREAD: | 482 case UNREAD: |
478 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); | 483 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
479 break; | 484 break; |
480 case UNSEEN: | 485 case UNSEEN: |
481 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); | 486 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); |
482 break; | 487 break; |
483 } | 488 } |
484 | 489 |
485 return pb_entry; | 490 return pb_entry; |
486 } | 491 } |
OLD | NEW |