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/core/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/core/offline_url_utils.h" |
10 #include "components/reading_list/ios/proto/reading_list.pb.h" | 10 #include "components/reading_list/core/proto/reading_list.pb.h" |
11 #include "components/reading_list/ios/reading_list_store.h" | 11 #include "components/reading_list/core/reading_list_store.h" |
12 #include "components/sync/protocol/reading_list_specifics.pb.h" | 12 #include "components/sync/protocol/reading_list_specifics.pb.h" |
13 #include "net/base/backoff_entry_serializer.h" | 13 #include "net/base/backoff_entry_serializer.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 // Converts |time| to the number of microseconds since Jan 1st 1970. | 16 // Converts |time| to the number of microseconds since Jan 1st 1970. |
17 int64_t TimeToUS(const base::Time& time) { | 17 int64_t TimeToUS(const base::Time& time) { |
18 return (time - base::Time::UnixEpoch()).InMicroseconds(); | 18 return (time - base::Time::UnixEpoch()).InMicroseconds(); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 distillation_size_ = distilation_size; | 229 distillation_size_ = distilation_size; |
230 backoff_->Reset(); | 230 backoff_->Reset(); |
231 failed_download_counter_ = 0; | 231 failed_download_counter_ = 0; |
232 } | 232 } |
233 | 233 |
234 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { | 234 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { |
235 DCHECK(distilled_state != PROCESSED); // use SetDistilledPath instead. | 235 DCHECK(distilled_state != PROCESSED); // use SetDistilledPath instead. |
236 DCHECK(distilled_state != WAITING); | 236 DCHECK(distilled_state != WAITING); |
237 // Increase time until next retry exponentially if the state change from a | 237 // Increase time until next retry exponentially if the state change from a |
238 // non-error state to an error state. | 238 // non-error state to an error state. |
239 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && | 239 if ((distilled_state == WILL_RETRY || |
240 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) { | 240 distilled_state == DISTILLATION_ERROR) && |
| 241 distilled_state_ != WILL_RETRY && |
| 242 distilled_state_ != DISTILLATION_ERROR) { |
241 backoff_->InformOfRequest(false); | 243 backoff_->InformOfRequest(false); |
242 failed_download_counter_++; | 244 failed_download_counter_++; |
243 } | 245 } |
244 | 246 |
245 distilled_state_ = distilled_state; | 247 distilled_state_ = distilled_state; |
246 distilled_path_ = base::FilePath(); | 248 distilled_path_ = base::FilePath(); |
247 distilled_url_ = GURL::EmptyGURL(); | 249 distilled_url_ = GURL::EmptyGURL(); |
248 } | 250 } |
249 | 251 |
250 int64_t ReadingListEntry::UpdateTime() const { | 252 int64_t ReadingListEntry::UpdateTime() const { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 break; | 331 break; |
330 case reading_list::ReadingListLocal::PROCESSING: | 332 case reading_list::ReadingListLocal::PROCESSING: |
331 distillation_state = ReadingListEntry::PROCESSING; | 333 distillation_state = ReadingListEntry::PROCESSING; |
332 break; | 334 break; |
333 case reading_list::ReadingListLocal::PROCESSED: | 335 case reading_list::ReadingListLocal::PROCESSED: |
334 distillation_state = ReadingListEntry::PROCESSED; | 336 distillation_state = ReadingListEntry::PROCESSED; |
335 break; | 337 break; |
336 case reading_list::ReadingListLocal::WILL_RETRY: | 338 case reading_list::ReadingListLocal::WILL_RETRY: |
337 distillation_state = ReadingListEntry::WILL_RETRY; | 339 distillation_state = ReadingListEntry::WILL_RETRY; |
338 break; | 340 break; |
339 case reading_list::ReadingListLocal::ERROR: | 341 case reading_list::ReadingListLocal::DISTILLATION_ERROR: |
340 distillation_state = ReadingListEntry::ERROR; | 342 distillation_state = ReadingListEntry::DISTILLATION_ERROR; |
341 break; | 343 break; |
342 } | 344 } |
343 } | 345 } |
344 | 346 |
345 base::FilePath distilled_path; | 347 base::FilePath distilled_path; |
346 if (pb_entry.has_distilled_path()) { | 348 if (pb_entry.has_distilled_path()) { |
347 distilled_path = base::FilePath(pb_entry.distilled_path()); | 349 distilled_path = base::FilePath::FromUTF8Unsafe(pb_entry.distilled_path()); |
348 } | 350 } |
349 | 351 |
350 GURL distilled_url; | 352 GURL distilled_url; |
351 if (pb_entry.has_distilled_url()) { | 353 if (pb_entry.has_distilled_url()) { |
352 distilled_url = GURL(pb_entry.distilled_url()); | 354 distilled_url = GURL(pb_entry.distilled_url()); |
353 } | 355 } |
354 | 356 |
355 int64_t distillation_time_us = 0; | 357 int64_t distillation_time_us = 0; |
356 if (pb_entry.has_distillation_time_us()) { | 358 if (pb_entry.has_distillation_time_us()) { |
357 distillation_time_us = pb_entry.distillation_time_us(); | 359 distillation_time_us = pb_entry.distillation_time_us(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 pb_entry->set_status(reading_list::ReadingListLocal::READ); | 516 pb_entry->set_status(reading_list::ReadingListLocal::READ); |
515 break; | 517 break; |
516 case UNREAD: | 518 case UNREAD: |
517 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); | 519 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); |
518 break; | 520 break; |
519 case UNSEEN: | 521 case UNSEEN: |
520 pb_entry->set_status(reading_list::ReadingListLocal::UNSEEN); | 522 pb_entry->set_status(reading_list::ReadingListLocal::UNSEEN); |
521 break; | 523 break; |
522 } | 524 } |
523 | 525 |
524 reading_list::ReadingListLocal::DistillationState distilation_state; | 526 reading_list::ReadingListLocal::DistillationState distilation_state = |
| 527 reading_list::ReadingListLocal::WAITING; |
525 switch (DistilledState()) { | 528 switch (DistilledState()) { |
526 case ReadingListEntry::WAITING: | 529 case ReadingListEntry::WAITING: |
527 distilation_state = reading_list::ReadingListLocal::WAITING; | 530 distilation_state = reading_list::ReadingListLocal::WAITING; |
528 break; | 531 break; |
529 case ReadingListEntry::PROCESSING: | 532 case ReadingListEntry::PROCESSING: |
530 distilation_state = reading_list::ReadingListLocal::PROCESSING; | 533 distilation_state = reading_list::ReadingListLocal::PROCESSING; |
531 break; | 534 break; |
532 case ReadingListEntry::PROCESSED: | 535 case ReadingListEntry::PROCESSED: |
533 distilation_state = reading_list::ReadingListLocal::PROCESSED; | 536 distilation_state = reading_list::ReadingListLocal::PROCESSED; |
534 break; | 537 break; |
535 case ReadingListEntry::WILL_RETRY: | 538 case ReadingListEntry::WILL_RETRY: |
536 distilation_state = reading_list::ReadingListLocal::WILL_RETRY; | 539 distilation_state = reading_list::ReadingListLocal::WILL_RETRY; |
537 break; | 540 break; |
538 case ReadingListEntry::ERROR: | 541 case ReadingListEntry::DISTILLATION_ERROR: |
539 distilation_state = reading_list::ReadingListLocal::ERROR; | 542 distilation_state = reading_list::ReadingListLocal::DISTILLATION_ERROR; |
540 break; | 543 break; |
541 } | 544 } |
542 pb_entry->set_distillation_state(distilation_state); | 545 pb_entry->set_distillation_state(distilation_state); |
543 if (!DistilledPath().empty()) { | 546 if (!DistilledPath().empty()) { |
544 pb_entry->set_distilled_path(DistilledPath().value()); | 547 pb_entry->set_distilled_path(DistilledPath().AsUTF8Unsafe()); |
545 } | 548 } |
546 if (DistilledURL().is_valid()) { | 549 if (DistilledURL().is_valid()) { |
547 pb_entry->set_distilled_url(DistilledURL().spec()); | 550 pb_entry->set_distilled_url(DistilledURL().spec()); |
548 } | 551 } |
549 if (DistillationTime()) { | 552 if (DistillationTime()) { |
550 pb_entry->set_distillation_time_us(DistillationTime()); | 553 pb_entry->set_distillation_time_us(DistillationTime()); |
551 } | 554 } |
552 if (DistillationSize()) { | 555 if (DistillationSize()) { |
553 pb_entry->set_distillation_size(DistillationSize()); | 556 pb_entry->set_distillation_size(DistillationSize()); |
554 } | 557 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 case UNREAD: | 592 case UNREAD: |
590 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); | 593 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
591 break; | 594 break; |
592 case UNSEEN: | 595 case UNSEEN: |
593 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); | 596 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); |
594 break; | 597 break; |
595 } | 598 } |
596 | 599 |
597 return pb_entry; | 600 return pb_entry; |
598 } | 601 } |
OLD | NEW |