Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: components/offline_pages/background/save_page_request.cc

Issue 2218403002: Change database scheme - add state and start tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete old database if any Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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)
fgorski 2016/08/08 17:48:05 nit: rename to user_requested, please.
Pete Williamson 2016/08/08 18:44:29 Is it OK to do that later? was_user_requested is
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;
55 } 62 }
56 63
57 void SavePageRequest::MarkAttemptCompleted() { 64 void SavePageRequest::MarkAttemptCompleted() {
58 last_attempt_time_ = base::Time(); 65 last_attempt_time_ = base::Time();
66 ++completed_attempt_count_;
67 state_ = RequestState::AVAILABLE;
59 } 68 }
60 69
61 void SavePageRequest::MarkAttemptAborted() { 70 void SavePageRequest::MarkAttemptAborted() {
62 DCHECK_GT(attempt_count_, 0); 71 DCHECK_GT(started_attempt_count_, 0);
72 // We intentinally do not increment the completed_attempt_count_, since this
fgorski 2016/08/08 17:48:05 typo in: intentinally extra space after "intentio
Pete Williamson 2016/08/08 18:44:29 Done.
73 // was killed before it had a chance to run to completion so we could use the
fgorski 2016/08/08 17:48:05 how about: chance to complete. Phone was used for
chili 2016/08/08 18:17:01 even shorter: "since this was killed before it com
Pete Williamson 2016/08/08 18:44:29 Done.
Pete Williamson 2016/08/08 18:44:29 Done.
74 // phone or browser for other things.
63 last_attempt_time_ = base::Time(); 75 last_attempt_time_ = base::Time();
64 // TODO(dougarnett): Would be safer if we had two persisted counters 76 state_ = RequestState::AVAILABLE;
65 // (attempts_started and attempts_completed) rather just one with decrement. 77 }
66 --attempt_count_; 78
79 void SavePageRequest::MarkAttemptPaused() {
80 DCHECK_GT(started_attempt_count_, 0);
fgorski 2016/08/08 17:48:05 Would it not be possible to pause a task before it
Pete Williamson 2016/08/08 18:44:28 Good catch, removed DCHECK
81 state_ = RequestState::PAUSED;
fgorski 2016/08/08 17:48:05 can we mark last_attempt_time_ = base::Time(), sin
Pete Williamson 2016/08/08 18:44:28 In the normal case the request has not been attemp
fgorski 2016/08/08 22:35:33 Then why clearing it in cases where the attempt wa
Pete Williamson 2016/08/08 22:56:56 OK, I chose to stop clearing it and rely solely on
67 } 82 }
68 83
69 } // namespace offline_pages 84 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698