Chromium Code Reviews| 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 base::Time& creation_time); | |
| 33 SavePageRequest(int64_t request_id, | |
| 34 const GURL& url, | |
| 35 const base::Time& creation_time, | |
| 36 const base::Time& activation_time); | |
| 37 ~SavePageRequest(); | |
| 38 | |
| 39 // Status of this request. | |
| 40 Status GetStatus(const base::Time& now); | |
| 41 | |
| 42 // Updates the |last_attempt_time_| and increments |attempt_count_|. | |
| 43 void MarkAttempStarted(const base::Time& start_time); | |
|
dougarnett
2016/05/02 15:54:20
Nice
| |
| 44 | |
| 45 // Marks attempt as completed and clears |last_attempt_time_|. | |
| 46 void MarkAttempCompleted(); | |
| 47 | |
| 48 int64_t request_id() const { return request_id_; } | |
| 49 | |
| 50 const GURL& url() const { return url_; } | |
| 51 | |
| 52 const ClientId& client_id() const { return client_id_; } | |
| 53 | |
| 54 const base::Time& creation_time() const { return creation_time_; } | |
| 55 | |
| 56 const base::Time& activation_time() const { return activation_time_; } | |
| 57 | |
| 58 int64_t attempt_count() const { return attempt_count_; } | |
| 59 | |
| 60 const base::Time& last_attempt_time() const { return last_attempt_time_; } | |
| 61 | |
| 62 private: | |
| 63 // ID of this request. | |
| 64 int64_t request_id_; | |
| 65 | |
| 66 // Online URL of a page to be offlined. | |
| 67 GURL url_; | |
| 68 | |
| 69 // Client ID related to the request. Contains namespace and ID assigned by the | |
| 70 // requester. | |
| 71 ClientId client_id_; | |
| 72 | |
| 73 // Time when this request was created. (Alternative 2). | |
| 74 base::Time creation_time_; | |
| 75 | |
| 76 // Time when this request will become active. | |
| 77 base::Time activation_time_; | |
| 78 | |
| 79 // Number of attempts made to get the page. | |
| 80 int attempt_count_; | |
| 81 | |
| 82 // Timestamp of the last request starting. | |
| 83 base::Time last_attempt_time_; | |
| 84 }; | |
| 85 | |
| 86 } // namespace offline_pages | |
| 87 | |
| 88 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_SAVE_PAGE_REQUEST_H_ | |
| OLD | NEW |