| 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/core/background/save_page_request.h" | 5 #include "components/offline_pages/core/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, |
| 11 const ClientId& client_id, | 11 const ClientId& client_id, |
| 12 const base::Time& creation_time, | 12 const base::Time& creation_time, |
| 13 const bool user_requested) | 13 const bool user_requested) |
| 14 : request_id_(request_id), | 14 : request_id_(request_id), |
| 15 url_(url), | 15 url_(url), |
| 16 client_id_(client_id), | 16 client_id_(client_id), |
| 17 creation_time_(creation_time), | 17 creation_time_(creation_time), |
| 18 activation_time_(creation_time), | |
| 19 started_attempt_count_(0), | 18 started_attempt_count_(0), |
| 20 completed_attempt_count_(0), | 19 completed_attempt_count_(0), |
| 21 user_requested_(user_requested), | 20 user_requested_(user_requested), |
| 22 state_(RequestState::AVAILABLE) {} | |
| 23 | |
| 24 SavePageRequest::SavePageRequest(int64_t request_id, | |
| 25 const GURL& url, | |
| 26 const ClientId& client_id, | |
| 27 const base::Time& creation_time, | |
| 28 const base::Time& activation_time, | |
| 29 const bool user_requested) | |
| 30 : request_id_(request_id), | |
| 31 url_(url), | |
| 32 client_id_(client_id), | |
| 33 creation_time_(creation_time), | |
| 34 activation_time_(activation_time), | |
| 35 started_attempt_count_(0), | |
| 36 completed_attempt_count_(0), | |
| 37 user_requested_(user_requested), | |
| 38 state_(RequestState::AVAILABLE) {} | 21 state_(RequestState::AVAILABLE) {} |
| 39 | 22 |
| 40 SavePageRequest::SavePageRequest(const SavePageRequest& other) | 23 SavePageRequest::SavePageRequest(const SavePageRequest& other) |
| 41 : request_id_(other.request_id_), | 24 : request_id_(other.request_id_), |
| 42 url_(other.url_), | 25 url_(other.url_), |
| 43 client_id_(other.client_id_), | 26 client_id_(other.client_id_), |
| 44 creation_time_(other.creation_time_), | 27 creation_time_(other.creation_time_), |
| 45 activation_time_(other.activation_time_), | |
| 46 started_attempt_count_(other.started_attempt_count_), | 28 started_attempt_count_(other.started_attempt_count_), |
| 47 completed_attempt_count_(other.completed_attempt_count_), | 29 completed_attempt_count_(other.completed_attempt_count_), |
| 48 last_attempt_time_(other.last_attempt_time_), | 30 last_attempt_time_(other.last_attempt_time_), |
| 49 user_requested_(other.user_requested_), | 31 user_requested_(other.user_requested_), |
| 50 state_(other.state_), | 32 state_(other.state_), |
| 51 original_url_(other.original_url_) {} | 33 original_url_(other.original_url_) {} |
| 52 | 34 |
| 53 SavePageRequest::~SavePageRequest() {} | 35 SavePageRequest::~SavePageRequest() {} |
| 54 | 36 |
| 55 bool SavePageRequest::operator==(const SavePageRequest& other) const { | 37 bool SavePageRequest::operator==(const SavePageRequest& other) const { |
| 56 return request_id_ == other.request_id_ && url_ == other.url_ && | 38 return request_id_ == other.request_id_ && url_ == other.url_ && |
| 57 client_id_ == other.client_id_ && | 39 client_id_ == other.client_id_ && |
| 58 creation_time_ == other.creation_time_ && | 40 creation_time_ == other.creation_time_ && |
| 59 activation_time_ == other.activation_time_ && | |
| 60 started_attempt_count_ == other.started_attempt_count_ && | 41 started_attempt_count_ == other.started_attempt_count_ && |
| 61 completed_attempt_count_ == other.completed_attempt_count_ && | 42 completed_attempt_count_ == other.completed_attempt_count_ && |
| 62 last_attempt_time_ == other.last_attempt_time_ && | 43 last_attempt_time_ == other.last_attempt_time_ && |
| 63 state_ == other.state_ && original_url_ == other.original_url_; | 44 state_ == other.state_ && original_url_ == other.original_url_; |
| 64 } | 45 } |
| 65 | 46 |
| 66 void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) { | 47 void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) { |
| 67 DCHECK_LE(activation_time_, start_time); | |
| 68 last_attempt_time_ = start_time; | 48 last_attempt_time_ = start_time; |
| 69 ++started_attempt_count_; | 49 ++started_attempt_count_; |
| 70 state_ = RequestState::OFFLINING; | 50 state_ = RequestState::OFFLINING; |
| 71 } | 51 } |
| 72 | 52 |
| 73 void SavePageRequest::MarkAttemptCompleted() { | 53 void SavePageRequest::MarkAttemptCompleted() { |
| 74 ++completed_attempt_count_; | 54 ++completed_attempt_count_; |
| 75 state_ = RequestState::AVAILABLE; | 55 state_ = RequestState::AVAILABLE; |
| 76 } | 56 } |
| 77 | 57 |
| 78 void SavePageRequest::MarkAttemptAborted() { | 58 void SavePageRequest::MarkAttemptAborted() { |
| 79 DCHECK_GT(started_attempt_count_, 0); | 59 DCHECK_GT(started_attempt_count_, 0); |
| 80 // We intentinally do not increment the completed_attempt_count_, since this | 60 // We intentinally do not increment the completed_attempt_count_, since this |
| 81 // was killed before it completed, so we could use the phone or browser for | 61 // was killed before it completed, so we could use the phone or browser for |
| 82 // other things. | 62 // other things. |
| 83 if (state_ == RequestState::OFFLINING) | 63 if (state_ == RequestState::OFFLINING) |
| 84 state_ = RequestState::AVAILABLE; | 64 state_ = RequestState::AVAILABLE; |
| 85 } | 65 } |
| 86 | 66 |
| 87 void SavePageRequest::MarkAttemptPaused() { | 67 void SavePageRequest::MarkAttemptPaused() { |
| 88 state_ = RequestState::PAUSED; | 68 state_ = RequestState::PAUSED; |
| 89 } | 69 } |
| 90 | 70 |
| 91 } // namespace offline_pages | 71 } // namespace offline_pages |
| OLD | NEW |