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

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

Issue 2727253002: Added DownloadItem::Observer to JobController. (Closed)
Patch Set: Added TODO Created 3 years, 9 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 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. It lives entirely on the IO thread. 26 // the DownloadManager. It lives entirely on the IO thread.
24 // TODO(harkness): The JobController should also observe downloads. 27 class CONTENT_EXPORT BackgroundFetchJobController
25 class CONTENT_EXPORT BackgroundFetchJobController { 28 : public DownloadItem::Observer {
26 public: 29 public:
27 BackgroundFetchJobController( 30 BackgroundFetchJobController(
28 const std::string& job_guid, 31 const std::string& job_guid,
29 BrowserContext* browser_context, 32 BrowserContext* browser_context,
30 StoragePartition* storage_partition, 33 StoragePartition* storage_partition,
31 std::unique_ptr<BackgroundFetchJobData> job_data); 34 std::unique_ptr<BackgroundFetchJobData> job_data);
32 ~BackgroundFetchJobController(); 35 ~BackgroundFetchJobController() override;
33 36
34 // Start processing on a batch of requests. Some of these may already be in 37 // Start processing on a batch of requests. Some of these may already be in
35 // progress or completed from a previous chromium instance. 38 // progress or completed from a previous chromium instance.
36 void StartProcessing(); 39 void StartProcessing();
37 40
38 // Called by the BackgroundFetchContext when the system is shutting down. 41 // Called by the BackgroundFetchContext when the system is shutting down.
39 void Shutdown(); 42 void Shutdown();
40 43
41 private: 44 private:
45 // DownloadItem::Observer methods.
46 void OnDownloadUpdated(DownloadItem* item) override;
47 void OnDownloadDestroyed(DownloadItem* item) override;
48
49 // Callback passed to the DownloadManager which will be invoked once the
50 // download starts.
51 void DownloadStarted(const std::string& request_guid,
52 DownloadItem* item,
53 DownloadInterruptReason reason);
54
42 void ProcessRequest(const BackgroundFetchRequestInfo& request); 55 void ProcessRequest(const BackgroundFetchRequestInfo& request);
43 56
44 // Pointer to the browser context. The BackgroundFetchJobController is owned 57 // Pointer to the browser context. The BackgroundFetchJobController is owned
45 // by the BrowserContext via the StoragePartition. 58 // by the BrowserContext via the StoragePartition.
59 // TODO(harkness): Currently this is only used to lookup the DownloadManager.
60 // Investigate whether the DownloadManager should be passed instead.
46 BrowserContext* browser_context_; 61 BrowserContext* browser_context_;
47 62
48 // Pointer to the storage partition. This object is owned by the partition 63 // Pointer to the storage partition. This object is owned by the partition
49 // (through a sequence of other classes). 64 // (through a sequence of other classes).
50 StoragePartition* storage_partition_; 65 StoragePartition* storage_partition_;
51 66
52 // The JobData which talks to the DataManager for this job_guid. 67 // The JobData which talks to the DataManager for this job_guid.
53 std::unique_ptr<BackgroundFetchJobData> job_data_; 68 std::unique_ptr<BackgroundFetchJobData> job_data_;
54 69
70 // Map from the GUID assigned by the DownloadManager to the request_guid.
71 std::unordered_map<std::string, std::string> download_guid_map_;
72
73 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_;
74
55 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); 75 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController);
56 }; 76 };
57 77
58 } // namespace content 78 } // namespace content
59 79
60 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ 80 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698