| 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/browser/background_fetch/background_fetch_registration_id.h" |
| 16 #include "content/common/background_fetch/background_fetch_types.h" |
| 16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 17 #include "content/public/browser/download_item.h" | 18 #include "content/public/browser/download_item.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 class BackgroundFetchDataManager; | 22 class BackgroundFetchDataManager; |
| 22 class BackgroundFetchRequestInfo; | 23 class BackgroundFetchRequestInfo; |
| 23 class BrowserContext; | 24 class BrowserContext; |
| 24 class StoragePartition; | 25 class StoragePartition; |
| 25 | 26 |
| 26 // The JobController will be responsible for coordinating communication with the | 27 // The JobController will be responsible for coordinating communication with the |
| 27 // DownloadManager. It will get requests from the DataManager and dispatch them | 28 // DownloadManager. It will get requests from the DataManager and dispatch them |
| 28 // to the DownloadManager. It lives entirely on the IO thread. | 29 // to the DownloadManager. It lives entirely on the IO thread. |
| 29 class CONTENT_EXPORT BackgroundFetchJobController | 30 class CONTENT_EXPORT BackgroundFetchJobController |
| 30 : public DownloadItem::Observer { | 31 : public DownloadItem::Observer { |
| 31 public: | 32 public: |
| 32 using CompletedCallback = | 33 using CompletedCallback = |
| 33 base::OnceCallback<void(const BackgroundFetchRegistrationId&)>; | 34 base::OnceCallback<void(const BackgroundFetchRegistrationId&, |
| 35 bool /* aborted_by_developer */)>; |
| 34 | 36 |
| 35 BackgroundFetchJobController( | 37 BackgroundFetchJobController( |
| 36 const BackgroundFetchRegistrationId& registration_id, | 38 const BackgroundFetchRegistrationId& registration_id, |
| 39 const BackgroundFetchOptions& options, |
| 37 BrowserContext* browser_context, | 40 BrowserContext* browser_context, |
| 38 StoragePartition* storage_partition, | 41 StoragePartition* storage_partition, |
| 39 BackgroundFetchDataManager* data_manager, | 42 BackgroundFetchDataManager* data_manager, |
| 40 CompletedCallback completed_callback); | 43 CompletedCallback completed_callback); |
| 41 ~BackgroundFetchJobController() override; | 44 ~BackgroundFetchJobController() override; |
| 42 | 45 |
| 43 // Start processing on a batch of requests. Some of these may already be in | 46 // Start processing on a batch of requests. Some of these may already be in |
| 44 // progress or completed from a previous chromium instance. | 47 // progress or completed from a previous chromium instance. |
| 45 void StartProcessing(); | 48 void StartProcessing(); |
| 46 | 49 |
| 50 // Updates the representation of this Background Fetch in the user interface |
| 51 // to match the given |title|. |
| 52 void UpdateUI(const std::string& title); |
| 53 |
| 54 // Immediately aborts this Background Fetch by request of the developer. |
| 55 void Abort(); |
| 56 |
| 47 // Called by the BackgroundFetchContext when the system is shutting down. | 57 // Called by the BackgroundFetchContext when the system is shutting down. |
| 48 void Shutdown(); | 58 void Shutdown(); |
| 49 | 59 |
| 60 // Returns the registration id for which this job is fetching data. |
| 61 const BackgroundFetchRegistrationId& registration_id() const { |
| 62 return registration_id_; |
| 63 } |
| 64 |
| 65 // Returns the options with which this job is fetching data. |
| 66 const BackgroundFetchOptions& options() const { return options_; } |
| 67 |
| 50 private: | 68 private: |
| 51 // DownloadItem::Observer methods. | 69 // DownloadItem::Observer methods. |
| 52 void OnDownloadUpdated(DownloadItem* item) override; | 70 void OnDownloadUpdated(DownloadItem* item) override; |
| 53 void OnDownloadDestroyed(DownloadItem* item) override; | 71 void OnDownloadDestroyed(DownloadItem* item) override; |
| 54 | 72 |
| 55 // Callback passed to the DownloadManager which will be invoked once the | 73 // Callback passed to the DownloadManager which will be invoked once the |
| 56 // download starts. | 74 // download starts. |
| 57 void DownloadStarted(const std::string& request_guid, | 75 void DownloadStarted(const std::string& request_guid, |
| 58 DownloadItem* item, | 76 DownloadItem* item, |
| 59 DownloadInterruptReason reason); | 77 DownloadInterruptReason reason); |
| 60 | 78 |
| 61 void ProcessRequest(const BackgroundFetchRequestInfo& request); | 79 void ProcessRequest(const BackgroundFetchRequestInfo& request); |
| 62 | 80 |
| 63 // The registration id on behalf of which this controller is fetching data. | 81 // The registration id on behalf of which this controller is fetching data. |
| 64 BackgroundFetchRegistrationId registration_id_; | 82 BackgroundFetchRegistrationId registration_id_; |
| 65 | 83 |
| 84 // Options for the represented background fetch registration. |
| 85 BackgroundFetchOptions options_; |
| 86 |
| 66 // TODO(peter): Deprecated, remove in favor of |registration_id|. | 87 // TODO(peter): Deprecated, remove in favor of |registration_id|. |
| 67 std::string job_guid_; | 88 std::string job_guid_; |
| 68 | 89 |
| 69 // Pointer to the browser context. The BackgroundFetchJobController is owned | 90 // Pointer to the browser context. The BackgroundFetchJobController is owned |
| 70 // by the BrowserContext via the StoragePartition. | 91 // by the BrowserContext via the StoragePartition. |
| 71 // TODO(harkness): Currently this is only used to lookup the DownloadManager. | 92 // TODO(harkness): Currently this is only used to lookup the DownloadManager. |
| 72 // Investigate whether the DownloadManager should be passed instead. | 93 // Investigate whether the DownloadManager should be passed instead. |
| 73 BrowserContext* browser_context_; | 94 BrowserContext* browser_context_; |
| 74 | 95 |
| 75 // Pointer to the storage partition. This object is owned by the partition | 96 // Pointer to the storage partition. This object is owned by the partition |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 std::unordered_map<std::string, std::string> download_guid_map_; | 108 std::unordered_map<std::string, std::string> download_guid_map_; |
| 88 | 109 |
| 89 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; | 110 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; |
| 90 | 111 |
| 91 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); | 112 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); |
| 92 }; | 113 }; |
| 93 | 114 |
| 94 } // namespace content | 115 } // namespace content |
| 95 | 116 |
| 96 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ | 117 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ |
| OLD | NEW |