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

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: 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_request_info.h" 18 #include "content/browser/background_fetch/background_fetch_request_info.h"
18 #include "content/browser/background_fetch/background_fetch_registration_id.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 BlobHandle; 26 class BlobHandle;
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(std::unique_ptr<BackgroundFetchJobInfo> job_info, 44 // fail due to invalid input or storage errors.
39 BackgroundFetchRequestInfos request_infos); 45 void CreateRegistration(
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);
40 55
41 // TODO(harkness): Replace the OnceClosure with a callback to return the 56 // TODO(harkness): Replace the OnceClosure with a callback to return the
42 // 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
43 // caller or stay here. 58 // caller or stay here.
44 void GetJobResponse(const std::string& job_guid, 59 void GetJobResponse(const std::string& job_guid,
45 const BackgroundFetchResponseCompleteCallback& callback); 60 const BackgroundFetchResponseCompleteCallback& callback);
46 61
47 // 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.
48 // Returns a boolean indicating whether there are more requests to process. 63 // Returns a boolean indicating whether there are more requests to process.
49 virtual bool UpdateRequestState(const std::string& job_guid, 64 virtual bool UpdateRequestState(const std::string& job_guid,
(...skipping 13 matching lines...) Expand all
63 virtual const BackgroundFetchRequestInfo& GetNextBackgroundFetchRequestInfo( 78 virtual const BackgroundFetchRequestInfo& GetNextBackgroundFetchRequestInfo(
64 const std::string& job_guid); 79 const std::string& job_guid);
65 80
66 // Indicates whether all requests have been handed to the JobController. 81 // Indicates whether all requests have been handed to the JobController.
67 virtual bool HasRequestsRemaining(const std::string& job_guid) const; 82 virtual bool HasRequestsRemaining(const std::string& job_guid) const;
68 83
69 // Indicates whether all requests have been handed out and completed. 84 // Indicates whether all requests have been handed out and completed.
70 virtual bool IsComplete(const std::string& job_guid) const; 85 virtual bool IsComplete(const std::string& job_guid) const;
71 86
72 private: 87 private:
88 friend class BackgroundFetchDataManagerTest;
89
90 void CreateRequestForTests(std::unique_ptr<BackgroundFetchJobInfo> job_info,
harkness 2017/03/27 15:35:12 I don't see a definition of this? It looks like yo
Peter Beverloo 2017/03/27 15:42:55 Oops, removed.
91 BackgroundFetchRequestInfos request_infos);
92
73 // Storage interface. 93 // Storage interface.
74 void WriteJobToStorage(std::unique_ptr<BackgroundFetchJobInfo> job_info, 94 void WriteJobToStorage(std::unique_ptr<BackgroundFetchJobInfo> job_info,
75 BackgroundFetchRequestInfos request_infos); 95 BackgroundFetchRequestInfos request_infos);
76 void WriteRequestToStorage(const std::string& job_guid, 96 void WriteRequestToStorage(const std::string& job_guid,
77 BackgroundFetchRequestInfo* request_info); 97 BackgroundFetchRequestInfo* request_info);
78 std::unique_ptr<BackgroundFetchRequestInfo> GetRequestInfo( 98 std::unique_ptr<BackgroundFetchRequestInfo> GetRequestInfo(
79 const std::string& job_guid, 99 const std::string& job_guid,
80 size_t request_index); 100 size_t request_index);
81 101
82 void DidGetRequestResponse(const std::string& job_guid, 102 void DidGetRequestResponse(const std::string& job_guid,
83 int request_sequence_number, 103 int request_sequence_number,
84 std::unique_ptr<BlobHandle> blob_handle); 104 std::unique_ptr<BlobHandle> blob_handle);
85 105
86 // Indirectly, this is owned by the BrowserContext. 106 // Indirectly, this is owned by the BrowserContext.
87 BrowserContext* browser_context_; 107 BrowserContext* browser_context_;
88 108
89 // Set of known background fetch registration ids. 109 // Set of known background fetch registration ids.
90 std::set<BackgroundFetchRegistrationId> known_registrations_; 110 std::set<BackgroundFetchRegistrationId> registrations_;
91 111
92 // Map from job_guid to JobInfo. 112 // Map from job_guid to JobInfo.
93 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobInfo>> 113 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobInfo>>
94 job_map_; 114 job_map_;
95 115
96 // Temporary map to hold data which will be written to storage. 116 // Temporary map to hold data which will be written to storage.
97 // Map from job_guid to RequestInfos. 117 // Map from job_guid to RequestInfos.
98 std::unordered_map<std::string, std::vector<BackgroundFetchRequestInfo>> 118 std::unordered_map<std::string, std::vector<BackgroundFetchRequestInfo>>
99 request_map_; 119 request_map_;
100 120
101 base::WeakPtrFactory<BackgroundFetchDataManager> weak_ptr_factory_; 121 base::WeakPtrFactory<BackgroundFetchDataManager> weak_ptr_factory_;
102 122
103 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); 123 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager);
104 }; 124 };
105 125
106 } // namespace content 126 } // namespace content
107 127
108 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ 128 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698