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

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

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 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_ 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "components/offline_pages/offline_page_item.h" 11 #include "components/offline_pages/offline_page_item.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 13
14 namespace offline_pages { 14 namespace offline_pages {
15 15
16 // Class representing a request to save page. 16 // Class representing a request to save page.
17 class SavePageRequest { 17 class SavePageRequest {
18 public: 18 public:
19 enum class RequestState {
20 AVAILABLE = 0, // Request can be scheduled when preconditions are met.
21 PAUSED = 1, // Request is not available until it is unpaused
22 PRERENDERING = 2, // Request is active in the pre-renderer
23 };
24
19 SavePageRequest(int64_t request_id, 25 SavePageRequest(int64_t request_id,
20 const GURL& url, 26 const GURL& url,
21 const ClientId& client_id, 27 const ClientId& client_id,
22 const base::Time& creation_time, 28 const base::Time& creation_time,
23 const bool user_requested); 29 const bool user_requested);
24 SavePageRequest(int64_t request_id, 30 SavePageRequest(int64_t request_id,
25 const GURL& url, 31 const GURL& url,
26 const ClientId& client_id, 32 const ClientId& client_id,
27 const base::Time& creation_time, 33 const base::Time& creation_time,
28 const base::Time& activation_time, 34 const base::Time& activation_time,
29 const bool user_requested); 35 const bool user_requested);
30 SavePageRequest(const SavePageRequest& other); 36 SavePageRequest(const SavePageRequest& other);
31 ~SavePageRequest(); 37 ~SavePageRequest();
32 38
33 // Updates the |last_attempt_time_| and increments |attempt_count_|. 39 // Updates the |last_attempt_time_| and increments |attempt_count_|.
34 void MarkAttemptStarted(const base::Time& start_time); 40 void MarkAttemptStarted(const base::Time& start_time);
35 41
36 // Marks attempt as completed and clears |last_attempt_time_|. 42 // Marks attempt as completed and clears |last_attempt_time_|.
37 void MarkAttemptCompleted(); 43 void MarkAttemptCompleted();
38 44
39 // Marks attempt as aborted. Specifically it clears |last_attempt_time_| 45 // Marks attempt as aborted. Specifically it clears |last_attempt_time_|
40 // and decrements |attempt_count_|. 46 // and decrements |attempt_count_|.
41 void MarkAttemptAborted(); 47 void MarkAttemptAborted();
42 48
49 // Mark the attempt as paused. It is not available for future prerendering
50 // until it has been explicitly unpaused.
51 void MarkAttemptPaused();
52
43 int64_t request_id() const { return request_id_; } 53 int64_t request_id() const { return request_id_; }
44 54
45 const GURL& url() const { return url_; } 55 const GURL& url() const { return url_; }
46 56
47 const ClientId& client_id() const { return client_id_; } 57 const ClientId& client_id() const { return client_id_; }
48 58
59 RequestState request_state() const { return state_; }
60 void set_request_state(RequestState new_state) { state_ = new_state; }
61
49 const base::Time& creation_time() const { return creation_time_; } 62 const base::Time& creation_time() const { return creation_time_; }
50 63
51 const base::Time& activation_time() const { return activation_time_; } 64 const base::Time& activation_time() const { return activation_time_; }
52 65
53 int64_t attempt_count() const { return attempt_count_; } 66 int64_t started_attempt_count() const { return started_attempt_count_; }
54 void set_attempt_count(int64_t attempt_count) { 67 void set_started_attempt_count(int64_t started_attempt_count) {
55 attempt_count_ = attempt_count; 68 started_attempt_count_ = started_attempt_count;
69 }
70
71 int64_t completed_attempt_count() const { return completed_attempt_count_; }
72 void set_completed_attempt_count(int64_t completed_attempt_count) {
73 completed_attempt_count_ = completed_attempt_count;
56 } 74 }
57 75
58 const base::Time& last_attempt_time() const { return last_attempt_time_; } 76 const base::Time& last_attempt_time() const { return last_attempt_time_; }
59 void set_last_attempt_time(const base::Time& last_attempt_time) { 77 void set_last_attempt_time(const base::Time& last_attempt_time) {
60 last_attempt_time_ = last_attempt_time; 78 last_attempt_time_ = last_attempt_time;
61 } 79 }
62 80
63 bool user_requested() const { return user_requested_; } 81 bool user_requested() const { return user_requested_; }
64 82
65 void set_user_requested(bool user_requested) { 83 void set_user_requested(bool user_requested) {
(...skipping 10 matching lines...) Expand all
76 // Client ID related to the request. Contains namespace and ID assigned by the 94 // Client ID related to the request. Contains namespace and ID assigned by the
77 // requester. 95 // requester.
78 ClientId client_id_; 96 ClientId client_id_;
79 97
80 // Time when this request was created. (Alternative 2). 98 // Time when this request was created. (Alternative 2).
81 base::Time creation_time_; 99 base::Time creation_time_;
82 100
83 // Time when this request will become active. 101 // Time when this request will become active.
84 base::Time activation_time_; 102 base::Time activation_time_;
85 103
86 // Number of attempts made to get the page. 104 // Number of attempts started to get the page. This may be different than the
87 int attempt_count_; 105 // number of attempts finished because we could crash.
fgorski 2016/08/08 17:48:05 s/finished/completed/
Pete Williamson 2016/08/08 18:44:29 Done.
106 int started_attempt_count_;
107
108 // Number of attempts we actually finished to get the page.
fgorski 2016/08/08 17:48:05 s/finished/completed/
Pete Williamson 2016/08/08 18:44:29 Done.
109 int completed_attempt_count_;
88 110
89 // Timestamp of the last request starting. 111 // Timestamp of the last request starting.
90 base::Time last_attempt_time_; 112 base::Time last_attempt_time_;
91 113
92 // Whether the user specifically requested this page (as opposed to a client 114 // Whether the user specifically requested this page (as opposed to a client
93 // like AGSA or Now.) 115 // like AGSA or Now.)
94 bool user_requested_; 116 bool user_requested_;
117
118 // The current state of this request
119 RequestState state_;
95 }; 120 };
96 121
97 } // namespace offline_pages 122 } // namespace offline_pages
98 123
99 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_ 124 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698