| 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 enum class Status { |
| 20 kNotReady, // Component requested a page be saved, but not until |
| 21 // |activation_time_|. |
| 22 kPending, // Page request is pending, and coordinator can attempt it |
| 23 // when it gets a chance to. |
| 24 kStarted, // The request is currently being processed. |
| 25 kFailed, // Page request failed many times and will no longer be |
| 26 // retried. |
| 27 kExpired, // Save page request expired without being fulfilled. |
| 28 }; |
| 29 |
| 30 SavePageRequest(int64_t request_id, |
| 31 const GURL& url, |
| 32 const ClientId& client_id, |
| 33 const base::Time& creation_time); |
| 34 SavePageRequest(int64_t request_id, |
| 35 const GURL& url, |
| 36 const ClientId& client_id, |
| 37 const base::Time& creation_time, |
| 38 const base::Time& activation_time); |
| 39 ~SavePageRequest(); |
| 40 |
| 41 // Status of this request. |
| 42 Status GetStatus(const base::Time& now) const; |
| 43 |
| 44 // Updates the |last_attempt_time_| and increments |attempt_count_|. |
| 45 void MarkAttemptStarted(const base::Time& start_time); |
| 46 |
| 47 // Marks attempt as completed and clears |last_attempt_time_|. |
| 48 void MarkAttemptCompleted(); |
| 49 |
| 50 int64_t request_id() const { return request_id_; } |
| 51 |
| 52 const GURL& url() const { return url_; } |
| 53 |
| 54 const ClientId& client_id() const { return client_id_; } |
| 55 |
| 56 const base::Time& creation_time() const { return creation_time_; } |
| 57 |
| 58 const base::Time& activation_time() const { return activation_time_; } |
| 59 |
| 60 int64_t attempt_count() const { return attempt_count_; } |
| 61 |
| 62 const base::Time& last_attempt_time() const { return last_attempt_time_; } |
| 63 |
| 64 private: |
| 65 // ID of this request. |
| 66 int64_t request_id_; |
| 67 |
| 68 // Online URL of a page to be offlined. |
| 69 GURL url_; |
| 70 |
| 71 // Client ID related to the request. Contains namespace and ID assigned by the |
| 72 // requester. |
| 73 ClientId client_id_; |
| 74 |
| 75 // Time when this request was created. (Alternative 2). |
| 76 base::Time creation_time_; |
| 77 |
| 78 // Time when this request will become active. |
| 79 base::Time activation_time_; |
| 80 |
| 81 // Number of attempts made to get the page. |
| 82 int attempt_count_; |
| 83 |
| 84 // Timestamp of the last request starting. |
| 85 base::Time last_attempt_time_; |
| 86 }; |
| 87 |
| 88 } // namespace offline_pages |
| 89 |
| 90 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_ |
| OLD | NEW |