| 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/offline_pages/background/save_page_request.h" | 5 #include "components/offline_pages/background/save_page_request.h" |
| 6 | 6 |
| 7 namespace offline_pages { | 7 namespace offline_pages { |
| 8 | 8 |
| 9 SavePageRequest::SavePageRequest(int64_t request_id, | 9 SavePageRequest::SavePageRequest(int64_t request_id, |
| 10 const GURL& url, | 10 const GURL& url, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 activation_time_(other.activation_time_), | 37 activation_time_(other.activation_time_), |
| 38 attempt_count_(other.attempt_count_), | 38 attempt_count_(other.attempt_count_), |
| 39 last_attempt_time_(other.last_attempt_time_) {} | 39 last_attempt_time_(other.last_attempt_time_) {} |
| 40 | 40 |
| 41 SavePageRequest::~SavePageRequest() {} | 41 SavePageRequest::~SavePageRequest() {} |
| 42 | 42 |
| 43 // TODO(fgorski): Introduce policy parameter, once policy is available. | 43 // TODO(fgorski): Introduce policy parameter, once policy is available. |
| 44 SavePageRequest::Status SavePageRequest::GetStatus( | 44 SavePageRequest::Status SavePageRequest::GetStatus( |
| 45 const base::Time& now) const { | 45 const base::Time& now) const { |
| 46 if (now < activation_time_) | 46 if (now < activation_time_) |
| 47 return Status::kNotReady; | 47 return Status::NOT_READY; |
| 48 | 48 |
| 49 // TODO(fgorski): enable check once policy available. | 49 // TODO(fgorski): enable check once policy available. |
| 50 // if (attempt_count_ >= policy.max_attempt_count) | 50 // if (attempt_count_ >= policy.max_attempt_count) |
| 51 // return Status::kFailed; | 51 // return Status::FAILED; |
| 52 | 52 |
| 53 // TODO(fgorski): enable check once policy available. | 53 // TODO(fgorski): enable check once policy available. |
| 54 // if (activation_time_+ policy.page_expiration_interval < now) | 54 // if (activation_time_+ policy.page_expiration_interval < now) |
| 55 // return Status::kExpired; | 55 // return Status::EXPIRED; |
| 56 | 56 |
| 57 if (creation_time_ < last_attempt_time_) | 57 if (creation_time_ < last_attempt_time_) |
| 58 return Status::kStarted; | 58 return Status::STARTED; |
| 59 | 59 |
| 60 return Status::kPending; | 60 return Status::PENDING; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) { | 63 void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) { |
| 64 DCHECK_LE(activation_time_, start_time); | 64 DCHECK_LE(activation_time_, start_time); |
| 65 // TODO(fgorski): As part of introducing policy in GetStatus, we can make a | 65 // TODO(fgorski): As part of introducing policy in GetStatus, we can make a |
| 66 // check here to ensure we only start tasks in status pending, and bail out in | 66 // check here to ensure we only start tasks in status pending, and bail out in |
| 67 // other cases. | 67 // other cases. |
| 68 last_attempt_time_ = start_time; | 68 last_attempt_time_ = start_time; |
| 69 ++attempt_count_; | 69 ++attempt_count_; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void SavePageRequest::MarkAttemptCompleted() { | 72 void SavePageRequest::MarkAttemptCompleted() { |
| 73 last_attempt_time_ = base::Time(); | 73 last_attempt_time_ = base::Time(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace offline_pages | 76 } // namespace offline_pages |
| OLD | NEW |