OLD | NEW |
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_OFFLINER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 | 9 |
10 namespace offline_pages { | 10 namespace offline_pages { |
11 | 11 |
12 class SavePageRequest; | 12 class SavePageRequest; |
13 | 13 |
14 // Interface of a class responsible for constructing an offline page given | 14 // Interface of a class responsible for constructing an offline page given |
15 // a request with a URL. | 15 // a request with a URL. |
16 class Offliner { | 16 class Offliner { |
17 public: | 17 public: |
18 // Status of processing an offline page request. | 18 // Status of processing an offline page request. |
19 enum class RequestStatus { | 19 // WARNING: You must update histograms.xml to match any changes made to |
20 UNKNOWN, // No status determined/reported yet. | 20 // this enum (ie, OfflinePagesBackgroundOfflinerRequestStatus histogram enum). |
21 LOADED, // Page loaded but not (yet) saved. | 21 enum RequestStatus { |
22 SAVED, // Offline page snapshot saved. | 22 UNKNOWN = 0, // No status determined/reported yet. |
23 CANCELED, // Request was canceled. | 23 LOADED = 1, // Page loaded but not (yet) saved. |
24 FAILED, // Failed to load page. | 24 SAVED = 2, // Offline page snapshot saved. |
25 FAILED_SAVE, // Failed to save loaded page. | 25 REQUEST_COORDINATOR_CANCELED = 3, // RequestCoordinator canceled request. |
26 // TODO(dougarnett): Define a retry-able failure status. | 26 PRERENDERING_CANCELED = 4, // Prerendering was canceled. |
| 27 PRERENDERING_FAILED = 5, // Prerendering failed to load page. |
| 28 SAVE_FAILED = 6, // Failed to save loaded page. |
| 29 // NOTE: insert new values above this line and update histogram enum too. |
| 30 STATUS_COUNT |
27 }; | 31 }; |
28 | 32 |
29 // Reports the completion status of a request. | 33 // Reports the completion status of a request. |
30 // TODO(dougarnett): consider passing back a request id instead of request. | 34 // TODO(dougarnett): consider passing back a request id instead of request. |
31 typedef base::Callback<void(const SavePageRequest&, RequestStatus)> | 35 typedef base::Callback<void(const SavePageRequest&, RequestStatus)> |
32 CompletionCallback; | 36 CompletionCallback; |
33 | 37 |
34 Offliner() {} | 38 Offliner() {} |
35 virtual ~Offliner() {} | 39 virtual ~Offliner() {} |
36 | 40 |
37 // Processes |request| to load and save an offline page. | 41 // Processes |request| to load and save an offline page. |
38 // Returns whether the request was accepted or not. |callback| is guaranteed | 42 // Returns whether the request was accepted or not. |callback| is guaranteed |
39 // to be called if the request was accepted and |Cancel()| is not called. | 43 // to be called if the request was accepted and |Cancel()| is not called. |
40 virtual bool LoadAndSave( | 44 virtual bool LoadAndSave( |
41 const SavePageRequest& request, | 45 const SavePageRequest& request, |
42 const CompletionCallback& callback) = 0; | 46 const CompletionCallback& callback) = 0; |
43 | 47 |
44 // Clears the currently processing request, if any. | 48 // Clears the currently processing request, if any, and skips running its |
| 49 // CompletionCallback. |
45 virtual void Cancel() = 0; | 50 virtual void Cancel() = 0; |
46 | 51 |
47 // TODO(dougarnett): add policy support methods. | 52 // TODO(dougarnett): add policy support methods. |
48 }; | 53 }; |
49 | 54 |
50 } // namespace offline_pages | 55 } // namespace offline_pages |
51 | 56 |
52 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_H_ | 57 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_H_ |
OLD | NEW |