| 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 // Completion status of processing an offline page request. | 18 // Status of processing an offline page request. |
| 19 enum CompletionStatus { | 19 enum class RequestStatus { |
| 20 SAVED = 0, | 20 UNKNOWN, // No status determined/reported yet. |
| 21 CANCELED = 1, | 21 LOADED, // Page loaded but not (yet) saved. |
| 22 FAILED_CONSIDER_RETRY = 2, | 22 SAVED, // Offline page snapshot saved. |
| 23 FAILED_DO_NOT_RETRY = 3, | 23 CANCELED, // Request was canceled. |
| 24 UNKNOWN = 4, | 24 FAILED, // Request failed. |
| 25 // TODO(dougarnett): Define a retry-able failure status. |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 // Reports the completion status of a request. | 28 // Reports the completion status of a request. |
| 28 // TODO(dougarnett): consider passing back a request id instead of request. | 29 // TODO(dougarnett): consider passing back a request id instead of request. |
| 29 typedef base::Callback<void(const SavePageRequest&, CompletionStatus)> | 30 typedef base::Callback<void(const SavePageRequest&, RequestStatus)> |
| 30 CompletionCallback; | 31 CompletionCallback; |
| 31 | 32 |
| 32 Offliner() {} | 33 Offliner() {} |
| 33 virtual ~Offliner() {} | 34 virtual ~Offliner() {} |
| 34 | 35 |
| 35 // Processes |request| to load and save an offline page. | 36 // Processes |request| to load and save an offline page. |
| 36 // Returns whether the request was accepted or not. | 37 // Returns whether the request was accepted or not. |
| 37 virtual bool LoadAndSave( | 38 virtual bool LoadAndSave( |
| 38 const SavePageRequest& request, | 39 const SavePageRequest& request, |
| 39 const CompletionCallback& callback) = 0; | 40 const CompletionCallback& callback) = 0; |
| 40 | 41 |
| 41 // Clears the currently processing request, if any. | 42 // Clears the currently processing request, if any. |
| 42 virtual void Cancel() = 0; | 43 virtual void Cancel() = 0; |
| 43 | 44 |
| 44 // TODO(dougarnett): add policy support methods. | 45 // TODO(dougarnett): add policy support methods. |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 } // namespace offline_pages | 48 } // namespace offline_pages |
| 48 | 49 |
| 49 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_H_ | 50 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_H_ |
| OLD | NEW |