Chromium Code Reviews| 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/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/download_item.h" | 16 #include "content/public/browser/download_item.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 class BackgroundFetchJobData; | 20 class BackgroundFetchJobData; |
| 20 class BackgroundFetchRequestInfo; | 21 class BackgroundFetchRequestInfo; |
| 21 class BrowserContext; | 22 class BrowserContext; |
| 22 class StoragePartition; | 23 class StoragePartition; |
| 23 | 24 |
| 24 // The JobController will be responsible for coordinating communication with the | 25 // The JobController will be responsible for coordinating communication with the |
| 25 // DownloadManager. It will get requests from the JobData and dispatch them to | 26 // DownloadManager. It will get requests from the JobData and dispatch them to |
| 26 // the DownloadManager. It lives entirely on the IO thread. | 27 // the DownloadManager. It lives entirely on the IO thread. |
| 27 class CONTENT_EXPORT BackgroundFetchJobController | 28 class CONTENT_EXPORT BackgroundFetchJobController |
| 28 : public DownloadItem::Observer { | 29 : public DownloadItem::Observer { |
| 29 public: | 30 public: |
| 30 BackgroundFetchJobController( | 31 using JobCompleteCallback = base::Callback<void()>; |
|
Peter Beverloo
2017/03/15 16:53:38
base::OnceClosure. Can also drop the typedef that
harkness
2017/03/16 11:41:09
I had hesitated on this based on the discussions a
| |
| 31 const std::string& job_guid, | 32 |
| 32 BrowserContext* browser_context, | 33 BackgroundFetchJobController(const std::string& job_guid, |
| 33 StoragePartition* storage_partition, | 34 BrowserContext* browser_context, |
| 34 std::unique_ptr<BackgroundFetchJobData> job_data); | 35 StoragePartition* storage_partition, |
| 36 std::unique_ptr<BackgroundFetchJobData> job_data, | |
| 37 const JobCompleteCallback& callback); | |
|
Peter Beverloo
2017/03/15 16:53:38
nit: drop const& if you can use OnceClosure and st
Peter Beverloo
2017/03/15 16:53:38
nit: completed_callback?
harkness
2017/03/16 11:41:09
Done.
harkness
2017/03/16 11:41:09
Done.
| |
| 35 ~BackgroundFetchJobController() override; | 38 ~BackgroundFetchJobController() override; |
| 36 | 39 |
| 37 // 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 |
| 38 // progress or completed from a previous chromium instance. | 41 // progress or completed from a previous chromium instance. |
| 39 void StartProcessing(); | 42 void StartProcessing(); |
| 40 | 43 |
| 41 // Called by the BackgroundFetchContext when the system is shutting down. | 44 // Called by the BackgroundFetchContext when the system is shutting down. |
| 42 void Shutdown(); | 45 void Shutdown(); |
| 43 | 46 |
| 44 private: | 47 private: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 60 // Investigate whether the DownloadManager should be passed instead. | 63 // Investigate whether the DownloadManager should be passed instead. |
| 61 BrowserContext* browser_context_; | 64 BrowserContext* browser_context_; |
| 62 | 65 |
| 63 // Pointer to the storage partition. This object is owned by the partition | 66 // Pointer to the storage partition. This object is owned by the partition |
| 64 // (through a sequence of other classes). | 67 // (through a sequence of other classes). |
| 65 StoragePartition* storage_partition_; | 68 StoragePartition* storage_partition_; |
| 66 | 69 |
| 67 // The JobData which talks to the DataManager for this job_guid. | 70 // The JobData which talks to the DataManager for this job_guid. |
| 68 std::unique_ptr<BackgroundFetchJobData> job_data_; | 71 std::unique_ptr<BackgroundFetchJobData> job_data_; |
| 69 | 72 |
| 73 // Callback for when all fetches have been completed. | |
| 74 JobCompleteCallback callback_; | |
| 75 | |
| 70 // Map from the GUID assigned by the DownloadManager to the request_guid. | 76 // Map from the GUID assigned by the DownloadManager to the request_guid. |
| 71 std::unordered_map<std::string, std::string> download_guid_map_; | 77 std::unordered_map<std::string, std::string> download_guid_map_; |
| 72 | 78 |
| 73 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; | 79 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; |
| 74 | 80 |
| 75 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); | 81 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); |
| 76 }; | 82 }; |
| 77 | 83 |
| 78 } // namespace content | 84 } // namespace content |
| 79 | 85 |
| 80 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ | 86 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ |
| OLD | NEW |