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

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

Issue 2064793003: Remove old requests from queue, start new requests if any, add test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
(...skipping 29 matching lines...) Expand all
40 40
41 ~RequestCoordinator() override; 41 ~RequestCoordinator() override;
42 42
43 // Queues |request| to later load and save when system conditions allow. 43 // Queues |request| to later load and save when system conditions allow.
44 // Returns true if the page could be queued successfully. 44 // Returns true if the page could be queued successfully.
45 bool SavePageLater(const GURL& url, const ClientId& client_id); 45 bool SavePageLater(const GURL& url, const ClientId& client_id);
46 46
47 // Starts processing of one or more queued save page later requests. 47 // Starts processing of one or more queued save page later requests.
48 // Returns whether processing was started and that caller should expect 48 // Returns whether processing was started and that caller should expect
49 // a callback. If processing was already active, returns false. 49 // a callback. If processing was already active, returns false.
50 bool StartProcessing(const base::Callback<void(bool)>& callback); 50 bool StartProcessing(const base::Callback<void(bool)> callback);
51 51
52 // Stops the current request processing if active. This is a way for 52 // Stops the current request processing if active. This is a way for
53 // caller to abort processing; otherwise, processing will complete on 53 // caller to abort processing; otherwise, processing will complete on
54 // its own. In either case, the callback will be called when processing 54 // its own. In either case, the callback will be called when processing
55 // is stopped or complete. 55 // is stopped or complete.
56 void StopProcessing(); 56 void StopProcessing();
57 57
58 // Called by the offliner when an offlining request is completed. (and by
59 // tests).
60 void OfflinerDoneCallback(const SavePageRequest& request,
dewittj 2016/06/14 16:16:36 nit: make this private and make the test harness a
Pete Williamson 2016/06/14 21:03:14 Done.
61 Offliner::RequestStatus status);
62
63 // A way for tests to set the callback in use when an operation is over.
64 void SetProcessingCallbackForTest(const base::Callback<void(bool)> callback) {
65 scheduler_callback_ = callback;
66 }
67
58 // Returns the request queue used for requests. Coordinator keeps ownership. 68 // Returns the request queue used for requests. Coordinator keeps ownership.
59 RequestQueue* queue() { return queue_.get(); } 69 RequestQueue* queue() { return queue_.get(); }
60 70
61 // Return an unowned pointer to the Scheduler. 71 // Return an unowned pointer to the Scheduler.
62 Scheduler* scheduler() { return scheduler_.get(); } 72 Scheduler* scheduler() { return scheduler_.get(); }
63 73
64 // Returns the status of the most recent offlining. 74 // Returns the status of the most recent offlining.
65 Offliner::RequestStatus last_offlining_status() { 75 Offliner::RequestStatus last_offlining_status() {
66 return last_offlining_status_; 76 return last_offlining_status_;
67 } 77 }
68 78
69 private: 79 private:
70 void AddRequestResultCallback(RequestQueue::AddRequestResult result, 80 void AddRequestResultCallback(RequestQueue::AddRequestResult result,
71 const SavePageRequest& request); 81 const SavePageRequest& request);
72 82
83 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result);
84
73 // Callback from the request picker when it has chosen our next request. 85 // Callback from the request picker when it has chosen our next request.
74 void RequestPicked(const SavePageRequest& request); 86 void RequestPicked(const SavePageRequest& request);
75 87
76 // Callback from the request picker when no more requests are in the queue. 88 // Callback from the request picker when no more requests are in the queue.
77 void RequestQueueEmpty(); 89 void RequestQueueEmpty();
78 90
79 void SendRequestToOffliner(const SavePageRequest& request); 91 void SendRequestToOffliner(const SavePageRequest& request);
80 92
81 void OfflinerDoneCallback(const SavePageRequest& request, 93 void TryNextRequest();
82 Offliner::RequestStatus status);
83 94
84 // RequestCoordinator takes over ownership of the policy 95 // RequestCoordinator takes over ownership of the policy
85 std::unique_ptr<OfflinerPolicy> policy_; 96 std::unique_ptr<OfflinerPolicy> policy_;
86 // OfflinerFactory. Used to create offline pages. Owned. 97 // OfflinerFactory. Used to create offline pages. Owned.
87 std::unique_ptr<OfflinerFactory> factory_; 98 std::unique_ptr<OfflinerFactory> factory_;
88 // RequestQueue. Used to store incoming requests. Owned. 99 // RequestQueue. Used to store incoming requests. Owned.
89 std::unique_ptr<RequestQueue> queue_; 100 std::unique_ptr<RequestQueue> queue_;
90 // Scheduler. Used to request a callback when network is available. Owned. 101 // Scheduler. Used to request a callback when network is available. Owned.
91 std::unique_ptr<Scheduler> scheduler_; 102 std::unique_ptr<Scheduler> scheduler_;
92 // Status of the most recent offlining. 103 // Status of the most recent offlining.
93 Offliner::RequestStatus last_offlining_status_; 104 Offliner::RequestStatus last_offlining_status_;
94 // Class to choose which request to schedule next 105 // Class to choose which request to schedule next
95 std::unique_ptr<RequestPicker> picker_; 106 std::unique_ptr<RequestPicker> picker_;
107 // Calling this returns to the scheduler across the JNI bridge.
108 base::Callback<void(bool)> scheduler_callback_;
96 // Allows us to pass a weak pointer to callbacks. 109 // Allows us to pass a weak pointer to callbacks.
97 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 110 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
98 111
99 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 112 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
100 }; 113 };
101 114
102 } // namespace offline_pages 115 } // namespace offline_pages
103 116
104 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 117 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698