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

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

Issue 2030773002: Add unit tests for the Background Scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable flaky 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
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 11 matching lines...) Expand all
22 class OfflinerFactory; 22 class OfflinerFactory;
23 class Offliner; 23 class Offliner;
24 class RequestPicker; 24 class RequestPicker;
25 class SavePageRequest; 25 class SavePageRequest;
26 class Scheduler; 26 class Scheduler;
27 27
28 // Coordinates queueing and processing save page later requests. 28 // Coordinates queueing and processing save page later requests.
29 class RequestCoordinator : public KeyedService { 29 class RequestCoordinator : public KeyedService {
30 public: 30 public:
31 // 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.
32 typedef base::Callback<void()> ProcessingDoneCallback;
33 typedef base::Callback<void(const SavePageRequest& request)> 32 typedef base::Callback<void(const SavePageRequest& request)>
34 RequestPickedCallback; 33 RequestPickedCallback;
35 typedef base::Callback<void()> RequestQueueEmptyCallback; 34 typedef base::Callback<void()> RequestQueueEmptyCallback;
36 35
37 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 36 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
38 std::unique_ptr<OfflinerFactory> factory, 37 std::unique_ptr<OfflinerFactory> factory,
39 std::unique_ptr<RequestQueue> queue, 38 std::unique_ptr<RequestQueue> queue,
40 std::unique_ptr<Scheduler> scheduler); 39 std::unique_ptr<Scheduler> scheduler);
41 40
42 ~RequestCoordinator() override; 41 ~RequestCoordinator() override;
43 42
44 // Queues |request| to later load and save when system conditions allow. 43 // Queues |request| to later load and save when system conditions allow.
45 // Returns true if the page could be queued successfully. 44 // Returns true if the page could be queued successfully.
46 bool SavePageLater(const GURL& url, const ClientId& client_id); 45 bool SavePageLater(const GURL& url, const ClientId& client_id);
47 46
48 // Starts processing of one or more queued save page later requests. 47 // Starts processing of one or more queued save page later requests.
49 // Returns whether processing was started and that caller should expect 48 // Returns whether processing was started and that caller should expect
50 // a callback. If processing was already active, returns false. 49 // a callback. If processing was already active, returns false.
51 bool StartProcessing(const ProcessingDoneCallback& callback); 50 bool StartProcessing(const base::Callback<void(bool)>& callback);
52 51
53 // 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
54 // caller to abort processing; otherwise, processing will complete on 53 // caller to abort processing; otherwise, processing will complete on
55 // 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
56 // is stopped or complete. 55 // is stopped or complete.
57 void StopProcessing(); 56 void StopProcessing();
58 57
59 // Returns the request queue used for requests. Coordinator keeps ownership. 58 // Returns the request queue used for requests. Coordinator keeps ownership.
60 RequestQueue* queue() { return queue_.get(); } 59 RequestQueue* queue() { return queue_.get(); }
61 60
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 std::unique_ptr<RequestPicker> picker_; 95 std::unique_ptr<RequestPicker> picker_;
97 // Allows us to pass a weak pointer to callbacks. 96 // Allows us to pass a weak pointer to callbacks.
98 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 97 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
99 98
100 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 99 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
101 }; 100 };
102 101
103 } // namespace offline_pages 102 } // namespace offline_pages
104 103
105 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 104 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698