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

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

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

Powered by Google App Engine
This is Rietveld 408576698