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