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

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: Remove files added in error. 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 "components/keyed_service/core/keyed_service.h" 12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/offline_pages/background/request_queue.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace offline_pages { 16 namespace offline_pages {
16 17
17 struct ClientId; 18 struct ClientId;
18 class OfflinerPolicy; 19 class OfflinerPolicy;
19 class OfflinerFactory; 20 class OfflinerFactory;
20 class Offliner; 21 class Offliner;
22 class RequestQueue;
fgorski 2016/05/10 21:18:12 since you are adding the header above, you don't n
Pete Williamson 2016/05/10 22:51:57 Done.
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 : public KeyedService {
25 public: 27 public:
26 // Callback to report when the processing of a triggered task is complete. 28 // Callback to report when the processing of a triggered task is complete.
27 typedef base::Callback<void()> ProcessingDoneCallback; 29 typedef base::Callback<void()> ProcessingDoneCallback;
28 30
29 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 31 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
30 std::unique_ptr<OfflinerFactory> factory); 32 std::unique_ptr<OfflinerFactory> factory,
33 std::unique_ptr<RequestQueue> queue);
31 34
32 ~RequestCoordinator() override; 35 ~RequestCoordinator() override;
33 36
34 // Queues |request| to later load and save when system conditions allow. 37 // Queues |request| to later load and save when system conditions allow.
35 // Returns true if the page could be queued successfully. 38 // Returns true if the page could be queued successfully.
36 bool SavePageLater(const GURL& url, const ClientId& client_id); 39 bool SavePageLater(const GURL& url, const ClientId& client_id);
37 40
38 // Starts processing of one or more queued save page later requests. 41 // Starts processing of one or more queued save page later requests.
39 // Returns whether processing was started and that caller should expect 42 // Returns whether processing was started and that caller should expect
40 // a callback. If processing was already active, returns false. 43 // a callback. If processing was already active, returns false.
41 bool StartProcessing(const ProcessingDoneCallback& callback); 44 bool StartProcessing(const ProcessingDoneCallback& callback);
42 45
43 // Stops the current request processing if active. This is a way for 46 // Stops the current request processing if active. This is a way for
44 // caller to abort processing; otherwise, processing will complete on 47 // caller to abort processing; otherwise, processing will complete on
45 // its own. In either case, the callback will be called when processing 48 // its own. In either case, the callback will be called when processing
46 // is stopped or complete. 49 // is stopped or complete.
47 void StopProcessing(); 50 void StopProcessing();
48 51
52 // Returns the request queue used for requests. Coordinator keeps ownership.
53 RequestQueue* GetQueue() { return queue_.get(); }
54
49 private: 55 private:
56 void AddRequestResultCallback(RequestQueue::AddRequestResult result,
57 const SavePageRequest& request);
50 // RequestCoordinator takes over ownership of the policy 58 // RequestCoordinator takes over ownership of the policy
51 std::unique_ptr<OfflinerPolicy> policy_; 59 std::unique_ptr<OfflinerPolicy> policy_;
52 // Factory is owned by the RequestCoordinator. 60 // Factory is owned by the RequestCoordinator.
53 std::unique_ptr<OfflinerFactory> factory_; 61 std::unique_ptr<OfflinerFactory> factory_;
62 // The queue is also owned by this RequestCoordinator.
dougarnett 2016/05/10 20:23:34 nit - unless I'm missing something, seems like all
Pete Williamson 2016/05/10 21:07:45 Sure. I was trying to avoid boring the reader by
fgorski 2016/05/10 21:18:12 Good point. I suggest: // Request queue. Used to <
Pete Williamson 2016/05/10 22:51:57 Done.
63 std::unique_ptr<RequestQueue> queue_;
54 64
55 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 65 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
56 }; 66 };
57 67
58 } // namespace offline_pages 68 } // namespace offline_pages
59 69
60 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 70 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698