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

Unified Diff: content/browser/background_fetch/background_fetch_service_impl.cc

Issue 2774343002: Hook up BackgroundFetchServiceImpl::Fetch() to start a fetch (Closed)
Patch Set: 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_service_impl.cc
diff --git a/content/browser/background_fetch/background_fetch_service_impl.cc b/content/browser/background_fetch/background_fetch_service_impl.cc
index 582827e4c4da1b7ced6d64310ccd89142f78bcf7..658f7452c099da801e369a5a61847d11328d9fd3 100644
--- a/content/browser/background_fetch/background_fetch_service_impl.cc
+++ b/content/browser/background_fetch/background_fetch_service_impl.cc
@@ -8,6 +8,8 @@
#include "base/memory/ptr_util.h"
#include "base/optional.h"
#include "content/browser/background_fetch/background_fetch_context.h"
+#include "content/browser/background_fetch/background_fetch_registration_id.h"
+#include "content/browser/bad_message.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/common/background_fetch/background_fetch_types.h"
#include "content/public/browser/browser_thread.h"
@@ -18,23 +20,22 @@ namespace content {
// static
void BackgroundFetchServiceImpl::Create(
+ int render_process_id,
scoped_refptr<BackgroundFetchContext> background_fetch_context,
- scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
blink::mojom::BackgroundFetchServiceRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>(
- std::move(background_fetch_context),
- std::move(service_worker_context)),
- std::move(request));
+ mojo::MakeStrongBinding(
+ base::MakeUnique<BackgroundFetchServiceImpl>(
+ render_process_id, std::move(background_fetch_context)),
+ std::move(request));
}
BackgroundFetchServiceImpl::BackgroundFetchServiceImpl(
- scoped_refptr<BackgroundFetchContext> background_fetch_context,
- scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
- : background_fetch_context_(std::move(background_fetch_context)),
- service_worker_context_(std::move(service_worker_context)) {
+ int render_process_id,
+ scoped_refptr<BackgroundFetchContext> background_fetch_context)
+ : render_process_id_(render_process_id),
+ background_fetch_context_(std::move(background_fetch_context)) {
DCHECK(background_fetch_context_);
- DCHECK(service_worker_context_);
}
BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default;
@@ -45,18 +46,37 @@ void BackgroundFetchServiceImpl::Fetch(int64_t service_worker_registration_id,
const BackgroundFetchOptions& options,
const FetchCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- // TODO(peter): Create a new job with the BackgroundFetchContext for the
- // given tag, requests and options. For now we return a registration that's
- // based on the given |options|, to make sure round-trip is covered.
-
- BackgroundFetchRegistration registration;
- registration.tag = tag;
- registration.icons = options.icons;
- registration.title = options.title;
- registration.total_download_size = options.total_download_size;
-
- callback.Run(blink::mojom::BackgroundFetchError::NONE, registration);
+ BackgroundFetchRegistrationId registration_id(service_worker_registration_id,
+ origin, tag);
+
+ if (tag.empty()) {
+ bad_message::ReceivedBadMessage(render_process_id_,
+ bad_message::BFSI_INVALID_TAG);
+
+ // The |callback| must be run in order to not crash the browser process.
+ callback.Run(blink::mojom::BackgroundFetchError::INVALID_ARGUMENT,
+ base::nullopt /* registration */);
+ return;
+ }
+
+ // TODO(peter): Remove once https://codereview.chromium.org/2762303002/ lands.
+ std::vector<ServiceWorkerFetchRequest> requests;
+ requests.emplace_back(GURL("https://example.com/image.png"), "POST",
+ ServiceWorkerHeaderMap(), Referrer(),
+ false /* is_reload */);
+
+ if (!requests.size()) {
+ bad_message::ReceivedBadMessage(render_process_id_,
+ bad_message::BFSI_INVALID_REQUESTS);
+
+ // The |callback| must be run in order to not crash the browser process.
+ callback.Run(blink::mojom::BackgroundFetchError::INVALID_ARGUMENT,
+ base::nullopt /* registration */);
+ return;
+ }
+
+ background_fetch_context_->StartFetch(registration_id, requests, options,
+ callback);
}
void BackgroundFetchServiceImpl::UpdateUI(

Powered by Google App Engine
This is Rietveld 408576698