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

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

Issue 2767373002: Implement GetJobResponse and merge JobData into DataManager. (Closed)
Patch Set: Removed typedef and added DISALLOW_COPY_AND_ASSIGN 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 #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/common/content_export.h" 15 #include "content/common/content_export.h"
16 #include "content/public/browser/download_item.h" 16 #include "content/public/browser/download_item.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 class BackgroundFetchJobData; 20 class BackgroundFetchDataManager;
21 class BackgroundFetchRequestInfo; 21 class BackgroundFetchRequestInfo;
22 class BrowserContext; 22 class BrowserContext;
23 class StoragePartition; 23 class StoragePartition;
24 24
25 // The JobController will be responsible for coordinating communication with the 25 // The JobController will be responsible for coordinating communication with the
26 // DownloadManager. It will get requests from the JobData and dispatch them to 26 // DownloadManager. It will get requests from the DataManager and dispatch them
27 // the DownloadManager. It lives entirely on the IO thread. 27 // to the DownloadManager. It lives entirely on the IO thread.
28 class CONTENT_EXPORT BackgroundFetchJobController 28 class CONTENT_EXPORT BackgroundFetchJobController
29 : public DownloadItem::Observer { 29 : public DownloadItem::Observer {
30 public: 30 public:
31 BackgroundFetchJobController(const std::string& job_guid, 31 BackgroundFetchJobController(const std::string& job_guid,
32 BrowserContext* browser_context, 32 BrowserContext* browser_context,
33 StoragePartition* storage_partition, 33 StoragePartition* storage_partition,
34 std::unique_ptr<BackgroundFetchJobData> job_data, 34 BackgroundFetchDataManager* data_manager,
35 base::OnceClosure completed_closure); 35 base::OnceClosure completed_closure);
36 ~BackgroundFetchJobController() override; 36 ~BackgroundFetchJobController() override;
37 37
38 // Start processing on a batch of requests. Some of these may already be in 38 // Start processing on a batch of requests. Some of these may already be in
39 // progress or completed from a previous chromium instance. 39 // progress or completed from a previous chromium instance.
40 void StartProcessing(); 40 void StartProcessing();
41 41
42 // Called by the BackgroundFetchContext when the system is shutting down. 42 // Called by the BackgroundFetchContext when the system is shutting down.
43 void Shutdown(); 43 void Shutdown();
44 44
45 private: 45 private:
46 // DownloadItem::Observer methods. 46 // DownloadItem::Observer methods.
47 void OnDownloadUpdated(DownloadItem* item) override; 47 void OnDownloadUpdated(DownloadItem* item) override;
48 void OnDownloadDestroyed(DownloadItem* item) override; 48 void OnDownloadDestroyed(DownloadItem* item) override;
49 49
50 // Callback passed to the DownloadManager which will be invoked once the 50 // Callback passed to the DownloadManager which will be invoked once the
51 // download starts. 51 // download starts.
52 void DownloadStarted(const std::string& request_guid, 52 void DownloadStarted(const std::string& request_guid,
53 DownloadItem* item, 53 DownloadItem* item,
54 DownloadInterruptReason reason); 54 DownloadInterruptReason reason);
55 55
56 void ProcessRequest(const BackgroundFetchRequestInfo& request); 56 void ProcessRequest(const BackgroundFetchRequestInfo& request);
57 57
58 std::string job_guid_;
59
58 // Pointer to the browser context. The BackgroundFetchJobController is owned 60 // Pointer to the browser context. The BackgroundFetchJobController is owned
59 // by the BrowserContext via the StoragePartition. 61 // by the BrowserContext via the StoragePartition.
60 // TODO(harkness): Currently this is only used to lookup the DownloadManager. 62 // TODO(harkness): Currently this is only used to lookup the DownloadManager.
61 // Investigate whether the DownloadManager should be passed instead. 63 // Investigate whether the DownloadManager should be passed instead.
62 BrowserContext* browser_context_; 64 BrowserContext* browser_context_;
63 65
64 // 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
65 // (through a sequence of other classes). 67 // (through a sequence of other classes).
66 StoragePartition* storage_partition_; 68 StoragePartition* storage_partition_;
67 69
68 // The JobData which talks to the DataManager for this job_guid. 70 // The DataManager's lifetime is controlled by the BackgroundFetchContext and
69 std::unique_ptr<BackgroundFetchJobData> job_data_; 71 // will be kept alive until after the JobController is destroyed.
72 BackgroundFetchDataManager* data_manager_;
70 73
71 // Callback for when all fetches have been completed. 74 // Callback for when all fetches have been completed.
72 base::OnceClosure completed_closure_; 75 base::OnceClosure completed_closure_;
73 76
74 // Map from the GUID assigned by the DownloadManager to the request_guid. 77 // Map from the GUID assigned by the DownloadManager to the request_guid.
75 std::unordered_map<std::string, std::string> download_guid_map_; 78 std::unordered_map<std::string, std::string> download_guid_map_;
76 79
77 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; 80 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_;
78 81
79 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); 82 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController);
80 }; 83 };
81 84
82 } // namespace content 85 } // namespace content
83 86
84 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ 87 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698