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_REQUEST_COORDINATOR_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" |
9 | 13 |
10 namespace offline_pages { | 14 namespace offline_pages { |
11 | 15 |
| 16 class OfflinerPolicy; |
| 17 class OfflinerFactory; |
| 18 class Offliner; |
12 class SavePageRequest; | 19 class SavePageRequest; |
13 | 20 |
14 // Coordinates queueing and processing save page later requests. | 21 // Coordinates queueing and processing save page later requests. |
15 class RequestCoordinator { | 22 class RequestCoordinator : public KeyedService { |
16 public: | 23 public: |
17 // Callback to report when the processing of a triggered task is complete. | 24 // Callback to report when the processing of a triggered task is complete. |
18 typedef base::Callback<void()> ProcessingDoneCallback; | 25 typedef base::Callback<void()> ProcessingDoneCallback; |
19 | 26 |
20 // TODO(dougarnett): How to inject Offliner factories and policy objects. | 27 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
21 RequestCoordinator(); | 28 std::unique_ptr<OfflinerFactory> factory); |
22 | 29 |
23 ~RequestCoordinator(); | 30 ~RequestCoordinator() override; |
24 | 31 |
25 // Queues |request| to later load and save when system conditions allow. | 32 // Queues |request| to later load and save when system conditions allow. |
26 // Returns true if the page could be queued successfully. | 33 // Returns true if the page could be queued successfully. |
27 bool SavePageLater(const SavePageRequest& request); | 34 bool SavePageLater(const SavePageRequest& request); |
28 | 35 |
29 // Starts processing of one or more queued save page later requests. | 36 // Starts processing of one or more queued save page later requests. |
30 // Returns whether processing was started and that caller should expect | 37 // Returns whether processing was started and that caller should expect |
31 // a callback. If processing was already active, returns false. | 38 // a callback. If processing was already active, returns false. |
32 bool StartProcessing(const ProcessingDoneCallback& callback); | 39 bool StartProcessing(const ProcessingDoneCallback& callback); |
33 | 40 |
34 // Stops the current request processing if active. This is a way for | 41 // Stops the current request processing if active. This is a way for |
35 // caller to abort processing; otherwise, processing will complete on | 42 // caller to abort processing; otherwise, processing will complete on |
36 // its own. In either case, the callback will be called when processing | 43 // its own. In either case, the callback will be called when processing |
37 // is stopped or complete. | 44 // is stopped or complete. |
38 void StopProcessing(); | 45 void StopProcessing(); |
39 | 46 |
40 // TODO(dougarnett): add policy support methods. | 47 private: |
| 48 // RequestCoordinator takes over ownership of the policy |
| 49 std::unique_ptr<OfflinerPolicy> policy_; |
| 50 // Factory is owned by the RequestCoordinator. |
| 51 std::unique_ptr<OfflinerFactory> factory_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
41 }; | 54 }; |
42 | 55 |
43 } // namespace offline_pages | 56 } // namespace offline_pages |
44 | 57 |
45 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 58 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
OLD | NEW |