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

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

Issue 2774343002: Hook up BackgroundFetchServiceImpl::Fetch() to start a fetch (Closed)
Patch Set: rebase 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_DATA_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <unordered_map> 11 #include <unordered_map>
12 12
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "content/browser/background_fetch/background_fetch_job_info.h" 15 #include "content/browser/background_fetch/background_fetch_job_info.h"
16 #include "content/browser/background_fetch/background_fetch_job_response_data.h" 16 #include "content/browser/background_fetch/background_fetch_job_response_data.h"
17 #include "content/browser/background_fetch/background_fetch_registration_id.h" 17 #include "content/browser/background_fetch/background_fetch_registration_id.h"
18 #include "content/browser/background_fetch/background_fetch_request_info.h" 18 #include "content/browser/background_fetch/background_fetch_request_info.h"
19 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
20 #include "third_party/WebKit/public/platform/modules/background_fetch/background _fetch.mojom.h"
20 #include "url/origin.h" 21 #include "url/origin.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 class BrowserContext; 25 class BrowserContext;
25 class ChromeBlobStorageContext; 26 class ChromeBlobStorageContext;
26 27
27 // The BackgroundFetchDataManager keeps track of all of the outstanding requests 28 // The BackgroundFetchDataManager keeps track of all of the outstanding requests
28 // which are in process in the DownloadManager. When Chromium restarts, it is 29 // which are in process in the DownloadManager. When Chromium restarts, it is
29 // responsibile for reconnecting all the in progress downloads with an observer 30 // responsibile for reconnecting all the in progress downloads with an observer
30 // which will keep the metadata up to date. 31 // which will keep the metadata up to date.
31 class CONTENT_EXPORT BackgroundFetchDataManager { 32 class CONTENT_EXPORT BackgroundFetchDataManager {
32 public: 33 public:
34 using CreateRegistrationCallback =
35 base::OnceCallback<void(blink::mojom::BackgroundFetchError)>;
36 using DeleteRegistrationCallback =
37 base::OnceCallback<void(blink::mojom::BackgroundFetchError)>;
38
33 explicit BackgroundFetchDataManager(BrowserContext* browser_context); 39 explicit BackgroundFetchDataManager(BrowserContext* browser_context);
34 ~BackgroundFetchDataManager(); 40 ~BackgroundFetchDataManager();
35 41
36 // Called by BackgroundFetchContext when a new request is started, this will 42 // Creates and stores a new registration with the given properties. Will
37 // store all of the necessary metadata to track the request. 43 // invoke the |callback| when the registration has been created, which may
38 void CreateRequest( 44 // fail due to invalid input or storage errors.
39 std::unique_ptr<BackgroundFetchJobInfo> job_info, 45 void CreateRegistration(
40 std::vector<std::unique_ptr<BackgroundFetchRequestInfo>> request_infos); 46 const BackgroundFetchRegistrationId& registration_id,
47 const std::vector<ServiceWorkerFetchRequest>& requests,
48 const BackgroundFetchOptions& options,
49 CreateRegistrationCallback callback);
50
51 // Deletes the registration identified by |registration_id|. Will invoke the
52 // |callback| when the registration has been deleted from storage.
53 void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id,
54 DeleteRegistrationCallback callback);
41 55
42 // TODO(harkness): Replace the OnceClosure with a callback to return the 56 // TODO(harkness): Replace the OnceClosure with a callback to return the
43 // response object once it is decided whether lifetime should be passed to the 57 // response object once it is decided whether lifetime should be passed to the
44 // caller or stay here. 58 // caller or stay here.
45 void GetJobResponse(const std::string& job_guid, 59 void GetJobResponse(const std::string& job_guid,
46 const BackgroundFetchResponseCompleteCallback& callback); 60 const BackgroundFetchResponseCompleteCallback& callback);
47 61
48 // The following methods are called by the JobController to update job state. 62 // The following methods are called by the JobController to update job state.
49 // Returns a boolean indicating whether there are more requests to process. 63 // Returns a boolean indicating whether there are more requests to process.
50 virtual bool UpdateRequestState(const std::string& job_guid, 64 virtual bool UpdateRequestState(const std::string& job_guid,
(...skipping 13 matching lines...) Expand all
64 virtual const BackgroundFetchRequestInfo& GetNextBackgroundFetchRequestInfo( 78 virtual const BackgroundFetchRequestInfo& GetNextBackgroundFetchRequestInfo(
65 const std::string& job_guid); 79 const std::string& job_guid);
66 80
67 // Indicates whether all requests have been handed to the JobController. 81 // Indicates whether all requests have been handed to the JobController.
68 virtual bool HasRequestsRemaining(const std::string& job_guid) const; 82 virtual bool HasRequestsRemaining(const std::string& job_guid) const;
69 83
70 // Indicates whether all requests have been handed out and completed. 84 // Indicates whether all requests have been handed out and completed.
71 virtual bool IsComplete(const std::string& job_guid) const; 85 virtual bool IsComplete(const std::string& job_guid) const;
72 86
73 private: 87 private:
88 friend class BackgroundFetchDataManagerTest;
89
74 // Storage interface. 90 // Storage interface.
75 void WriteJobToStorage( 91 void WriteJobToStorage(
76 std::unique_ptr<BackgroundFetchJobInfo> job_info, 92 std::unique_ptr<BackgroundFetchJobInfo> job_info,
77 std::vector<std::unique_ptr<BackgroundFetchRequestInfo>> request_infos); 93 std::vector<std::unique_ptr<BackgroundFetchRequestInfo>> request_infos);
78 void WriteRequestToStorage(const std::string& job_guid, 94 void WriteRequestToStorage(const std::string& job_guid,
79 BackgroundFetchRequestInfo* request_info); 95 BackgroundFetchRequestInfo* request_info);
80 std::unique_ptr<BackgroundFetchRequestInfo> GetRequestInfo( 96 std::unique_ptr<BackgroundFetchRequestInfo> GetRequestInfo(
81 const std::string& job_guid, 97 const std::string& job_guid,
82 size_t request_index); 98 size_t request_index);
83 99
84 void DidGetBlobStorageContext( 100 void DidGetBlobStorageContext(
85 const std::string& job_guid, 101 const std::string& job_guid,
86 const BackgroundFetchResponseCompleteCallback& callback, 102 const BackgroundFetchResponseCompleteCallback& callback,
87 ChromeBlobStorageContext* blob_context); 103 ChromeBlobStorageContext* blob_context);
88 104
89 // Indirectly, this is owned by the BrowserContext. 105 // Indirectly, this is owned by the BrowserContext.
90 BrowserContext* browser_context_; 106 BrowserContext* browser_context_;
91 107
92 // Set of known background fetch registration ids. 108 // Set of known background fetch registration ids.
93 std::set<BackgroundFetchRegistrationId> known_registrations_; 109 std::set<BackgroundFetchRegistrationId> registrations_;
94 110
95 // Map from job_guid to JobInfo. 111 // Map from job_guid to JobInfo.
96 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobInfo>> 112 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobInfo>>
97 job_map_; 113 job_map_;
98 114
99 // Temporary map to hold data which will be written to storage. 115 // Temporary map to hold data which will be written to storage.
100 // Map from job_guid to RequestInfos. 116 // Map from job_guid to RequestInfos.
101 std::unordered_map<std::string, std::vector<BackgroundFetchRequestInfo>> 117 std::unordered_map<std::string, std::vector<BackgroundFetchRequestInfo>>
102 request_map_; 118 request_map_;
103 119
104 base::WeakPtrFactory<BackgroundFetchDataManager> weak_ptr_factory_; 120 base::WeakPtrFactory<BackgroundFetchDataManager> weak_ptr_factory_;
105 121
106 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); 122 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager);
107 }; 123 };
108 124
109 } // namespace content 125 } // namespace content
110 126
111 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ 127 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698