Chromium Code Reviews| 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, |
| 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 was_user_requested) | 13 const bool was_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), | 18 activation_time_(creation_time), |
| 19 attempt_count_(0), | 19 started_attempt_count_(0), |
| 20 user_requested_(was_user_requested) {} | 20 completed_attempt_count_(0), |
| 21 user_requested_(was_user_requested), | |
| 22 state_(RequestState::AVAILABLE) {} | |
| 21 | 23 |
| 22 SavePageRequest::SavePageRequest(int64_t request_id, | 24 SavePageRequest::SavePageRequest(int64_t request_id, |
| 23 const GURL& url, | 25 const GURL& url, |
| 24 const ClientId& client_id, | 26 const ClientId& client_id, |
| 25 const base::Time& creation_time, | 27 const base::Time& creation_time, |
| 26 const base::Time& activation_time, | 28 const base::Time& activation_time, |
| 27 const bool user_requested) | 29 const bool user_requested) |
| 28 : request_id_(request_id), | 30 : request_id_(request_id), |
| 29 url_(url), | 31 url_(url), |
| 30 client_id_(client_id), | 32 client_id_(client_id), |
| 31 creation_time_(creation_time), | 33 creation_time_(creation_time), |
| 32 activation_time_(activation_time), | 34 activation_time_(activation_time), |
| 33 attempt_count_(0), | 35 started_attempt_count_(0), |
| 34 user_requested_(user_requested) {} | 36 completed_attempt_count_(0), |
| 37 user_requested_(user_requested), | |
| 38 state_(RequestState::AVAILABLE) {} | |
| 35 | 39 |
| 36 SavePageRequest::SavePageRequest(const SavePageRequest& other) | 40 SavePageRequest::SavePageRequest(const SavePageRequest& other) |
| 37 : request_id_(other.request_id_), | 41 : request_id_(other.request_id_), |
| 38 url_(other.url_), | 42 url_(other.url_), |
| 39 client_id_(other.client_id_), | 43 client_id_(other.client_id_), |
| 40 creation_time_(other.creation_time_), | 44 creation_time_(other.creation_time_), |
| 41 activation_time_(other.activation_time_), | 45 activation_time_(other.activation_time_), |
| 42 attempt_count_(other.attempt_count_), | 46 started_attempt_count_(other.started_attempt_count_), |
| 47 completed_attempt_count_(other.completed_attempt_count_), | |
| 43 last_attempt_time_(other.last_attempt_time_), | 48 last_attempt_time_(other.last_attempt_time_), |
| 44 user_requested_(other.user_requested_) {} | 49 user_requested_(other.user_requested_), |
| 50 state_(other.state_) {} | |
| 45 | 51 |
| 46 SavePageRequest::~SavePageRequest() {} | 52 SavePageRequest::~SavePageRequest() {} |
| 47 | 53 |
| 48 void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) { | 54 void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) { |
| 49 DCHECK_LE(activation_time_, start_time); | 55 DCHECK_LE(activation_time_, start_time); |
| 50 // TODO(fgorski): As part of introducing policy in GetStatus, we can make a | 56 // TODO(fgorski): As part of introducing policy in GetStatus, we can make a |
| 51 // check here to ensure we only start tasks in status pending, and bail out in | 57 // check here to ensure we only start tasks in status pending, and bail out in |
| 52 // other cases. | 58 // other cases. |
| 53 last_attempt_time_ = start_time; | 59 last_attempt_time_ = start_time; |
| 54 ++attempt_count_; | 60 ++started_attempt_count_; |
| 61 state_ = RequestState::PRERENDERING; | |
|
dougarnett
2016/08/19 20:21:26
I don't understand why this internally sets a spec
Pete Williamson
2016/08/22 16:33:29
The thinking was that we might someday have other
| |
| 55 } | 62 } |
| 56 | 63 |
| 57 void SavePageRequest::MarkAttemptCompleted() { | 64 void SavePageRequest::MarkAttemptCompleted() { |
| 58 last_attempt_time_ = base::Time(); | 65 ++completed_attempt_count_; |
| 66 state_ = RequestState::AVAILABLE; | |
| 59 } | 67 } |
| 60 | 68 |
| 61 void SavePageRequest::MarkAttemptAborted() { | 69 void SavePageRequest::MarkAttemptAborted() { |
| 62 DCHECK_GT(attempt_count_, 0); | 70 DCHECK_GT(started_attempt_count_, 0); |
| 63 last_attempt_time_ = base::Time(); | 71 // We intentinally do not increment the completed_attempt_count_, since this |
| 64 // TODO(dougarnett): Would be safer if we had two persisted counters | 72 // was killed before it completed, so we could use the phone or browser for |
| 65 // (attempts_started and attempts_completed) rather just one with decrement. | 73 // other things. |
| 66 --attempt_count_; | 74 state_ = RequestState::AVAILABLE; |
| 75 } | |
| 76 | |
| 77 void SavePageRequest::MarkAttemptPaused() { | |
| 78 state_ = RequestState::PAUSED; | |
| 67 } | 79 } |
| 68 | 80 |
| 69 } // namespace offline_pages | 81 } // namespace offline_pages |
| OLD | NEW |