Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: components/offline_pages/background/request_coordinator.h

Issue 1969463002: Add a save page request to the request queue (and test it). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More CR feedback from FGorski Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/weak_ptr.h"
12 #include "components/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
14 #include "components/offline_pages/background/request_queue.h"
13 #include "url/gurl.h" 15 #include "url/gurl.h"
14 16
15 namespace offline_pages { 17 namespace offline_pages {
16 18
17 struct ClientId; 19 struct ClientId;
18 class OfflinerPolicy; 20 class OfflinerPolicy;
19 class OfflinerFactory; 21 class OfflinerFactory;
20 class Offliner; 22 class Offliner;
21 class SavePageRequest; 23 class SavePageRequest;
22 24
23 // Coordinates queueing and processing save page later requests. 25 // Coordinates queueing and processing save page later requests.
24 class RequestCoordinator : public KeyedService { 26 class RequestCoordinator :
27 public KeyedService,
28 public base::SupportsWeakPtr<RequestCoordinator> {
25 public: 29 public:
26 // Callback to report when the processing of a triggered task is complete. 30 // Callback to report when the processing of a triggered task is complete.
27 typedef base::Callback<void()> ProcessingDoneCallback; 31 typedef base::Callback<void()> ProcessingDoneCallback;
28 32
29 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 33 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
30 std::unique_ptr<OfflinerFactory> factory); 34 std::unique_ptr<OfflinerFactory> factory,
35 std::unique_ptr<RequestQueue> queue);
31 36
32 ~RequestCoordinator() override; 37 ~RequestCoordinator() override;
33 38
34 // Queues |request| to later load and save when system conditions allow. 39 // Queues |request| to later load and save when system conditions allow.
35 // Returns true if the page could be queued successfully. 40 // Returns true if the page could be queued successfully.
36 bool SavePageLater(const GURL& url, const ClientId& client_id); 41 bool SavePageLater(const GURL& url, const ClientId& client_id);
37 42
38 // Starts processing of one or more queued save page later requests. 43 // Starts processing of one or more queued save page later requests.
39 // Returns whether processing was started and that caller should expect 44 // Returns whether processing was started and that caller should expect
40 // a callback. If processing was already active, returns false. 45 // a callback. If processing was already active, returns false.
41 bool StartProcessing(const ProcessingDoneCallback& callback); 46 bool StartProcessing(const ProcessingDoneCallback& callback);
42 47
43 // Stops the current request processing if active. This is a way for 48 // Stops the current request processing if active. This is a way for
44 // caller to abort processing; otherwise, processing will complete on 49 // caller to abort processing; otherwise, processing will complete on
45 // its own. In either case, the callback will be called when processing 50 // its own. In either case, the callback will be called when processing
46 // is stopped or complete. 51 // is stopped or complete.
47 void StopProcessing(); 52 void StopProcessing();
48 53
54 // Returns the request queue used for requests. Coordinator keeps ownership.
55 RequestQueue* GetQueue() { return queue_.get(); }
56
49 private: 57 private:
50 // RequestCoordinator takes over ownership of the policy 58 void AddRequestResultCallback(RequestQueue::AddRequestResult result,
59 const SavePageRequest& request);
60 // OfflinerPolicy. Used to store policies. Owned.
51 std::unique_ptr<OfflinerPolicy> policy_; 61 std::unique_ptr<OfflinerPolicy> policy_;
52 // Factory is owned by the RequestCoordinator. 62 // OfflinerFactory. Used to create offline pages. Owned.
53 std::unique_ptr<OfflinerFactory> factory_; 63 std::unique_ptr<OfflinerFactory> factory_;
64 // RequestQueue. Used to store incoming requests. Owned.
65 std::unique_ptr<RequestQueue> queue_;
54 66
55 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 67 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
56 }; 68 };
57 69
58 } // namespace offline_pages 70 } // namespace offline_pages
59 71
60 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 72 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698