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

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: CR feedback per FGorski 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 "base/memory/weak_ptr.h"
12 #include "components/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
14 #include "components/offline_pages/background/request_queue.h"
13 #include "url/gurl.h" 15 #include "url/gurl.h"
14 16
15 namespace offline_pages { 17 namespace offline_pages {
16 18
17 struct ClientId; 19 struct ClientId;
18 class OfflinerPolicy; 20 class OfflinerPolicy;
19 class OfflinerFactory; 21 class OfflinerFactory;
20 class Offliner; 22 class Offliner;
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,
27 public base::SupportsWeakPtr<RequestCoordinator> {
fgorski 2016/05/11 19:45:15 nit: alignment. Unless you ran git cl format and
Pete Williamson 2016/05/11 22:13:03 Done.
25 public: 28 public:
26 // Callback to report when the processing of a triggered task is complete. 29 // Callback to report when the processing of a triggered task is complete.
27 typedef base::Callback<void()> ProcessingDoneCallback; 30 typedef base::Callback<void()> ProcessingDoneCallback;
28 31
29 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 32 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
30 std::unique_ptr<OfflinerFactory> factory); 33 std::unique_ptr<OfflinerFactory> factory,
34 std::unique_ptr<RequestQueue> queue);
31 35
32 ~RequestCoordinator() override; 36 ~RequestCoordinator() override;
33 37
34 // Queues |request| to later load and save when system conditions allow. 38 // Queues |request| to later load and save when system conditions allow.
35 // Returns true if the page could be queued successfully. 39 // Returns true if the page could be queued successfully.
36 bool SavePageLater(const GURL& url, const ClientId& client_id); 40 bool SavePageLater(const GURL& url, const ClientId& client_id);
37 41
38 // Starts processing of one or more queued save page later requests. 42 // Starts processing of one or more queued save page later requests.
39 // Returns whether processing was started and that caller should expect 43 // Returns whether processing was started and that caller should expect
40 // a callback. If processing was already active, returns false. 44 // a callback. If processing was already active, returns false.
41 bool StartProcessing(const ProcessingDoneCallback& callback); 45 bool StartProcessing(const ProcessingDoneCallback& callback);
42 46
43 // Stops the current request processing if active. This is a way for 47 // Stops the current request processing if active. This is a way for
44 // caller to abort processing; otherwise, processing will complete on 48 // caller to abort processing; otherwise, processing will complete on
45 // its own. In either case, the callback will be called when processing 49 // its own. In either case, the callback will be called when processing
46 // is stopped or complete. 50 // is stopped or complete.
47 void StopProcessing(); 51 void StopProcessing();
48 52
53 // Returns the request queue used for requests. Coordinator keeps ownership.
54 RequestQueue* GetQueue() { return queue_.get(); }
55
49 private: 56 private:
50 // RequestCoordinator takes over ownership of the policy 57 void AddRequestResultCallback(RequestQueue::AddRequestResult result,
58 const SavePageRequest& request);
59 // OfflinerPolicy. Used to store policies. Owned.
51 std::unique_ptr<OfflinerPolicy> policy_; 60 std::unique_ptr<OfflinerPolicy> policy_;
52 // Factory is owned by the RequestCoordinator. 61 // OfflinerFactory. Used to create offline pages. Owned.
53 std::unique_ptr<OfflinerFactory> factory_; 62 std::unique_ptr<OfflinerFactory> factory_;
63 // RequestQueue. Used to store incoming requests. Owned.
64 std::unique_ptr<RequestQueue> queue_;
54 65
55 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 66 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
56 }; 67 };
57 68
58 } // namespace offline_pages 69 } // namespace offline_pages
59 70
60 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 71 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698