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