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_CORE_BACKGROUND_OFFLINER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 LOADING_NOT_ACCEPTED = 12, | 52 LOADING_NOT_ACCEPTED = 12, |
53 // The RequestCoordinator did not start loading the request because | 53 // The RequestCoordinator did not start loading the request because |
54 // updating the status in the request queue failed. | 54 // updating the status in the request queue failed. |
55 QUEUE_UPDATE_FAILED = 13, | 55 QUEUE_UPDATE_FAILED = 13, |
56 // Scheduler canceled processing of requests. | 56 // Scheduler canceled processing of requests. |
57 BACKGROUND_SCHEDULER_CANCELED = 14, | 57 BACKGROUND_SCHEDULER_CANCELED = 14, |
58 // NOTE: insert new values above this line and update histogram enum too. | 58 // NOTE: insert new values above this line and update histogram enum too. |
59 STATUS_COUNT | 59 STATUS_COUNT |
60 }; | 60 }; |
61 | 61 |
| 62 // Reports the load progress of a request. |
| 63 typedef base::Callback<void(const SavePageRequest&, int64_t received_bytes)> |
| 64 ProgressCallback; |
62 // Reports the completion status of a request. | 65 // Reports the completion status of a request. |
63 // TODO(dougarnett): consider passing back a request id instead of request. | 66 // TODO(dougarnett): consider passing back a request id instead of request. |
64 typedef base::Callback<void(const SavePageRequest&, RequestStatus)> | 67 typedef base::Callback<void(const SavePageRequest&, RequestStatus)> |
65 CompletionCallback; | 68 CompletionCallback; |
66 // Reports that the cancel operation has completed. | 69 // Reports that the cancel operation has completed. |
67 // TODO(chili): make save operation cancellable. | 70 // TODO(chili): make save operation cancellable. |
68 typedef base::Callback<void(int64_t request_id)> CancelCallback; | 71 typedef base::Callback<void(int64_t request_id)> CancelCallback; |
69 | 72 |
70 Offliner() {} | 73 Offliner() {} |
71 virtual ~Offliner() {} | 74 virtual ~Offliner() {} |
72 | 75 |
73 // Processes |request| to load and save an offline page. | 76 // Processes |request| to load and save an offline page. |
74 // Returns whether the request was accepted or not. |callback| is guaranteed | 77 // Returns whether the request was accepted or not. |completion_callback| is |
75 // to be called if the request was accepted and |Cancel()| is not called. | 78 // guaranteed to be called if the request was accepted and |Cancel()| is not |
| 79 // called on it. |progress_callback| is invoked periodically to report the |
| 80 // number of bytes received from the network (for UI purposes). |
76 virtual bool LoadAndSave(const SavePageRequest& request, | 81 virtual bool LoadAndSave(const SavePageRequest& request, |
77 const CompletionCallback& callback) = 0; | 82 const CompletionCallback& completion_callback, |
| 83 const ProgressCallback& progress_callback) = 0; |
78 | 84 |
79 // Clears the currently processing request, if any, and skips running its | 85 // Clears the currently processing request, if any, and skips running its |
80 // CompletionCallback. | 86 // CompletionCallback. |
81 virtual void Cancel(const CancelCallback& callback) = 0; | 87 virtual void Cancel(const CancelCallback& callback) = 0; |
82 | 88 |
83 // Handles timeout scenario. Returns true if lowbar is met and try to do a | 89 // Handles timeout scenario. Returns true if lowbar is met and try to do a |
84 // snapshot of the current webcontents. | 90 // snapshot of the current webcontents. |
85 virtual bool HandleTimeout(const SavePageRequest& request) = 0; | 91 virtual bool HandleTimeout(const SavePageRequest& request) = 0; |
86 | 92 |
87 // TODO(dougarnett): add policy support methods. | 93 // TODO(dougarnett): add policy support methods. |
88 }; | 94 }; |
89 | 95 |
90 } // namespace offline_pages | 96 } // namespace offline_pages |
91 | 97 |
92 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_H_ | 98 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_H_ |
OLD | NEW |