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

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

Issue 2020833002: Add the request picker and a unit test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per Dimich and DougArnett Created 4 years, 6 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 "base/memory/weak_ptr.h"
13 #include "components/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
14 #include "components/offline_pages/background/offliner.h" 14 #include "components/offline_pages/background/offliner.h"
15 #include "components/offline_pages/background/request_queue.h" 15 #include "components/offline_pages/background/request_queue.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace offline_pages { 18 namespace offline_pages {
19 19
20 struct ClientId; 20 struct ClientId;
21 class OfflinerPolicy; 21 class OfflinerPolicy;
22 class OfflinerFactory; 22 class OfflinerFactory;
23 class Offliner; 23 class Offliner;
24 class RequestPicker;
24 class SavePageRequest; 25 class SavePageRequest;
25 class Scheduler; 26 class Scheduler;
26 27
27 // Coordinates queueing and processing save page later requests. 28 // Coordinates queueing and processing save page later requests.
28 class RequestCoordinator : 29 class RequestCoordinator : public KeyedService {
29 public KeyedService,
30 public base::SupportsWeakPtr<RequestCoordinator> {
31 public: 30 public:
32 // Callback to report when the processing of a triggered task is complete. 31 // Callback to report when the processing of a triggered task is complete.
33 typedef base::Callback<void()> ProcessingDoneCallback; 32 typedef base::Callback<void()> ProcessingDoneCallback;
33 typedef base::Callback<void(const SavePageRequest& request)>
34 RequestPickedCallback;
35 typedef base::Callback<void()> RequestQueueEmptyCallback;
34 36
35 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 37 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
36 std::unique_ptr<OfflinerFactory> factory, 38 std::unique_ptr<OfflinerFactory> factory,
37 std::unique_ptr<RequestQueue> queue, 39 std::unique_ptr<RequestQueue> queue,
38 std::unique_ptr<Scheduler> scheduler); 40 std::unique_ptr<Scheduler> scheduler);
39 41
40 ~RequestCoordinator() override; 42 ~RequestCoordinator() override;
41 43
42 // Queues |request| to later load and save when system conditions allow. 44 // Queues |request| to later load and save when system conditions allow.
43 // Returns true if the page could be queued successfully. 45 // Returns true if the page could be queued successfully.
(...skipping 17 matching lines...) Expand all
61 63
62 // Returns the status of the most recent offlining. 64 // Returns the status of the most recent offlining.
63 Offliner::RequestStatus last_offlining_status() { 65 Offliner::RequestStatus last_offlining_status() {
64 return last_offlining_status_; 66 return last_offlining_status_;
65 } 67 }
66 68
67 private: 69 private:
68 void AddRequestResultCallback(RequestQueue::AddRequestResult result, 70 void AddRequestResultCallback(RequestQueue::AddRequestResult result,
69 const SavePageRequest& request); 71 const SavePageRequest& request);
70 72
73 // Callback from the request picker when it has chosen our next request.
74 void RequestPicked(const SavePageRequest& request);
75
76 // Callback from the request picker when no more requests are in the queue.
77 void RequestQueueEmpty();
78
71 void SendRequestToOffliner(const SavePageRequest& request); 79 void SendRequestToOffliner(const SavePageRequest& request);
72 80
73 void OfflinerDoneCallback(const SavePageRequest& request, 81 void OfflinerDoneCallback(const SavePageRequest& request,
74 Offliner::RequestStatus status); 82 Offliner::RequestStatus status);
75 83
76 // RequestCoordinator takes over ownership of the policy 84 // RequestCoordinator takes over ownership of the policy
77 std::unique_ptr<OfflinerPolicy> policy_; 85 std::unique_ptr<OfflinerPolicy> policy_;
78 // OfflinerFactory. Used to create offline pages. Owned. 86 // OfflinerFactory. Used to create offline pages. Owned.
79 std::unique_ptr<OfflinerFactory> factory_; 87 std::unique_ptr<OfflinerFactory> factory_;
80 // RequestQueue. Used to store incoming requests. Owned. 88 // RequestQueue. Used to store incoming requests. Owned.
81 std::unique_ptr<RequestQueue> queue_; 89 std::unique_ptr<RequestQueue> queue_;
82 // Scheduler. Used to request a callback when network is available. Owned. 90 // Scheduler. Used to request a callback when network is available. Owned.
83 std::unique_ptr<Scheduler> scheduler_; 91 std::unique_ptr<Scheduler> scheduler_;
84 // Status of the most recent offlining. 92 // Status of the most recent offlining.
85 Offliner::RequestStatus last_offlining_status_; 93 Offliner::RequestStatus last_offlining_status_;
94 // Class to choose which request to schedule next
95 std::unique_ptr<RequestPicker> picker_;
96 // Allows us to pass a weak pointer to callbacks.
97 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
86 98
87 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 99 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
88 }; 100 };
89 101
90 } // namespace offline_pages 102 } // namespace offline_pages
91 103
92 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 104 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW
« no previous file with comments | « components/offline_pages/background/BUILD.gn ('k') | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698