OLD | NEW |
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 BackgroundFetchJobData; | 21 class BackgroundFetchJobData; |
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 JobData and dispatch them to | 27 // DownloadManager. It will get requests from the JobData and dispatch them to |
27 // the DownloadManager. It lives entirely on the IO thread. | 28 // 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 BackgroundFetchJobController( |
32 BrowserContext* browser_context, | 33 const BackgroundFetchRegistrationId& registration_id, |
33 StoragePartition* storage_partition, | 34 BrowserContext* browser_context, |
34 std::unique_ptr<BackgroundFetchJobData> job_data, | 35 StoragePartition* storage_partition, |
35 base::OnceClosure completed_closure); | 36 std::unique_ptr<BackgroundFetchJobData> job_data, |
| 37 base::OnceClosure completed_closure); |
36 ~BackgroundFetchJobController() override; | 38 ~BackgroundFetchJobController() override; |
37 | 39 |
38 // Start processing on a batch of requests. Some of these may already be in | 40 // Start processing on a batch of requests. Some of these may already be in |
39 // progress or completed from a previous chromium instance. | 41 // progress or completed from a previous chromium instance. |
40 void StartProcessing(); | 42 void StartProcessing(); |
41 | 43 |
42 // Called by the BackgroundFetchContext when the system is shutting down. | 44 // Called by the BackgroundFetchContext when the system is shutting down. |
43 void Shutdown(); | 45 void Shutdown(); |
44 | 46 |
| 47 const BackgroundFetchRegistrationId& registration_id() const { |
| 48 return registration_id_; |
| 49 } |
| 50 |
45 private: | 51 private: |
46 // DownloadItem::Observer methods. | 52 // DownloadItem::Observer methods. |
47 void OnDownloadUpdated(DownloadItem* item) override; | 53 void OnDownloadUpdated(DownloadItem* item) override; |
48 void OnDownloadDestroyed(DownloadItem* item) override; | 54 void OnDownloadDestroyed(DownloadItem* item) override; |
49 | 55 |
50 // Callback passed to the DownloadManager which will be invoked once the | 56 // Callback passed to the DownloadManager which will be invoked once the |
51 // download starts. | 57 // download starts. |
52 void DownloadStarted(const std::string& request_guid, | 58 void DownloadStarted(const std::string& request_guid, |
53 DownloadItem* item, | 59 DownloadItem* item, |
54 DownloadInterruptReason reason); | 60 DownloadInterruptReason reason); |
55 | 61 |
56 void ProcessRequest(const BackgroundFetchRequestInfo& request); | 62 void ProcessRequest(const BackgroundFetchRequestInfo& request); |
57 | 63 |
| 64 BackgroundFetchRegistrationId registration_id_; |
| 65 |
58 // Pointer to the browser context. The BackgroundFetchJobController is owned | 66 // Pointer to the browser context. The BackgroundFetchJobController is owned |
59 // by the BrowserContext via the StoragePartition. | 67 // by the BrowserContext via the StoragePartition. |
60 // TODO(harkness): Currently this is only used to lookup the DownloadManager. | 68 // TODO(harkness): Currently this is only used to lookup the DownloadManager. |
61 // Investigate whether the DownloadManager should be passed instead. | 69 // Investigate whether the DownloadManager should be passed instead. |
62 BrowserContext* browser_context_; | 70 BrowserContext* browser_context_; |
63 | 71 |
64 // Pointer to the storage partition. This object is owned by the partition | 72 // Pointer to the storage partition. This object is owned by the partition |
65 // (through a sequence of other classes). | 73 // (through a sequence of other classes). |
66 StoragePartition* storage_partition_; | 74 StoragePartition* storage_partition_; |
67 | 75 |
68 // The JobData which talks to the DataManager for this job_guid. | 76 // The JobData which talks to the DataManager for this job_guid. |
69 std::unique_ptr<BackgroundFetchJobData> job_data_; | 77 std::unique_ptr<BackgroundFetchJobData> job_data_; |
70 | 78 |
71 // Callback for when all fetches have been completed. | 79 // Callback for when all fetches have been completed. |
72 base::OnceClosure completed_closure_; | 80 base::OnceClosure completed_closure_; |
73 | 81 |
74 // Map from the GUID assigned by the DownloadManager to the request_guid. | 82 // Map from the GUID assigned by the DownloadManager to the request_guid. |
75 std::unordered_map<std::string, std::string> download_guid_map_; | 83 std::unordered_map<std::string, std::string> download_guid_map_; |
76 | 84 |
77 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; | 85 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; |
78 | 86 |
79 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); | 87 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); |
80 }; | 88 }; |
81 | 89 |
82 } // namespace content | 90 } // namespace content |
83 | 91 |
84 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ | 92 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ |
OLD | NEW |