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 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 12 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/download_item.h" | |
| 13 | 16 |
| 14 namespace content { | 17 namespace content { |
| 15 | 18 |
| 16 class BackgroundFetchJobData; | 19 class BackgroundFetchJobData; |
| 17 class BackgroundFetchRequestInfo; | 20 class BackgroundFetchRequestInfo; |
| 18 class BrowserContext; | 21 class BrowserContext; |
| 19 class StoragePartition; | 22 class StoragePartition; |
| 20 | 23 |
| 21 // The JobController will be responsible for coordinating communication with the | 24 // The JobController will be responsible for coordinating communication with the |
| 22 // DownloadManager. It will get requests from the JobData and dispatch them to | 25 // DownloadManager. It will get requests from the JobData and dispatch them to |
| 23 // the DownloadManager. | 26 // the DownloadManager. |
| 24 // TODO(harkness): The JobController should also observe downloads. | 27 class CONTENT_EXPORT BackgroundFetchJobController |
| 25 class CONTENT_EXPORT BackgroundFetchJobController { | 28 : public content::DownloadItem::Observer { |
|
Peter Beverloo
2017/03/08 14:58:19
nit: you are in `content::`
harkness
2017/03/10 13:33:53
Done.
| |
| 26 public: | 29 public: |
| 27 BackgroundFetchJobController(const std::string& job_guid, | 30 BackgroundFetchJobController(const std::string& job_guid, |
| 28 BrowserContext* browser_context, | 31 BrowserContext* browser_context, |
| 29 StoragePartition* storage_partition, | 32 StoragePartition* storage_partition, |
| 30 BackgroundFetchJobData* job_data); | 33 BackgroundFetchJobData* job_data); |
| 31 ~BackgroundFetchJobController(); | 34 ~BackgroundFetchJobController() override; |
| 32 | 35 |
| 33 // Start processing on a batch of requests. Some of these may already be in | 36 // Start processing on a batch of requests. Some of these may already be in |
| 34 // progress or completed from a previous chromium instance. | 37 // progress or completed from a previous chromium instance. |
| 35 void StartProcessing(); | 38 void StartProcessing(); |
| 36 | 39 |
| 37 // Called by the BackgroundFetchContext when the system is shutting down. | 40 // Called by the BackgroundFetchContext when the system is shutting down. |
| 38 void Shutdown(); | 41 void Shutdown(); |
| 39 | 42 |
| 40 private: | 43 private: |
| 44 // DownloadItem::Observer methods. | |
| 45 void OnDownloadUpdated(DownloadItem* item) override; | |
| 46 void OnDownloadDestroyed(DownloadItem* item) override; | |
| 47 | |
| 48 // Callback passed to the DownloadManager which will be invoked once the | |
| 49 // download starts. | |
| 50 void DownloadStarted(const std::string& request_guid, | |
| 51 DownloadItem* item, | |
| 52 DownloadInterruptReason reason); | |
| 53 | |
| 41 void ProcessRequest(const BackgroundFetchRequestInfo& request); | 54 void ProcessRequest(const BackgroundFetchRequestInfo& request); |
| 42 | 55 |
| 56 void StopObservations(); | |
| 57 | |
| 43 // Pointer to the browser context. The BackgroundFetchJobController is owned | 58 // Pointer to the browser context. The BackgroundFetchJobController is owned |
| 44 // by the BrowserContext via the StoragePartition. | 59 // by the BrowserContext via the StoragePartition. |
| 60 // TODO(harkness): Currently this is only used to lookup the DownloadManager. | |
| 61 // Investigate whether the DownloadManager should be passed instead. | |
| 45 BrowserContext* browser_context_; | 62 BrowserContext* browser_context_; |
| 46 | 63 |
| 47 // Pointer to the storage partition. This object is owned by the partition | 64 // Pointer to the storage partition. This object is owned by the partition |
| 48 // (through a sequence of other classes). | 65 // (through a sequence of other classes). |
| 49 StoragePartition* storage_partition_; | 66 StoragePartition* storage_partition_; |
| 50 | 67 |
| 51 // The JobData which talks to the DataManager for this job_guid. | 68 // The JobData which talks to the DataManager for this job_guid. |
| 52 std::unique_ptr<BackgroundFetchJobData> job_data_; | 69 std::unique_ptr<BackgroundFetchJobData> job_data_; |
| 53 | 70 |
| 71 // Map from the GUID assigned by the DownloadManager to the request_guid. | |
| 72 std::unordered_map<std::string, std::string> download_guid_map_; | |
|
Peter Beverloo
2017/03/08 14:58:19
Let's figure out a way to reduce the number of map
harkness
2017/03/10 13:33:54
As discussed in person, we're going to switch to u
| |
| 73 | |
| 74 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; | |
| 75 | |
| 54 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); | 76 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); |
| 55 }; | 77 }; |
| 56 | 78 |
| 57 } // namespace content | 79 } // namespace content |
| 58 | 80 |
| 59 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ | 81 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ |
| OLD | NEW |