Move Background Fetch registration creation to the Data Manager observer
When a Background Fetch registration is created, a BGFetchJobContoller
is created immediately after committing it to storage even if the job
can't be started just yet -- this should be the scheduler's decision.
This CL is the first step in removing the assumption that each existing
Background Fetch registration is represented by a BGFetchJobController.
Acknowledging creation of the registration is separated from indicating
that a new registration is available, by adding an OnRegistrationCreated
method to the BackgroundFetchDataManagerObserver.
As part of this refactoring, in an effort to avoid passing around unique
pointers to BackgroundFetchRegistration objects, these are now passed by
const& where the receiver makes a copy when necessary. This enabled
reducing knowledge of the protobufs throughout our system, which is a
nice clean-up on its own.
TBR=avi for BUILD.gn
Bug: 850512
Change-Id: I8d3c42a11ab89f7b7c3573a6f9a21e096493b838
Reviewed-on: https://chromium-review.googlesource.com/1149871
Commit-Queue: Peter Beverloo <[email protected]>
Reviewed-by: Mugdha Lakhani <[email protected]>
Reviewed-by: Rayan Kanso <[email protected]>
Cr-Commit-Position: refs/heads/master@{#577903}
diff --git a/content/browser/background_fetch/background_fetch_context.h b/content/browser/background_fetch/background_fetch_context.h
index a6b05e1..f2ec5e3 100644
--- a/content/browser/background_fetch/background_fetch_context.h
+++ b/content/browser/background_fetch/background_fetch_context.h
@@ -114,6 +114,12 @@
blink::mojom::BackgroundFetchService::UpdateUICallback callback);
// BackgroundFetchDataManagerObserver implementation.
+ void OnRegistrationCreated(
+ const BackgroundFetchRegistrationId& registration_id,
+ const BackgroundFetchRegistration& registration,
+ const BackgroundFetchOptions& options,
+ const SkBitmap& icon,
+ int num_requests) override;
void OnUpdatedUI(const BackgroundFetchRegistrationId& registration_id,
const std::string& title) override;
void OnServiceWorkerDatabaseCorrupted(
@@ -125,6 +131,8 @@
void OnStorageWiped() override;
private:
+ FRIEND_TEST_ALL_PREFIXES(BackgroundFetchServiceTest,
+ JobsInitializedOnBrowserRestart);
friend class BackgroundFetchServiceTest;
friend class BackgroundFetchJobControllerTest;
friend class base::DeleteHelper<BackgroundFetchContext>;
@@ -138,31 +146,27 @@
// Creates a new Job Controller for the given |registration_id| and |options|,
// which will start fetching the files that are part of the registration.
- void CreateController(
- const BackgroundFetchRegistrationId& registration_id,
- const BackgroundFetchOptions& options,
- const SkBitmap& icon,
- const std::string& ui_title,
- size_t num_completed_requests,
- size_t num_requests,
- const std::vector<std::string>& outstanding_guids,
- std::unique_ptr<BackgroundFetchRegistration> registration);
+ void CreateController(const BackgroundFetchRegistrationId& registration_id,
+ const BackgroundFetchRegistration& registration,
+ const BackgroundFetchOptions& options,
+ const SkBitmap& icon,
+ const std::string& ui_title,
+ size_t num_completed_requests,
+ size_t num_requests,
+ const std::vector<std::string>& outstanding_guids);
// Called when an existing registration has been retrieved from the data
// manager. If the registration does not exist then |registration| is nullptr.
void DidGetRegistration(
blink::mojom::BackgroundFetchService::GetRegistrationCallback callback,
blink::mojom::BackgroundFetchError error,
- std::unique_ptr<BackgroundFetchRegistration> registration);
+ const BackgroundFetchRegistration& registration);
// Called when a new registration has been created by the data manager.
void DidCreateRegistration(
const BackgroundFetchRegistrationId& registration_id,
- const BackgroundFetchOptions& options,
- const SkBitmap& icon,
- size_t num_requests,
blink::mojom::BackgroundFetchError error,
- std::unique_ptr<BackgroundFetchRegistration> registration);
+ const BackgroundFetchRegistration& registration);
// Called by a JobController when it finishes processing. Also used to
// implement |Abort|.