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

Side by Side Diff: content/browser/background_fetch/background_fetch_job_controller.h

Issue 2774343002: Hook up BackgroundFetchServiceImpl::Fetch() to start a fetch (Closed)
Patch Set: Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <unordered_map> 10 #include <unordered_map>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "content/browser/background_fetch/background_fetch_registration_id.h"
15 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
16 #include "content/public/browser/download_item.h" 17 #include "content/public/browser/download_item.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 class BackgroundFetchDataManager; 21 class BackgroundFetchDataManager;
21 class BackgroundFetchRequestInfo; 22 class BackgroundFetchRequestInfo;
22 class BrowserContext; 23 class BrowserContext;
23 class StoragePartition; 24 class StoragePartition;
24 25
25 // The JobController will be responsible for coordinating communication with the 26 // The JobController will be responsible for coordinating communication with the
26 // DownloadManager. It will get requests from the DataManager and dispatch them 27 // DownloadManager. It will get requests from the DataManager and dispatch them
27 // to the DownloadManager. It lives entirely on the IO thread. 28 // to the DownloadManager. It lives entirely on the IO thread.
28 class CONTENT_EXPORT BackgroundFetchJobController 29 class CONTENT_EXPORT BackgroundFetchJobController
29 : public DownloadItem::Observer { 30 : public DownloadItem::Observer {
30 public: 31 public:
31 BackgroundFetchJobController(const std::string& job_guid, 32 using CompletedCallback =
32 BrowserContext* browser_context, 33 base::OnceCallback<void(const BackgroundFetchRegistrationId&)>;
33 StoragePartition* storage_partition, 34
34 BackgroundFetchDataManager* data_manager, 35 BackgroundFetchJobController(
35 base::OnceClosure completed_closure); 36 const BackgroundFetchRegistrationId& registration_id,
37 BrowserContext* browser_context,
38 StoragePartition* storage_partition,
39 BackgroundFetchDataManager* data_manager,
40 CompletedCallback completed_callback);
36 ~BackgroundFetchJobController() override; 41 ~BackgroundFetchJobController() override;
37 42
38 // Start processing on a batch of requests. Some of these may already be in 43 // Start processing on a batch of requests. Some of these may already be in
39 // progress or completed from a previous chromium instance. 44 // progress or completed from a previous chromium instance.
40 void StartProcessing(); 45 void StartProcessing();
41 46
42 // Called by the BackgroundFetchContext when the system is shutting down. 47 // Called by the BackgroundFetchContext when the system is shutting down.
43 void Shutdown(); 48 void Shutdown();
44 49
45 private: 50 private:
46 // DownloadItem::Observer methods. 51 // DownloadItem::Observer methods.
47 void OnDownloadUpdated(DownloadItem* item) override; 52 void OnDownloadUpdated(DownloadItem* item) override;
48 void OnDownloadDestroyed(DownloadItem* item) override; 53 void OnDownloadDestroyed(DownloadItem* item) override;
49 54
50 // Callback passed to the DownloadManager which will be invoked once the 55 // Callback passed to the DownloadManager which will be invoked once the
51 // download starts. 56 // download starts.
52 void DownloadStarted(const std::string& request_guid, 57 void DownloadStarted(const std::string& request_guid,
53 DownloadItem* item, 58 DownloadItem* item,
54 DownloadInterruptReason reason); 59 DownloadInterruptReason reason);
55 60
56 void ProcessRequest(const BackgroundFetchRequestInfo& request); 61 void ProcessRequest(const BackgroundFetchRequestInfo& request);
57 62
63 // The registration id on behalf of which this controller is fetching data.
64 BackgroundFetchRegistrationId registration_id_;
65
66 // TODO(peter): Deprecated, remove in favor of |registration_id|.
58 std::string job_guid_; 67 std::string job_guid_;
59 68
60 // Pointer to the browser context. The BackgroundFetchJobController is owned 69 // Pointer to the browser context. The BackgroundFetchJobController is owned
61 // by the BrowserContext via the StoragePartition. 70 // by the BrowserContext via the StoragePartition.
62 // TODO(harkness): Currently this is only used to lookup the DownloadManager. 71 // TODO(harkness): Currently this is only used to lookup the DownloadManager.
63 // Investigate whether the DownloadManager should be passed instead. 72 // Investigate whether the DownloadManager should be passed instead.
64 BrowserContext* browser_context_; 73 BrowserContext* browser_context_;
65 74
66 // Pointer to the storage partition. This object is owned by the partition 75 // Pointer to the storage partition. This object is owned by the partition
67 // (through a sequence of other classes). 76 // (through a sequence of other classes).
68 StoragePartition* storage_partition_; 77 StoragePartition* storage_partition_;
69 78
70 // The DataManager's lifetime is controlled by the BackgroundFetchContext and 79 // The DataManager's lifetime is controlled by the BackgroundFetchContext and
71 // will be kept alive until after the JobController is destroyed. 80 // will be kept alive until after the JobController is destroyed.
72 BackgroundFetchDataManager* data_manager_; 81 BackgroundFetchDataManager* data_manager_;
73 82
74 // Callback for when all fetches have been completed. 83 // Callback for when all fetches have been completed.
75 base::OnceClosure completed_closure_; 84 CompletedCallback completed_callback_;
76 85
77 // Map from the GUID assigned by the DownloadManager to the request_guid. 86 // Map from the GUID assigned by the DownloadManager to the request_guid.
78 std::unordered_map<std::string, std::string> download_guid_map_; 87 std::unordered_map<std::string, std::string> download_guid_map_;
79 88
80 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; 89 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_;
81 90
82 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); 91 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController);
83 }; 92 };
84 93
85 } // namespace content 94 } // namespace content
86 95
87 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ 96 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698