Commit 4de0e19e authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Fetch] Pass developer-provided icon to browser

process from the renderer, all the way through to
OfflineItemsCollector, so that it can be used in notifications.
Also persist it using DataManager.

Additionally, a unit test has been added under browser_tests.

Bug: 813564
Change-Id: I8953deb9a7b19ed6cdab16806e79ffad98186256
Reviewed-on: https://chromium-review.googlesource.com/956183
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543354}
parent 22f5b2e3
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/download/download_service_factory.h" #include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h" #include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -32,6 +33,7 @@ using offline_items_collection::OfflineContentProvider; ...@@ -32,6 +33,7 @@ using offline_items_collection::OfflineContentProvider;
using offline_items_collection::OfflineItem; using offline_items_collection::OfflineItem;
using offline_items_collection::OfflineItemFilter; using offline_items_collection::OfflineItemFilter;
using offline_items_collection::OfflineItemProgressUnit; using offline_items_collection::OfflineItemProgressUnit;
using offline_items_collection::OfflineItemVisuals;
namespace { namespace {
...@@ -190,6 +192,21 @@ class BackgroundFetchBrowserTest : public InProcessBrowserTest { ...@@ -190,6 +192,21 @@ class BackgroundFetchBrowserTest : public InProcessBrowserTest {
run_loop.Run(); run_loop.Run();
} }
void GetVisualsForOfflineItemSync(
const ContentId& offline_item_id,
std::unique_ptr<OfflineItemVisuals>* out_visuals) {
base::RunLoop run_loop;
BackgroundFetchDelegateImpl* delegate =
static_cast<BackgroundFetchDelegateImpl*>(
browser()->profile()->GetBackgroundFetchDelegate());
DCHECK(delegate);
delegate->GetVisualsForItem(
offline_item_id, base::Bind(&BackgroundFetchBrowserTest::DidGetVisuals,
base::Unretained(this),
run_loop.QuitClosure(), out_visuals));
run_loop.Run();
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Helper functions. // Helper functions.
...@@ -243,6 +260,14 @@ class BackgroundFetchBrowserTest : public InProcessBrowserTest { ...@@ -243,6 +260,14 @@ class BackgroundFetchBrowserTest : public InProcessBrowserTest {
std::move(quit_closure).Run(); std::move(quit_closure).Run();
} }
void DidGetVisuals(base::OnceClosure quit_closure,
std::unique_ptr<OfflineItemVisuals>* out_visuals,
const ContentId& offline_item_id,
std::unique_ptr<OfflineItemVisuals> visuals) {
*out_visuals = std::move(visuals);
std::move(quit_closure).Run();
}
std::unique_ptr<net::EmbeddedTestServer> https_server_; std::unique_ptr<net::EmbeddedTestServer> https_server_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchBrowserTest); DISALLOW_COPY_AND_ASSIGN(BackgroundFetchBrowserTest);
...@@ -296,4 +321,42 @@ IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest, ...@@ -296,4 +321,42 @@ IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
EXPECT_FALSE(offline_item.is_resumable); EXPECT_FALSE(offline_item.is_resumable);
} }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
OfflineItemCollection_VerifyIconReceived) {
// Starts a Background Fetch for a single to-be-downloaded file and waits for
// the fetch to be registered with the offline items collection. We then
// verify that the expected icon is associated with the newly added offline
// item.
std::vector<OfflineItem> items;
ASSERT_NO_FATAL_FAILURE(
RunScriptAndWaitForOfflineItems("StartSingleFileDownload()", &items));
ASSERT_EQ(items.size(), 1u);
const OfflineItem& offline_item = items[0];
// Verify that the appropriate data is being set.
EXPECT_EQ(offline_item.title, GetExpectedTitle(kSingleFileDownloadTitle));
EXPECT_EQ(offline_item.filter, OfflineItemFilter::FILTER_OTHER);
EXPECT_TRUE(offline_item.is_transient);
EXPECT_FALSE(offline_item.is_suggested);
EXPECT_FALSE(offline_item.is_off_the_record);
EXPECT_EQ(offline_item.progress.value, 0);
EXPECT_EQ(offline_item.progress.max, 1);
EXPECT_EQ(offline_item.progress.unit, OfflineItemProgressUnit::PERCENTAGE);
// Change-detector tests for values we might want to provide or change.
EXPECT_TRUE(offline_item.description.empty());
EXPECT_TRUE(offline_item.page_url.is_empty());
EXPECT_FALSE(offline_item.is_resumable);
// Get visuals associated with the newly added offline item.
std::unique_ptr<OfflineItemVisuals> out_visuals;
GetVisualsForOfflineItemSync(offline_item.id, &out_visuals);
EXPECT_FALSE(out_visuals->icon.IsEmpty());
EXPECT_EQ(out_visuals->icon.Size().width(), 100);
EXPECT_EQ(out_visuals->icon.Size().height(), 100);
}
} // namespace } // namespace
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "components/offline_items_collection/core/offline_item.h" #include "components/offline_items_collection/core/offline_item.h"
#include "content/public/browser/background_fetch_response.h" #include "content/public/browser/background_fetch_response.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image_skia.h"
BackgroundFetchDelegateImpl::BackgroundFetchDelegateImpl(Profile* profile) BackgroundFetchDelegateImpl::BackgroundFetchDelegateImpl(Profile* profile)
: download_service_( : download_service_(
...@@ -45,10 +47,12 @@ BackgroundFetchDelegateImpl::JobDetails::JobDetails( ...@@ -45,10 +47,12 @@ BackgroundFetchDelegateImpl::JobDetails::JobDetails(
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts) int total_parts)
: title(title), : title(title),
origin(origin), origin(origin),
icon(gfx::ImageSkia::CreateFrom1xBitmap(icon)),
completed_parts(completed_parts), completed_parts(completed_parts),
total_parts(total_parts), total_parts(total_parts),
cancelled(false), cancelled(false),
...@@ -90,6 +94,7 @@ void BackgroundFetchDelegateImpl::CreateDownloadJob( ...@@ -90,6 +94,7 @@ void BackgroundFetchDelegateImpl::CreateDownloadJob(
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
const std::vector<std::string>& current_guids) { const std::vector<std::string>& current_guids) {
...@@ -98,8 +103,8 @@ void BackgroundFetchDelegateImpl::CreateDownloadJob( ...@@ -98,8 +103,8 @@ void BackgroundFetchDelegateImpl::CreateDownloadJob(
DCHECK(!job_details_map_.count(job_unique_id)); DCHECK(!job_details_map_.count(job_unique_id));
auto emplace_result = job_details_map_.emplace( auto emplace_result = job_details_map_.emplace(
job_unique_id, job_unique_id, JobDetails(job_unique_id, title, origin, icon,
JobDetails(job_unique_id, title, origin, completed_parts, total_parts)); completed_parts, total_parts));
const JobDetails& details = emplace_result.first->second; const JobDetails& details = emplace_result.first->second;
...@@ -419,9 +424,15 @@ void BackgroundFetchDelegateImpl::GetVisualsForItem( ...@@ -419,9 +424,15 @@ void BackgroundFetchDelegateImpl::GetVisualsForItem(
const VisualsCallback& callback) { const VisualsCallback& callback) {
// GetVisualsForItem mustn't be called directly since offline_items_collection // GetVisualsForItem mustn't be called directly since offline_items_collection
// is not re-entrant and it must be called even if there are no visuals. // is not re-entrant and it must be called even if there are no visuals.
// TODO(delphick): Call with an image when that becomes available. auto visuals =
std::make_unique<offline_items_collection::OfflineItemVisuals>();
auto it = job_details_map_.find(id.id);
if (it != job_details_map_.end()) {
visuals->icon = it->second.icon;
}
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, id, nullptr)); FROM_HERE, base::BindOnce(callback, id, std::move(visuals)));
} }
void BackgroundFetchDelegateImpl::AddObserver(Observer* observer) { void BackgroundFetchDelegateImpl::AddObserver(Observer* observer) {
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
#include "components/offline_items_collection/core/offline_content_provider.h" #include "components/offline_items_collection/core/offline_content_provider.h"
#include "components/offline_items_collection/core/offline_item.h" #include "components/offline_items_collection/core/offline_item.h"
#include "content/public/browser/background_fetch_delegate.h" #include "content/public/browser/background_fetch_delegate.h"
#include "ui/gfx/image/image.h"
#include "url/origin.h" #include "url/origin.h"
class Profile; class Profile;
class SkBitmap;
namespace download { namespace download {
class DownloadService; class DownloadService;
...@@ -50,6 +52,7 @@ class BackgroundFetchDelegateImpl ...@@ -50,6 +52,7 @@ class BackgroundFetchDelegateImpl
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
const std::vector<std::string>& current_guids) override; const std::vector<std::string>& current_guids) override;
...@@ -98,6 +101,7 @@ class BackgroundFetchDelegateImpl ...@@ -98,6 +101,7 @@ class BackgroundFetchDelegateImpl
JobDetails(const std::string& job_unique_id, JobDetails(const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts); int total_parts);
~JobDetails(); ~JobDetails();
...@@ -106,6 +110,7 @@ class BackgroundFetchDelegateImpl ...@@ -106,6 +110,7 @@ class BackgroundFetchDelegateImpl
std::string title; std::string title;
const url::Origin origin; const url::Origin origin;
gfx::Image icon;
int completed_parts; int completed_parts;
const int total_parts; const int total_parts;
bool cancelled; bool cancelled;
......
...@@ -15,7 +15,13 @@ function RegisterServiceWorker() { ...@@ -15,7 +15,13 @@ function RegisterServiceWorker() {
function StartSingleFileDownload() { function StartSingleFileDownload() {
navigator.serviceWorker.ready.then(swRegistration => { navigator.serviceWorker.ready.then(swRegistration => {
const options = { const options = {
// TODO(nator): Provide an icon here. icons: [
{
src: '/notifications/icon.png',
sizes: '100x100',
type: 'image/png'
}
],
title: 'Single-file Background Fetch' title: 'Single-file Background Fetch'
}; };
......
...@@ -37,14 +37,16 @@ ContentId JNI_OfflineContentAggregatorBridge_CreateContentId( ...@@ -37,14 +37,16 @@ ContentId JNI_OfflineContentAggregatorBridge_CreateContentId(
ConvertJavaStringToUTF8(env, j_id)); ConvertJavaStringToUTF8(env, j_id));
} }
void GetVisualsForItemHelperCallback(ScopedJavaGlobalRef<jobject> j_callback, void GetVisualsForItemHelperCallback(
ScopedJavaGlobalRef<jobject> j_callback,
const ContentId& id, const ContentId& id,
const OfflineItemVisuals* visuals) { std::unique_ptr<OfflineItemVisuals> visuals) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
Java_OfflineContentAggregatorBridge_onVisualsAvailable( Java_OfflineContentAggregatorBridge_onVisualsAvailable(
env, j_callback, ConvertUTF8ToJavaString(env, id.name_space), env, j_callback, ConvertUTF8ToJavaString(env, id.name_space),
ConvertUTF8ToJavaString(env, id.id), ConvertUTF8ToJavaString(env, id.id),
OfflineItemVisualsBridge::CreateOfflineItemVisuals(env, visuals)); OfflineItemVisualsBridge::CreateOfflineItemVisuals(env,
std::move(visuals)));
} }
void RunGetAllItemsCallback(const base::android::JavaRef<jobject>& j_callback, void RunGetAllItemsCallback(const base::android::JavaRef<jobject>& j_callback,
......
...@@ -17,7 +17,7 @@ namespace android { ...@@ -17,7 +17,7 @@ namespace android {
// static // static
ScopedJavaLocalRef<jobject> OfflineItemVisualsBridge::CreateOfflineItemVisuals( ScopedJavaLocalRef<jobject> OfflineItemVisualsBridge::CreateOfflineItemVisuals(
JNIEnv* env, JNIEnv* env,
const OfflineItemVisuals* const visuals) { std::unique_ptr<OfflineItemVisuals> const visuals) {
if (!visuals) if (!visuals)
return nullptr; return nullptr;
......
...@@ -23,7 +23,7 @@ class OfflineItemVisualsBridge { ...@@ -23,7 +23,7 @@ class OfflineItemVisualsBridge {
// Creates a Java OfflineItemVisuals from |visuals|. // Creates a Java OfflineItemVisuals from |visuals|.
static base::android::ScopedJavaLocalRef<jobject> CreateOfflineItemVisuals( static base::android::ScopedJavaLocalRef<jobject> CreateOfflineItemVisuals(
JNIEnv* env, JNIEnv* env,
const OfflineItemVisuals* const visuals); std::unique_ptr<OfflineItemVisuals> visuals);
private: private:
OfflineItemVisualsBridge(); OfflineItemVisualsBridge();
......
...@@ -24,7 +24,8 @@ class OfflineContentProvider { ...@@ -24,7 +24,8 @@ class OfflineContentProvider {
public: public:
using OfflineItemList = std::vector<OfflineItem>; using OfflineItemList = std::vector<OfflineItem>;
using VisualsCallback = using VisualsCallback =
base::Callback<void(const ContentId&, const OfflineItemVisuals*)>; base::Callback<void(const ContentId&,
std::unique_ptr<OfflineItemVisuals>)>;
using MultipleItemCallback = base::OnceCallback<void(const OfflineItemList&)>; using MultipleItemCallback = base::OnceCallback<void(const OfflineItemList&)>;
using SingleItemCallback = using SingleItemCallback =
base::OnceCallback<void(const base::Optional<OfflineItem>&)>; base::OnceCallback<void(const base::Optional<OfflineItem>&)>;
......
...@@ -103,19 +103,21 @@ void BackgroundFetchContext::StartFetch( ...@@ -103,19 +103,21 @@ void BackgroundFetchContext::StartFetch(
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback) { blink::mojom::BackgroundFetchService::FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
data_manager_.CreateRegistration( data_manager_.CreateRegistration(
registration_id, requests, options, registration_id, requests, options, icon,
base::BindOnce(&BackgroundFetchContext::DidCreateRegistration, base::BindOnce(&BackgroundFetchContext::DidCreateRegistration,
weak_factory_.GetWeakPtr(), registration_id, options, weak_factory_.GetWeakPtr(), registration_id, options, icon,
std::move(callback))); std::move(callback)));
} }
void BackgroundFetchContext::DidCreateRegistration( void BackgroundFetchContext::DidCreateRegistration(
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback, blink::mojom::BackgroundFetchService::FetchCallback callback,
blink::mojom::BackgroundFetchError error, blink::mojom::BackgroundFetchError error,
std::unique_ptr<BackgroundFetchRegistration> registration) { std::unique_ptr<BackgroundFetchRegistration> registration) {
...@@ -129,7 +131,7 @@ void BackgroundFetchContext::DidCreateRegistration( ...@@ -129,7 +131,7 @@ void BackgroundFetchContext::DidCreateRegistration(
DCHECK(registration); DCHECK(registration);
// Create the BackgroundFetchJobController to do the actual fetching. // Create the BackgroundFetchJobController to do the actual fetching.
CreateController(registration_id, options, *registration.get()); CreateController(registration_id, options, icon, *registration.get());
std::move(callback).Run(error, *registration.get()); std::move(callback).Run(error, *registration.get());
} }
...@@ -180,11 +182,12 @@ void BackgroundFetchContext::DidUpdateStoredUI( ...@@ -180,11 +182,12 @@ void BackgroundFetchContext::DidUpdateStoredUI(
void BackgroundFetchContext::CreateController( void BackgroundFetchContext::CreateController(
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
const BackgroundFetchRegistration& registration) { const BackgroundFetchRegistration& registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
auto controller = std::make_unique<BackgroundFetchJobController>( auto controller = std::make_unique<BackgroundFetchJobController>(
&delegate_proxy_, registration_id, options, registration, &delegate_proxy_, registration_id, options, icon, registration,
scheduler_.get(), scheduler_.get(),
// Safe because JobControllers are destroyed before RegistrationNotifier. // Safe because JobControllers are destroyed before RegistrationNotifier.
base::BindRepeating(&BackgroundFetchRegistrationNotifier::Notify, base::BindRepeating(&BackgroundFetchRegistrationNotifier::Notify,
......
...@@ -71,6 +71,7 @@ class CONTENT_EXPORT BackgroundFetchContext ...@@ -71,6 +71,7 @@ class CONTENT_EXPORT BackgroundFetchContext
void StartFetch(const BackgroundFetchRegistrationId& registration_id, void StartFetch(const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback); blink::mojom::BackgroundFetchService::FetchCallback callback);
// Aborts the Background Fetch for the |registration_id|. The callback will be // Aborts the Background Fetch for the |registration_id|. The callback will be
...@@ -106,6 +107,7 @@ class CONTENT_EXPORT BackgroundFetchContext ...@@ -106,6 +107,7 @@ class CONTENT_EXPORT BackgroundFetchContext
// which will start fetching the files that are part of the registration. // which will start fetching the files that are part of the registration.
void CreateController(const BackgroundFetchRegistrationId& registration_id, void CreateController(const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
const BackgroundFetchRegistration& registration); const BackgroundFetchRegistration& registration);
// Called when an existing registration has been retrieved from the data // Called when an existing registration has been retrieved from the data
...@@ -119,6 +121,7 @@ class CONTENT_EXPORT BackgroundFetchContext ...@@ -119,6 +121,7 @@ class CONTENT_EXPORT BackgroundFetchContext
void DidCreateRegistration( void DidCreateRegistration(
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback, blink::mojom::BackgroundFetchService::FetchCallback callback,
blink::mojom::BackgroundFetchError error, blink::mojom::BackgroundFetchError error,
std::unique_ptr<BackgroundFetchRegistration> registration); std::unique_ptr<BackgroundFetchRegistration> registration);
......
...@@ -51,8 +51,9 @@ class BackgroundFetchDataManager::RegistrationData { ...@@ -51,8 +51,9 @@ class BackgroundFetchDataManager::RegistrationData {
public: public:
RegistrationData(const BackgroundFetchRegistrationId& registration_id, RegistrationData(const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options) const BackgroundFetchOptions& options,
: registration_id_(registration_id), options_(options) { const SkBitmap& icon)
: registration_id_(registration_id), options_(options), icon_(icon) {
int request_index = 0; int request_index = 0;
// Convert the given |requests| to BackgroundFetchRequestInfo objects. // Convert the given |requests| to BackgroundFetchRequestInfo objects.
...@@ -124,6 +125,7 @@ class BackgroundFetchDataManager::RegistrationData { ...@@ -124,6 +125,7 @@ class BackgroundFetchDataManager::RegistrationData {
private: private:
BackgroundFetchRegistrationId registration_id_; BackgroundFetchRegistrationId registration_id_;
BackgroundFetchOptions options_; BackgroundFetchOptions options_;
SkBitmap icon_;
// Number of bytes downloaded as part of completed downloads. (In-progress // Number of bytes downloaded as part of completed downloads. (In-progress
// downloads are tracked elsewhere). // downloads are tracked elsewhere).
uint64_t complete_requests_downloaded_bytes_ = 0; uint64_t complete_requests_downloaded_bytes_ = 0;
...@@ -178,6 +180,7 @@ void BackgroundFetchDataManager::CreateRegistration( ...@@ -178,6 +180,7 @@ void BackgroundFetchDataManager::CreateRegistration(
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
GetRegistrationCallback callback) { GetRegistrationCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -207,9 +210,9 @@ void BackgroundFetchDataManager::CreateRegistration( ...@@ -207,9 +210,9 @@ void BackgroundFetchDataManager::CreateRegistration(
registration_id.unique_id()); registration_id.unique_id());
// Create the |RegistrationData|, and store it for easy access. // Create the |RegistrationData|, and store it for easy access.
registrations_.emplace( registrations_.emplace(registration_id.unique_id(),
registration_id.unique_id(), std::make_unique<RegistrationData>(
std::make_unique<RegistrationData>(registration_id, requests, options)); registration_id, requests, options, icon));
// Re-use GetRegistration to compile the BackgroundFetchRegistration object. // Re-use GetRegistration to compile the BackgroundFetchRegistration object.
// WARNING: GetRegistration doesn't use the |unique_id| when looking up the // WARNING: GetRegistration doesn't use the |unique_id| when looking up the
......
...@@ -73,6 +73,7 @@ class CONTENT_EXPORT BackgroundFetchDataManager ...@@ -73,6 +73,7 @@ class CONTENT_EXPORT BackgroundFetchDataManager
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
GetRegistrationCallback callback); GetRegistrationCallback callback);
// Get the BackgroundFetchOptions for a registration. // Get the BackgroundFetchOptions for a registration.
......
...@@ -116,7 +116,7 @@ class BackgroundFetchDataManagerTest ...@@ -116,7 +116,7 @@ class BackgroundFetchDataManagerTest
base::RunLoop run_loop; base::RunLoop run_loop;
background_fetch_data_manager_->CreateRegistration( background_fetch_data_manager_->CreateRegistration(
registration_id, requests, options, registration_id, requests, options, SkBitmap(),
base::BindOnce(&DidCreateRegistration, run_loop.QuitClosure(), base::BindOnce(&DidCreateRegistration, run_loop.QuitClosure(),
out_error)); out_error));
run_loop.Run(); run_loop.Run();
...@@ -545,7 +545,7 @@ TEST_P(BackgroundFetchDataManagerTest, CreateInParallel) { ...@@ -545,7 +545,7 @@ TEST_P(BackgroundFetchDataManagerTest, CreateInParallel) {
base::GenerateGUID()); base::GenerateGUID());
background_fetch_data_manager_->CreateRegistration( background_fetch_data_manager_->CreateRegistration(
registration_id, requests, options, registration_id, requests, options, SkBitmap(),
base::BindOnce(&DidCreateRegistration, quit_once_all_finished_closure, base::BindOnce(&DidCreateRegistration, quit_once_all_finished_closure,
&errors[i])); &errors[i]));
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "content/public/browser/background_fetch_response.h" #include "content/public/browser/background_fetch_response.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
class SkBitmap;
namespace content { namespace content {
// Internal functionality of the BackgroundFetchDelegateProxy that lives on the // Internal functionality of the BackgroundFetchDelegateProxy that lives on the
...@@ -42,13 +44,14 @@ class BackgroundFetchDelegateProxy::Core ...@@ -42,13 +44,14 @@ class BackgroundFetchDelegateProxy::Core
void CreateDownloadJob(const std::string& job_unique_id, void CreateDownloadJob(const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
const std::vector<std::string>& current_guids) { const std::vector<std::string>& current_guids) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (delegate_) { if (delegate_) {
delegate_->CreateDownloadJob(job_unique_id, title, origin, delegate_->CreateDownloadJob(job_unique_id, title, origin, icon,
completed_parts, total_parts, current_guids); completed_parts, total_parts, current_guids);
} }
} }
...@@ -231,6 +234,7 @@ void BackgroundFetchDelegateProxy::CreateDownloadJob( ...@@ -231,6 +234,7 @@ void BackgroundFetchDelegateProxy::CreateDownloadJob(
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
base::WeakPtr<Controller> controller, base::WeakPtr<Controller> controller,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
...@@ -243,7 +247,7 @@ void BackgroundFetchDelegateProxy::CreateDownloadJob( ...@@ -243,7 +247,7 @@ void BackgroundFetchDelegateProxy::CreateDownloadJob(
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&Core::CreateDownloadJob, ui_core_ptr_, job_unique_id, base::BindOnce(&Core::CreateDownloadJob, ui_core_ptr_, job_unique_id,
title, origin, completed_parts, total_parts, title, origin, icon, completed_parts, total_parts,
current_guids)); current_guids));
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "content/public/browser/background_fetch_response.h" #include "content/public/browser/background_fetch_response.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
class SkBitmap;
namespace content { namespace content {
class BackgroundFetchDelegate; class BackgroundFetchDelegate;
...@@ -65,6 +67,7 @@ class CONTENT_EXPORT BackgroundFetchDelegateProxy { ...@@ -65,6 +67,7 @@ class CONTENT_EXPORT BackgroundFetchDelegateProxy {
void CreateDownloadJob(const std::string& job_unique_id, void CreateDownloadJob(const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
base::WeakPtr<Controller> controller, base::WeakPtr<Controller> controller,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
......
...@@ -30,6 +30,7 @@ class FakeBackgroundFetchDelegate : public BackgroundFetchDelegate { ...@@ -30,6 +30,7 @@ class FakeBackgroundFetchDelegate : public BackgroundFetchDelegate {
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
const std::vector<std::string>& current_guids) override {} const std::vector<std::string>& current_guids) override {}
...@@ -140,9 +141,9 @@ TEST_F(BackgroundFetchDelegateProxyTest, StartRequest) { ...@@ -140,9 +141,9 @@ TEST_F(BackgroundFetchDelegateProxyTest, StartRequest) {
EXPECT_FALSE(controller.request_started_); EXPECT_FALSE(controller.request_started_);
EXPECT_FALSE(controller.request_completed_); EXPECT_FALSE(controller.request_completed_);
delegate_proxy_.CreateDownloadJob(kExampleUniqueId, "Job 1", url::Origin(), delegate_proxy_.CreateDownloadJob(
controller.weak_ptr_factory_.GetWeakPtr(), kExampleUniqueId, "Job 1", url::Origin(), SkBitmap(),
0, 1, {}); controller.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request); delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -160,9 +161,9 @@ TEST_F(BackgroundFetchDelegateProxyTest, StartRequest_NotCompleted) { ...@@ -160,9 +161,9 @@ TEST_F(BackgroundFetchDelegateProxyTest, StartRequest_NotCompleted) {
EXPECT_FALSE(controller.request_completed_); EXPECT_FALSE(controller.request_completed_);
delegate_.set_complete_downloads(false); delegate_.set_complete_downloads(false);
delegate_proxy_.CreateDownloadJob(kExampleUniqueId, "Job 1", url::Origin(), delegate_proxy_.CreateDownloadJob(
controller.weak_ptr_factory_.GetWeakPtr(), kExampleUniqueId, "Job 1", url::Origin(), SkBitmap(),
0, 1, {}); controller.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request); delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -184,13 +185,13 @@ TEST_F(BackgroundFetchDelegateProxyTest, Abort) { ...@@ -184,13 +185,13 @@ TEST_F(BackgroundFetchDelegateProxyTest, Abort) {
EXPECT_FALSE(controller2.request_started_); EXPECT_FALSE(controller2.request_started_);
EXPECT_FALSE(controller2.request_completed_); EXPECT_FALSE(controller2.request_completed_);
delegate_proxy_.CreateDownloadJob(kExampleUniqueId, "Job 1", url::Origin(), delegate_proxy_.CreateDownloadJob(
controller.weak_ptr_factory_.GetWeakPtr(), kExampleUniqueId, "Job 1", url::Origin(), SkBitmap(),
0, 1, {}); controller.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.CreateDownloadJob(kExampleUniqueId2, "Job 2", url::Origin(), delegate_proxy_.CreateDownloadJob(
controller2.weak_ptr_factory_.GetWeakPtr(), kExampleUniqueId2, "Job 2", url::Origin(), SkBitmap(),
0, 1, {}); controller2.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request); delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request);
delegate_proxy_.StartRequest(kExampleUniqueId2, url::Origin(), request2); delegate_proxy_.StartRequest(kExampleUniqueId2, url::Origin(), request2);
......
...@@ -16,6 +16,7 @@ BackgroundFetchJobController::BackgroundFetchJobController( ...@@ -16,6 +16,7 @@ BackgroundFetchJobController::BackgroundFetchJobController(
BackgroundFetchDelegateProxy* delegate_proxy, BackgroundFetchDelegateProxy* delegate_proxy,
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
const BackgroundFetchRegistration& registration, const BackgroundFetchRegistration& registration,
BackgroundFetchRequestManager* request_manager, BackgroundFetchRequestManager* request_manager,
ProgressCallback progress_callback, ProgressCallback progress_callback,
...@@ -23,6 +24,7 @@ BackgroundFetchJobController::BackgroundFetchJobController( ...@@ -23,6 +24,7 @@ BackgroundFetchJobController::BackgroundFetchJobController(
: BackgroundFetchScheduler::Controller(registration_id, : BackgroundFetchScheduler::Controller(registration_id,
std::move(finished_callback)), std::move(finished_callback)),
options_(options), options_(options),
icon_(icon),
complete_requests_downloaded_bytes_cache_(registration.downloaded), complete_requests_downloaded_bytes_cache_(registration.downloaded),
request_manager_(request_manager), request_manager_(request_manager),
delegate_proxy_(delegate_proxy), delegate_proxy_(delegate_proxy),
...@@ -44,9 +46,10 @@ void BackgroundFetchJobController::InitializeRequestStatus( ...@@ -44,9 +46,10 @@ void BackgroundFetchJobController::InitializeRequestStatus(
completed_downloads_ = completed_downloads; completed_downloads_ = completed_downloads;
total_downloads_ = total_downloads; total_downloads_ = total_downloads;
delegate_proxy_->CreateDownloadJob( delegate_proxy_->CreateDownloadJob(registration_id().unique_id(),
registration_id().unique_id(), options_.title, registration_id().origin(), options_.title, registration_id().origin(),
GetWeakPtr(), completed_downloads, total_downloads, outstanding_guids); icon_, GetWeakPtr(), completed_downloads,
total_downloads, outstanding_guids);
} }
BackgroundFetchJobController::~BackgroundFetchJobController() { BackgroundFetchJobController::~BackgroundFetchJobController() {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "content/common/background_fetch/background_fetch_types.h" #include "content/common/background_fetch/background_fetch_types.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace content { namespace content {
...@@ -49,6 +50,7 @@ class CONTENT_EXPORT BackgroundFetchJobController final ...@@ -49,6 +50,7 @@ class CONTENT_EXPORT BackgroundFetchJobController final
BackgroundFetchDelegateProxy* delegate_proxy, BackgroundFetchDelegateProxy* delegate_proxy,
const BackgroundFetchRegistrationId& registration_id, const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
const BackgroundFetchRegistration& registration, const BackgroundFetchRegistration& registration,
BackgroundFetchRequestManager* request_manager, BackgroundFetchRequestManager* request_manager,
ProgressCallback progress_callback, ProgressCallback progress_callback,
...@@ -102,6 +104,9 @@ class CONTENT_EXPORT BackgroundFetchJobController final ...@@ -102,6 +104,9 @@ class CONTENT_EXPORT BackgroundFetchJobController final
// Options for the represented background fetch registration. // Options for the represented background fetch registration.
BackgroundFetchOptions options_; BackgroundFetchOptions options_;
// Icon for the represented background fetch registration.
SkBitmap icon_;
// Map from in-progress |download_guid|s to number of bytes downloaded. // Map from in-progress |download_guid|s to number of bytes downloaded.
base::flat_map<std::string, uint64_t> active_request_download_bytes_; base::flat_map<std::string, uint64_t> active_request_download_bytes_;
......
...@@ -156,7 +156,7 @@ class BackgroundFetchJobControllerTest : public BackgroundFetchTestBase { ...@@ -156,7 +156,7 @@ class BackgroundFetchJobControllerTest : public BackgroundFetchTestBase {
auto controller = std::make_unique<BackgroundFetchJobController>( auto controller = std::make_unique<BackgroundFetchJobController>(
delegate_proxy_.get(), registration_id, BackgroundFetchOptions(), delegate_proxy_.get(), registration_id, BackgroundFetchOptions(),
registration, &request_manager_, SkBitmap(), registration, &request_manager_,
base::BindRepeating( base::BindRepeating(
&BackgroundFetchJobControllerTest::DidUpdateProgress, &BackgroundFetchJobControllerTest::DidUpdateProgress,
base::Unretained(this)), base::Unretained(this)),
......
...@@ -73,6 +73,7 @@ void BackgroundFetchServiceImpl::Fetch( ...@@ -73,6 +73,7 @@ void BackgroundFetchServiceImpl::Fetch(
const std::string& developer_id, const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
FetchCallback callback) { FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!ValidateDeveloperId(developer_id)) { if (!ValidateDeveloperId(developer_id)) {
...@@ -96,7 +97,7 @@ void BackgroundFetchServiceImpl::Fetch( ...@@ -96,7 +97,7 @@ void BackgroundFetchServiceImpl::Fetch(
base::GenerateGUID()); base::GenerateGUID());
background_fetch_context_->StartFetch(registration_id, requests, options, background_fetch_context_->StartFetch(registration_id, requests, options,
std::move(callback)); icon, std::move(callback));
} }
void BackgroundFetchServiceImpl::UpdateUI(const std::string& unique_id, void BackgroundFetchServiceImpl::UpdateUI(const std::string& unique_id,
......
...@@ -40,6 +40,7 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl ...@@ -40,6 +40,7 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
const std::string& developer_id, const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
FetchCallback callback) override; FetchCallback callback) override;
void UpdateUI(const std::string& unique_id, void UpdateUI(const std::string& unique_id,
const std::string& title, const std::string& title,
......
...@@ -93,6 +93,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase { ...@@ -93,6 +93,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
const std::string& developer_id, const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests, const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchError* out_error, blink::mojom::BackgroundFetchError* out_error,
BackgroundFetchRegistration* out_registration) { BackgroundFetchRegistration* out_registration) {
DCHECK(out_error); DCHECK(out_error);
...@@ -100,7 +101,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase { ...@@ -100,7 +101,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
base::RunLoop run_loop; base::RunLoop run_loop;
service_->Fetch( service_->Fetch(
service_worker_registration_id, developer_id, requests, options, service_worker_registration_id, developer_id, requests, options, icon,
base::BindOnce(&BackgroundFetchServiceTest::DidGetRegistration, base::BindOnce(&BackgroundFetchServiceTest::DidGetRegistration,
base::Unretained(this), run_loop.QuitClosure(), base::Unretained(this), run_loop.QuitClosure(),
out_error, out_registration)); out_error, out_registration));
...@@ -258,7 +259,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) { ...@@ -258,7 +259,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) {
BackgroundFetchRegistration registration; BackgroundFetchRegistration registration;
Fetch(42 /* service_worker_registration_id */, "" /* developer_id */, Fetch(42 /* service_worker_registration_id */, "" /* developer_id */,
requests, options, &error, &registration); requests, options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT);
EXPECT_EQ("Invalid developer_id", bad_message_observer.last_error()); EXPECT_EQ("Invalid developer_id", bad_message_observer.last_error());
} }
...@@ -273,7 +274,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) { ...@@ -273,7 +274,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) {
BackgroundFetchRegistration registration; BackgroundFetchRegistration registration;
Fetch(42 /* service_worker_registration_id */, kExampleDeveloperId, Fetch(42 /* service_worker_registration_id */, kExampleDeveloperId,
requests, options, &error, &registration); requests, options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT);
EXPECT_EQ("Invalid requests", bad_message_observer.last_error()); EXPECT_EQ("Invalid requests", bad_message_observer.last_error());
} }
...@@ -301,7 +302,7 @@ TEST_F(BackgroundFetchServiceTest, FetchRegistrationProperties) { ...@@ -301,7 +302,7 @@ TEST_F(BackgroundFetchServiceTest, FetchRegistrationProperties) {
BackgroundFetchRegistration registration; BackgroundFetchRegistration registration;
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options, Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options,
&error, &registration); SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
// The |registration| should reflect the options given in |options|. // The |registration| should reflect the options given in |options|.
...@@ -341,7 +342,7 @@ TEST_F(BackgroundFetchServiceTest, FetchDuplicatedRegistrationFailure) { ...@@ -341,7 +342,7 @@ TEST_F(BackgroundFetchServiceTest, FetchDuplicatedRegistrationFailure) {
// Create the first registration. This must succeed. // Create the first registration. This must succeed.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options, Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options,
&error, &registration); SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
blink::mojom::BackgroundFetchError second_error; blink::mojom::BackgroundFetchError second_error;
...@@ -349,7 +350,7 @@ TEST_F(BackgroundFetchServiceTest, FetchDuplicatedRegistrationFailure) { ...@@ -349,7 +350,7 @@ TEST_F(BackgroundFetchServiceTest, FetchDuplicatedRegistrationFailure) {
// Create the second registration with the same data. This must fail. // Create the second registration with the same data. This must fail.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options, Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options,
&second_error, &second_registration); SkBitmap(), &second_error, &second_registration);
ASSERT_EQ(second_error, ASSERT_EQ(second_error,
blink::mojom::BackgroundFetchError::DUPLICATED_DEVELOPER_ID); blink::mojom::BackgroundFetchError::DUPLICATED_DEVELOPER_ID);
} }
...@@ -409,7 +410,7 @@ TEST_F(BackgroundFetchServiceTest, FetchSuccessEventDispatch) { ...@@ -409,7 +410,7 @@ TEST_F(BackgroundFetchServiceTest, FetchSuccessEventDispatch) {
// Create the first registration. This must succeed. // Create the first registration. This must succeed.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration); options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
} }
...@@ -508,7 +509,7 @@ TEST_F(BackgroundFetchServiceTest, FetchFailEventDispatch) { ...@@ -508,7 +509,7 @@ TEST_F(BackgroundFetchServiceTest, FetchFailEventDispatch) {
// Create the first registration. This must succeed. // Create the first registration. This must succeed.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration); options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
} }
...@@ -579,7 +580,7 @@ TEST_F(BackgroundFetchServiceTest, UpdateUI) { ...@@ -579,7 +580,7 @@ TEST_F(BackgroundFetchServiceTest, UpdateUI) {
// Create the registration. // Create the registration.
BackgroundFetchRegistrationId registration_id = BackgroundFetchRegistrationId registration_id =
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration); options, SkBitmap(), &error, &registration);
ASSERT_EQ(blink::mojom::BackgroundFetchError::NONE, error); ASSERT_EQ(blink::mojom::BackgroundFetchError::NONE, error);
std::string second_title = "2nd title"; std::string second_title = "2nd title";
...@@ -615,7 +616,7 @@ TEST_F(BackgroundFetchServiceTest, Abort) { ...@@ -615,7 +616,7 @@ TEST_F(BackgroundFetchServiceTest, Abort) {
// Create the registration. This must succeed. // Create the registration. This must succeed.
BackgroundFetchRegistrationId registration_id = BackgroundFetchRegistrationId registration_id =
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration); options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
blink::mojom::BackgroundFetchError abort_error; blink::mojom::BackgroundFetchError abort_error;
...@@ -705,8 +706,9 @@ TEST_F(BackgroundFetchServiceTest, AbortEventDispatch) { ...@@ -705,8 +706,9 @@ TEST_F(BackgroundFetchServiceTest, AbortEventDispatch) {
BackgroundFetchRegistration registration; BackgroundFetchRegistration registration;
// Create the registration. This must succeed. // Create the registration. This must succeed.
registration_id = Fetch(service_worker_registration_id, kExampleDeveloperId, registration_id =
requests, options, &error, &registration); Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
} }
...@@ -751,7 +753,7 @@ TEST_F(BackgroundFetchServiceTest, UniqueId) { ...@@ -751,7 +753,7 @@ TEST_F(BackgroundFetchServiceTest, UniqueId) {
BackgroundFetchRegistration aborted_registration; BackgroundFetchRegistration aborted_registration;
BackgroundFetchRegistrationId aborted_registration_id = BackgroundFetchRegistrationId aborted_registration_id =
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
aborted_options, &error, &aborted_registration); aborted_options, SkBitmap(), &error, &aborted_registration);
ASSERT_EQ(blink::mojom::BackgroundFetchError::NONE, error); ASSERT_EQ(blink::mojom::BackgroundFetchError::NONE, error);
// Immediately abort the registration so it is no longer active (everything // Immediately abort the registration so it is no longer active (everything
...@@ -770,7 +772,7 @@ TEST_F(BackgroundFetchServiceTest, UniqueId) { ...@@ -770,7 +772,7 @@ TEST_F(BackgroundFetchServiceTest, UniqueId) {
BackgroundFetchRegistration second_registration; BackgroundFetchRegistration second_registration;
BackgroundFetchRegistrationId second_registration_id = BackgroundFetchRegistrationId second_registration_id =
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
second_options, &error, &second_registration); second_options, SkBitmap(), &error, &second_registration);
EXPECT_EQ(blink::mojom::BackgroundFetchError::NONE, error); EXPECT_EQ(blink::mojom::BackgroundFetchError::NONE, error);
// Now try to get the registration using its |developer_id|. This should // Now try to get the registration using its |developer_id|. This should
...@@ -865,7 +867,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) { ...@@ -865,7 +867,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
BackgroundFetchRegistration registration; BackgroundFetchRegistration registration;
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration); options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
} }
...@@ -887,7 +889,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) { ...@@ -887,7 +889,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
BackgroundFetchRegistration registration; BackgroundFetchRegistration registration;
Fetch(service_worker_registration_id, kAlternativeDeveloperId, requests, Fetch(service_worker_registration_id, kAlternativeDeveloperId, requests,
options, &error, &registration); options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE); ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
} }
......
...@@ -59,6 +59,7 @@ void MockBackgroundFetchDelegate::CreateDownloadJob( ...@@ -59,6 +59,7 @@ void MockBackgroundFetchDelegate::CreateDownloadJob(
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
const std::vector<std::string>& current_guids) {} const std::vector<std::string>& current_guids) {}
......
...@@ -67,6 +67,7 @@ class MockBackgroundFetchDelegate : public BackgroundFetchDelegate { ...@@ -67,6 +67,7 @@ class MockBackgroundFetchDelegate : public BackgroundFetchDelegate {
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
const std::vector<std::string>& current_guids) override; const std::vector<std::string>& current_guids) override;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
class GURL; class GURL;
class SkBitmap;
namespace net { namespace net {
class HttpRequestHeaders; class HttpRequestHeaders;
...@@ -84,6 +85,7 @@ class CONTENT_EXPORT BackgroundFetchDelegate { ...@@ -84,6 +85,7 @@ class CONTENT_EXPORT BackgroundFetchDelegate {
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& title, const std::string& title,
const url::Origin& origin, const url::Origin& origin,
const SkBitmap& icon,
int completed_parts, int completed_parts,
int total_parts, int total_parts,
const std::vector<std::string>& current_guids) = 0; const std::vector<std::string>& current_guids) = 0;
......
...@@ -44,10 +44,12 @@ BackgroundFetchBridge::~BackgroundFetchBridge() = default; ...@@ -44,10 +44,12 @@ BackgroundFetchBridge::~BackgroundFetchBridge() = default;
void BackgroundFetchBridge::Fetch(const String& developer_id, void BackgroundFetchBridge::Fetch(const String& developer_id,
Vector<WebServiceWorkerRequest> requests, Vector<WebServiceWorkerRequest> requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
const SkBitmap& icon,
RegistrationCallback callback) { RegistrationCallback callback) {
GetService()->Fetch( GetService()->Fetch(
GetSupplementable()->WebRegistration()->RegistrationId(), developer_id, GetSupplementable()->WebRegistration()->RegistrationId(), developer_id,
std::move(requests), mojom::blink::BackgroundFetchOptions::From(options), std::move(requests), mojom::blink::BackgroundFetchOptions::From(options),
icon,
WTF::Bind(&BackgroundFetchBridge::DidGetRegistration, WTF::Bind(&BackgroundFetchBridge::DidGetRegistration,
WrapPersistent(this), WTF::Passed(std::move(callback)))); WrapPersistent(this), WTF::Passed(std::move(callback))));
} }
......
...@@ -53,6 +53,7 @@ class BackgroundFetchBridge final ...@@ -53,6 +53,7 @@ class BackgroundFetchBridge final
void Fetch(const String& developer_id, void Fetch(const String& developer_id,
Vector<WebServiceWorkerRequest> requests, Vector<WebServiceWorkerRequest> requests,
const BackgroundFetchOptions&, const BackgroundFetchOptions&,
const SkBitmap& icon,
RegistrationCallback); RegistrationCallback);
// Updates the user interface for the Background Fetch identified by // Updates the user interface for the Background Fetch identified by
......
...@@ -275,8 +275,8 @@ void BackgroundFetchManager::DidLoadIcons( ...@@ -275,8 +275,8 @@ void BackgroundFetchManager::DidLoadIcons(
Vector<WebServiceWorkerRequest> web_requests, Vector<WebServiceWorkerRequest> web_requests,
const BackgroundFetchOptions& options, const BackgroundFetchOptions& options,
ScriptPromiseResolver* resolver, ScriptPromiseResolver* resolver,
const SkBitmap& bitmap) { const SkBitmap& icon) {
bridge_->Fetch(id, std::move(web_requests), options, bridge_->Fetch(id, std::move(web_requests), options, icon,
WTF::Bind(&BackgroundFetchManager::DidFetch, WTF::Bind(&BackgroundFetchManager::DidFetch,
WrapPersistent(this), WrapPersistent(resolver))); WrapPersistent(this), WrapPersistent(resolver)));
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
module blink.mojom; module blink.mojom;
import "skia/public/interfaces/bitmap.mojom";
import "third_party/WebKit/public/platform/modules/fetch/fetch_api_request.mojom"; import "third_party/WebKit/public/platform/modules/fetch/fetch_api_request.mojom";
enum BackgroundFetchError { enum BackgroundFetchError {
...@@ -59,13 +60,17 @@ interface BackgroundFetchRegistrationObserver { ...@@ -59,13 +60,17 @@ interface BackgroundFetchRegistrationObserver {
uint64 downloaded); uint64 downloaded);
}; };
// Interface for Background Fetch tasks. Lives in the browser process.
// Implements Background Fetch over Mojo IPC RFC.
interface BackgroundFetchService { interface BackgroundFetchService {
// Creates a new Background Fetch registration identified to the developer by // Creates a new Background Fetch registration identified to the developer by
// |developer_id|, with the given |options| for the sequence of |requests|. // |developer_id|, with the given |options| for the sequence of |requests|.
// Also passed along the |icon| to display.
Fetch(int64 service_worker_registration_id, Fetch(int64 service_worker_registration_id,
string developer_id, string developer_id,
array<FetchAPIRequest> requests, array<FetchAPIRequest> requests,
BackgroundFetchOptions options) BackgroundFetchOptions options,
skia.mojom.Bitmap? icon)
=> (BackgroundFetchError error, => (BackgroundFetchError error,
BackgroundFetchRegistration? registration); BackgroundFetchRegistration? registration);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment