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

Unified Diff: content/browser/background_fetch/background_fetch_data_manager.h

Issue 2770343002: Teach Background Fetch how to start a new fetch. (Closed)
Patch Set: Teach Background Fetch how to start a new fetch. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/background_fetch/background_fetch_data_manager.h
diff --git a/content/browser/background_fetch/background_fetch_data_manager.h b/content/browser/background_fetch/background_fetch_data_manager.h
index a093da2dbfbe97fe8829e894b0eb7f5814a25c7f..ebd44ee19ed4675a109f1cbb5ba70f7f10b1488a 100644
--- a/content/browser/background_fetch/background_fetch_data_manager.h
+++ b/content/browser/background_fetch/background_fetch_data_manager.h
@@ -7,19 +7,18 @@
#include <memory>
#include <set>
-#include <string>
-#include <unordered_map>
+#include <vector>
+#include "base/callback_forward.h"
#include "base/macros.h"
-#include "content/browser/background_fetch/background_fetch_job_data.h"
-#include "content/browser/background_fetch/background_fetch_job_info.h"
#include "content/browser/background_fetch/background_fetch_registration_id.h"
#include "content/common/content_export.h"
-#include "url/origin.h"
+#include "third_party/WebKit/public/platform/modules/background_fetch/background_fetch.mojom.h"
namespace content {
-class BackgroundFetchContext;
+class BackgroundFetchJobData;
+struct ServiceWorkerFetchRequest;
// The BackgroundFetchDataManager keeps track of all of the outstanding requests
// which are in process in the DownloadManager. When Chromium restarts, it is
@@ -27,36 +26,33 @@ class BackgroundFetchContext;
// which will keep the metadata up to date.
class CONTENT_EXPORT BackgroundFetchDataManager {
public:
- explicit BackgroundFetchDataManager(
- BackgroundFetchContext* background_fetch_context);
- ~BackgroundFetchDataManager();
-
- // Called by BackgroundFetchContext when a new request is started, this will
- // store all of the necessary metadata to track the request.
- std::unique_ptr<BackgroundFetchJobData> CreateRequest(
- std::unique_ptr<BackgroundFetchJobInfo> job_info,
- BackgroundFetchRequestInfos request_infos);
-
- private:
- void WriteJobToStorage(std::unique_ptr<BackgroundFetchJobInfo> job_info,
- BackgroundFetchRequestInfos request_infos);
+ using CreateRegistrationCallback =
+ base::OnceCallback<void(blink::mojom::BackgroundFetchError,
+ std::unique_ptr<BackgroundFetchJobData>)>;
+ using DeleteRegistrationCallback =
+ base::OnceCallback<void(blink::mojom::BackgroundFetchError)>;
- BackgroundFetchRequestInfos& ReadRequestsFromStorage(
- const std::string& job_guid);
+ BackgroundFetchDataManager();
+ ~BackgroundFetchDataManager();
- // BackgroundFetchContext owns this BackgroundFetchDataManager, so the
- // DataManager is guaranteed to be destructed before the Context.
- BackgroundFetchContext* background_fetch_context_;
+ // Creates and stores a new registration with the given properties. Will
+ // invoke the |callback| when the registration has been created, which may
+ // fail due to invalid input or storage errors.
+ void CreateRegistration(
+ const BackgroundFetchRegistrationId& registration_id,
+ const std::vector<ServiceWorkerFetchRequest>& requests,
+ const BackgroundFetchOptions& options,
+ CreateRegistrationCallback callback);
- // Set of known background fetch registration ids.
- std::set<BackgroundFetchRegistrationId> known_registrations_;
+ // Deletes the registration identified by |registration_id|. Will invoke the
+ // |callback| when the registration has been deleted from storage.
+ void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id,
+ DeleteRegistrationCallback callback);
- // Temporary map to hold data which will be written to storage.
- // Map from job_guid to JobInfo.
- std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobInfo>>
- job_map_;
- // Map from job_guid to RequestInfos.
- std::unordered_map<std::string, BackgroundFetchRequestInfos> request_map_;
+ private:
+ // TODO(peter): Created registrations should write to storage as opposed to
+ // a map scoped to the lifetime of this instance.
+ std::set<BackgroundFetchRegistrationId> registrations_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager);
};

Powered by Google App Engine
This is Rietveld 408576698