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

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

Issue 2978603003: [Background Fetch] Tidy up getting/activating pending requests (Closed)
Patch Set: Address 2nd round review comments Created 3 years, 5 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 30 matching lines...) Expand all
41 BackgroundFetchJobController( 41 BackgroundFetchJobController(
42 const BackgroundFetchRegistrationId& registration_id, 42 const BackgroundFetchRegistrationId& registration_id,
43 const BackgroundFetchOptions& options, 43 const BackgroundFetchOptions& options,
44 BackgroundFetchDataManager* data_manager, 44 BackgroundFetchDataManager* data_manager,
45 BrowserContext* browser_context, 45 BrowserContext* browser_context,
46 scoped_refptr<net::URLRequestContextGetter> request_context, 46 scoped_refptr<net::URLRequestContextGetter> request_context,
47 CompletedCallback completed_callback, 47 CompletedCallback completed_callback,
48 const net::NetworkTrafficAnnotationTag& traffic_annotation); 48 const net::NetworkTrafficAnnotationTag& traffic_annotation);
49 ~BackgroundFetchJobController(); 49 ~BackgroundFetchJobController();
50 50
51 // Starts fetching the |initial_fetches|. The controller will continue to 51 // Starts fetching the first few requests. The controller will continue to
52 // fetch new content until all requests have been handled. 52 // fetch new content until all requests have been handled.
53 void Start( 53 void Start();
54 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests);
55 54
56 // Updates the representation of this Background Fetch in the user interface 55 // Updates the representation of this Background Fetch in the user interface
57 // to match the given |title|. 56 // to match the given |title|.
58 void UpdateUI(const std::string& title); 57 void UpdateUI(const std::string& title);
59 58
60 // Immediately aborts this Background Fetch by request of the developer. 59 // Immediately aborts this Background Fetch by request of the developer.
61 void Abort(); 60 void Abort();
62 61
63 // Returns the current state of this Job Controller. 62 // Returns the current state of this Job Controller.
64 State state() const { return state_; } 63 State state() const { return state_; }
(...skipping 13 matching lines...) Expand all
78 void StartRequest(scoped_refptr<BackgroundFetchRequestInfo> request); 77 void StartRequest(scoped_refptr<BackgroundFetchRequestInfo> request);
79 78
80 // Called when the given |request| has started fetching, after having been 79 // Called when the given |request| has started fetching, after having been
81 // assigned the |download_guid| by the download system. 80 // assigned the |download_guid| by the download system.
82 void DidStartRequest(scoped_refptr<BackgroundFetchRequestInfo> request, 81 void DidStartRequest(scoped_refptr<BackgroundFetchRequestInfo> request,
83 const std::string& download_guid); 82 const std::string& download_guid);
84 83
85 // Called when the given |request| has been completed. 84 // Called when the given |request| has been completed.
86 void DidCompleteRequest(scoped_refptr<BackgroundFetchRequestInfo> request); 85 void DidCompleteRequest(scoped_refptr<BackgroundFetchRequestInfo> request);
87 86
88 // Called when a completed download has been marked as such in the DataManager 87 // Called when a completed download has been marked as such in DataManager.
89 // and the next request, if any, has been read from storage. 88 void DidMarkRequestCompleted(bool has_pending_or_active_requests);
90 void DidGetNextRequest(scoped_refptr<BackgroundFetchRequestInfo> request);
91 89
92 // The registration id on behalf of which this controller is fetching data. 90 // The registration id on behalf of which this controller is fetching data.
93 BackgroundFetchRegistrationId registration_id_; 91 BackgroundFetchRegistrationId registration_id_;
94 92
95 // Options for the represented background fetch registration. 93 // Options for the represented background fetch registration.
96 BackgroundFetchOptions options_; 94 BackgroundFetchOptions options_;
97 95
98 // The current state of this Job Controller. 96 // The current state of this Job Controller.
99 State state_ = State::INITIALIZED; 97 State state_ = State::INITIALIZED;
100 98
101 // Inner core of this job controller which lives on the UI thread. 99 // Inner core of this job controller which lives on the UI thread.
102 std::unique_ptr<Core, BrowserThread::DeleteOnUIThread> ui_core_; 100 std::unique_ptr<Core, BrowserThread::DeleteOnUIThread> ui_core_;
103 base::WeakPtr<Core> ui_core_ptr_; 101 base::WeakPtr<Core> ui_core_ptr_;
104 102
105 // The DataManager's lifetime is controlled by the BackgroundFetchContext and 103 // The DataManager's lifetime is controlled by the BackgroundFetchContext and
106 // will be kept alive until after the JobController is destroyed. 104 // will be kept alive until after the JobController is destroyed.
107 BackgroundFetchDataManager* data_manager_; 105 BackgroundFetchDataManager* data_manager_;
108 106
109 // Number of outstanding acknowledgements we still expect to receive.
110 int pending_completed_file_acknowledgements_ = 0;
111
112 // Callback for when all fetches have been completed. 107 // Callback for when all fetches have been completed.
113 CompletedCallback completed_callback_; 108 CompletedCallback completed_callback_;
114 109
115 // Traffic annotation for network request. 110 // Traffic annotation for network request.
116 const net::NetworkTrafficAnnotationTag traffic_annotation_; 111 const net::NetworkTrafficAnnotationTag traffic_annotation_;
117 112
118 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; 113 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_;
119 114
120 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); 115 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController);
121 }; 116 };
122 117
123 } // namespace content 118 } // namespace content
124 119
125 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_ 120 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698