Chromium Code Reviews| Index: content/browser/background_fetch/background_fetch_context.cc |
| diff --git a/content/browser/background_fetch/background_fetch_context.cc b/content/browser/background_fetch/background_fetch_context.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b6707f6ea3f423301f047e888b2f9ab32481bcfa |
| --- /dev/null |
| +++ b/content/browser/background_fetch/background_fetch_context.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/background_fetch/background_fetch_context.h" |
| + |
| +#include "content/browser/background_fetch/fetch_request.h" |
| +#include "content/browser/service_worker/service_worker_context_wrapper.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/download_manager.h" |
| +#include "content/public/browser/storage_partition.h" |
| + |
| +namespace content { |
| + |
| +BackgroundFetchContext::BackgroundFetchContext( |
| + BrowserContext* browser_context, |
| + const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
| + : browser_context_(browser_context), |
| + service_worker_context_(service_worker_context), |
| + background_fetch_data_manager_(this) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + service_worker_context_->AddObserver(this); |
| +} |
| + |
| +BackgroundFetchContext::~BackgroundFetchContext() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + service_worker_context_->RemoveObserver(this); |
| +} |
| + |
| +void BackgroundFetchContext::Init() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + // TODO(harkness) Create the Download observer. |
| + // TODO(harkness) Create the Data manager. |
|
Peter Beverloo
2017/02/13 18:35:05
nit: delete (see line 21)
harkness
2017/02/14 13:52:46
Done.
|
| + // TODO(harkness) Create the Batch manager. |
| +} |
| + |
| +void BackgroundFetchContext::Shutdown() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| +} |
| + |
| +void BackgroundFetchContext::OnRegistrationDeleted(int64_t registration_id, |
| + const GURL& pattern) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + // TODO(harkness) Call into the data manager and delete metadata, this will |
| + // a call to the DownloadManager to abort any ongoing downloads. |
| +} |
| + |
| +void BackgroundFetchContext::CreateRequest(const FetchRequest& fetch_request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + // Inform the data manager about the new download. |
| + background_fetch_data_manager_.CreateRequest(fetch_request); |
| + |
| + // Now make the request to the download manager. |
| + // TODO(harkness) Replace this with a call to the batch manager once that is |
| + // available. |
| + content::StoragePartition* storage_partition = |
|
Peter Beverloo
2017/02/13 18:35:05
drop `content::` everywhere - you are in that name
harkness
2017/02/14 13:52:46
Done.
|
| + content::BrowserContext::GetStoragePartitionForSite( |
| + browser_context_, GURL(fetch_request.origin().Serialize())); |
| + std::unique_ptr<content::DownloadUrlParameters> params( |
| + new content::DownloadUrlParameters( |
| + GURL(fetch_request.url().Serialize()), |
| + storage_partition->GetURLRequestContext())); |
| + // TODO(harkness) Set up the callback and start the download. |
| +} |
| + |
| +} // namespace content |