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

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

Issue 2796933003: Store BackgroundFetchRequestInfo in a refcounted pointer (Closed)
Patch Set: 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>
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 "base/optional.h"
16 #include "content/browser/background_fetch/background_fetch_registration_id.h" 15 #include "content/browser/background_fetch/background_fetch_registration_id.h"
17 #include "content/browser/background_fetch/background_fetch_request_info.h" 16 #include "content/browser/background_fetch/background_fetch_request_info.h"
18 #include "content/common/background_fetch/background_fetch_types.h" 17 #include "content/common/background_fetch/background_fetch_types.h"
19 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
20 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
21 20
22 namespace net { 21 namespace net {
23 class URLRequestContextGetter; 22 class URLRequestContextGetter;
24 } 23 }
25 24
(...skipping 16 matching lines...) Expand all
42 const BackgroundFetchRegistrationId& registration_id, 41 const BackgroundFetchRegistrationId& registration_id,
43 const BackgroundFetchOptions& options, 42 const BackgroundFetchOptions& options,
44 BackgroundFetchDataManager* data_manager, 43 BackgroundFetchDataManager* data_manager,
45 BrowserContext* browser_context, 44 BrowserContext* browser_context,
46 scoped_refptr<net::URLRequestContextGetter> request_context, 45 scoped_refptr<net::URLRequestContextGetter> request_context,
47 CompletedCallback completed_callback); 46 CompletedCallback completed_callback);
48 ~BackgroundFetchJobController(); 47 ~BackgroundFetchJobController();
49 48
50 // Starts fetching the |initial_fetches|. The controller will continue to 49 // Starts fetching the |initial_fetches|. The controller will continue to
51 // fetch new content until all requests have been handled. 50 // fetch new content until all requests have been handled.
52 void Start(std::vector<BackgroundFetchRequestInfo> initial_requests); 51 void Start(
52 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests);
53 53
54 // Updates the representation of this Background Fetch in the user interface 54 // Updates the representation of this Background Fetch in the user interface
55 // to match the given |title|. 55 // to match the given |title|.
56 void UpdateUI(const std::string& title); 56 void UpdateUI(const std::string& title);
57 57
58 // Immediately aborts this Background Fetch by request of the developer. 58 // Immediately aborts this Background Fetch by request of the developer.
59 void Abort(); 59 void Abort();
60 60
61 // Returns the current state of this Job Controller. 61 // Returns the current state of this Job Controller.
62 State state() const { return state_; } 62 State state() const { return state_; }
63 63
64 // Returns the registration id for which this job is fetching data. 64 // Returns the registration id for which this job is fetching data.
65 const BackgroundFetchRegistrationId& registration_id() const { 65 const BackgroundFetchRegistrationId& registration_id() const {
66 return registration_id_; 66 return registration_id_;
67 } 67 }
68 68
69 // Returns the options with which this job is fetching data. 69 // Returns the options with which this job is fetching data.
70 const BackgroundFetchOptions& options() const { return options_; } 70 const BackgroundFetchOptions& options() const { return options_; }
71 71
72 private: 72 private:
73 class Core; 73 class Core;
74 74
75 // Requests the download manager to start fetching |request|. 75 // Requests the download manager to start fetching |request|.
76 void StartRequest(const BackgroundFetchRequestInfo& request); 76 void StartRequest(scoped_refptr<BackgroundFetchRequestInfo> request);
77 77
78 // Called when the given |request| has started fetching, after having been 78 // Called when the given |request| has started fetching, after having been
79 // assigned the |download_guid| by the download system. 79 // assigned the |download_guid| by the download system.
80 void DidStartRequest(const BackgroundFetchRequestInfo& request, 80 void DidStartRequest(scoped_refptr<BackgroundFetchRequestInfo> request,
81 const std::string& download_guid); 81 const std::string& download_guid);
82 82
83 // Called when the given |request| has been completed. 83 // Called when the given |request| has been completed.
84 void DidCompleteRequest(const BackgroundFetchRequestInfo& request); 84 void DidCompleteRequest(scoped_refptr<BackgroundFetchRequestInfo> request);
85 85
86 // Called when a completed download has been marked as such in the DataManager 86 // Called when a completed download has been marked as such in the DataManager
87 // and the next request, if any, has been read from storage. 87 // and the next request, if any, has been read from storage.
88 void DidGetNextRequest( 88 void DidGetNextRequest(scoped_refptr<BackgroundFetchRequestInfo> request);
89 const base::Optional<BackgroundFetchRequestInfo>& request);
90 89
91 // 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.
92 BackgroundFetchRegistrationId registration_id_; 91 BackgroundFetchRegistrationId registration_id_;
93 92
94 // Options for the represented background fetch registration. 93 // Options for the represented background fetch registration.
95 BackgroundFetchOptions options_; 94 BackgroundFetchOptions options_;
96 95
97 // The current state of this Job Controller. 96 // The current state of this Job Controller.
98 State state_ = State::INITIALIZED; 97 State state_ = State::INITIALIZED;
99 98
(...skipping 12 matching lines...) Expand all
112 CompletedCallback completed_callback_; 111 CompletedCallback completed_callback_;
113 112
114 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_; 113 base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_;
115 114
116 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController); 115 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController);
117 }; 116 };
118 117
119 } // namespace content 118 } // namespace content
120 119
121 #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