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

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: Fix unit test 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
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // A way for tests to set the callback in use when an operation is over.
59 void SetProcessingCallbackForTest(const base::Callback<void(bool)> callback) {
60 scheduler_callback_ = callback;
61 }
62
58 // Returns the request queue used for requests. Coordinator keeps ownership. 63 // Returns the request queue used for requests. Coordinator keeps ownership.
59 RequestQueue* queue() { return queue_.get(); } 64 RequestQueue* queue() { return queue_.get(); }
60 65
61 // Return an unowned pointer to the Scheduler. 66 // Return an unowned pointer to the Scheduler.
62 Scheduler* scheduler() { return scheduler_.get(); } 67 Scheduler* scheduler() { return scheduler_.get(); }
63 68
64 // Returns the status of the most recent offlining. 69 // Returns the status of the most recent offlining.
65 Offliner::RequestStatus last_offlining_status() { 70 Offliner::RequestStatus last_offlining_status() {
66 return last_offlining_status_; 71 return last_offlining_status_;
67 } 72 }
68 73
69 private: 74 private:
70 void AddRequestResultCallback(RequestQueue::AddRequestResult result, 75 void AddRequestResultCallback(RequestQueue::AddRequestResult result,
71 const SavePageRequest& request); 76 const SavePageRequest& request);
72 77
78 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result);
79
73 // Callback from the request picker when it has chosen our next request. 80 // Callback from the request picker when it has chosen our next request.
74 void RequestPicked(const SavePageRequest& request); 81 void RequestPicked(const SavePageRequest& request);
75 82
76 // Callback from the request picker when no more requests are in the queue. 83 // Callback from the request picker when no more requests are in the queue.
77 void RequestQueueEmpty(); 84 void RequestQueueEmpty();
78 85
79 void SendRequestToOffliner(const SavePageRequest& request); 86 void SendRequestToOffliner(const SavePageRequest& request);
80 87
88 // Called by the offliner when an offlining request is completed. (and by
89 // tests).
81 void OfflinerDoneCallback(const SavePageRequest& request, 90 void OfflinerDoneCallback(const SavePageRequest& request,
82 Offliner::RequestStatus status); 91 Offliner::RequestStatus status);
83 92
93 void TryNextRequest();
94
95 friend class RequestCoordinatorTest;
96
84 // RequestCoordinator takes over ownership of the policy 97 // RequestCoordinator takes over ownership of the policy
85 std::unique_ptr<OfflinerPolicy> policy_; 98 std::unique_ptr<OfflinerPolicy> policy_;
86 // OfflinerFactory. Used to create offline pages. Owned. 99 // OfflinerFactory. Used to create offline pages. Owned.
87 std::unique_ptr<OfflinerFactory> factory_; 100 std::unique_ptr<OfflinerFactory> factory_;
88 // RequestQueue. Used to store incoming requests. Owned. 101 // RequestQueue. Used to store incoming requests. Owned.
89 std::unique_ptr<RequestQueue> queue_; 102 std::unique_ptr<RequestQueue> queue_;
90 // Scheduler. Used to request a callback when network is available. Owned. 103 // Scheduler. Used to request a callback when network is available. Owned.
91 std::unique_ptr<Scheduler> scheduler_; 104 std::unique_ptr<Scheduler> scheduler_;
92 // Status of the most recent offlining. 105 // Status of the most recent offlining.
93 Offliner::RequestStatus last_offlining_status_; 106 Offliner::RequestStatus last_offlining_status_;
94 // Class to choose which request to schedule next 107 // Class to choose which request to schedule next
95 std::unique_ptr<RequestPicker> picker_; 108 std::unique_ptr<RequestPicker> picker_;
109 // Calling this returns to the scheduler across the JNI bridge.
110 base::Callback<void(bool)> scheduler_callback_;
96 // Allows us to pass a weak pointer to callbacks. 111 // Allows us to pass a weak pointer to callbacks.
97 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 112 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
98 113
99 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 114 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
100 }; 115 };
101 116
102 } // namespace offline_pages 117 } // namespace offline_pages
103 118
104 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 119 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698