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 @@
#include "base/logging.h"
#include "base/run_loop.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/offline_items_collection/offline_content_aggregator_factory.h"
#include "chrome/browser/profiles/profile.h"
......@@ -32,6 +33,7 @@ using offline_items_collection::OfflineContentProvider;
using offline_items_collection::OfflineItem;
using offline_items_collection::OfflineItemFilter;
using offline_items_collection::OfflineItemProgressUnit;
using offline_items_collection::OfflineItemVisuals;
namespace {
......@@ -190,6 +192,21 @@ class BackgroundFetchBrowserTest : public InProcessBrowserTest {
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.
......@@ -243,6 +260,14 @@ class BackgroundFetchBrowserTest : public InProcessBrowserTest {
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_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchBrowserTest);
......@@ -296,4 +321,42 @@ IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
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
......@@ -19,6 +19,8 @@
#include "components/offline_items_collection/core/offline_item.h"
#include "content/public/browser/background_fetch_response.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)
: download_service_(
......@@ -45,10 +47,12 @@ BackgroundFetchDelegateImpl::JobDetails::JobDetails(
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts)
: title(title),
origin(origin),
icon(gfx::ImageSkia::CreateFrom1xBitmap(icon)),
completed_parts(completed_parts),
total_parts(total_parts),
cancelled(false),
......@@ -90,6 +94,7 @@ void BackgroundFetchDelegateImpl::CreateDownloadJob(
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts,
const std::vector<std::string>& current_guids) {
......@@ -98,8 +103,8 @@ void BackgroundFetchDelegateImpl::CreateDownloadJob(
DCHECK(!job_details_map_.count(job_unique_id));
auto emplace_result = job_details_map_.emplace(
job_unique_id,
JobDetails(job_unique_id, title, origin, completed_parts, total_parts));
job_unique_id, JobDetails(job_unique_id, title, origin, icon,
completed_parts, total_parts));
const JobDetails& details = emplace_result.first->second;
......@@ -419,9 +424,15 @@ void BackgroundFetchDelegateImpl::GetVisualsForItem(
const VisualsCallback& callback) {
// 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.
// 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(
FROM_HERE, base::BindOnce(callback, id, nullptr));
FROM_HERE, base::BindOnce(callback, id, std::move(visuals)));
}
void BackgroundFetchDelegateImpl::AddObserver(Observer* observer) {
......
......@@ -18,9 +18,11 @@
#include "components/offline_items_collection/core/offline_content_provider.h"
#include "components/offline_items_collection/core/offline_item.h"
#include "content/public/browser/background_fetch_delegate.h"
#include "ui/gfx/image/image.h"
#include "url/origin.h"
class Profile;
class SkBitmap;
namespace download {
class DownloadService;
......@@ -50,6 +52,7 @@ class BackgroundFetchDelegateImpl
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts,
const std::vector<std::string>& current_guids) override;
......@@ -98,6 +101,7 @@ class BackgroundFetchDelegateImpl
JobDetails(const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts);
~JobDetails();
......@@ -106,6 +110,7 @@ class BackgroundFetchDelegateImpl
std::string title;
const url::Origin origin;
gfx::Image icon;
int completed_parts;
const int total_parts;
bool cancelled;
......
......@@ -15,7 +15,13 @@ function RegisterServiceWorker() {
function StartSingleFileDownload() {
navigator.serviceWorker.ready.then(swRegistration => {
const options = {
// TODO(nator): Provide an icon here.
icons: [
{
src: '/notifications/icon.png',
sizes: '100x100',
type: 'image/png'
}
],
title: 'Single-file Background Fetch'
};
......
......@@ -37,14 +37,16 @@ ContentId JNI_OfflineContentAggregatorBridge_CreateContentId(
ConvertJavaStringToUTF8(env, j_id));
}
void GetVisualsForItemHelperCallback(ScopedJavaGlobalRef<jobject> j_callback,
const ContentId& id,
const OfflineItemVisuals* visuals) {
void GetVisualsForItemHelperCallback(
ScopedJavaGlobalRef<jobject> j_callback,
const ContentId& id,
std::unique_ptr<OfflineItemVisuals> visuals) {
JNIEnv* env = AttachCurrentThread();
Java_OfflineContentAggregatorBridge_onVisualsAvailable(
env, j_callback, ConvertUTF8ToJavaString(env, id.name_space),
ConvertUTF8ToJavaString(env, id.id),
OfflineItemVisualsBridge::CreateOfflineItemVisuals(env, visuals));
OfflineItemVisualsBridge::CreateOfflineItemVisuals(env,
std::move(visuals)));
}
void RunGetAllItemsCallback(const base::android::JavaRef<jobject>& j_callback,
......
......@@ -17,7 +17,7 @@ namespace android {
// static
ScopedJavaLocalRef<jobject> OfflineItemVisualsBridge::CreateOfflineItemVisuals(
JNIEnv* env,
const OfflineItemVisuals* const visuals) {
std::unique_ptr<OfflineItemVisuals> const visuals) {
if (!visuals)
return nullptr;
......
......@@ -23,7 +23,7 @@ class OfflineItemVisualsBridge {
// Creates a Java OfflineItemVisuals from |visuals|.
static base::android::ScopedJavaLocalRef<jobject> CreateOfflineItemVisuals(
JNIEnv* env,
const OfflineItemVisuals* const visuals);
std::unique_ptr<OfflineItemVisuals> visuals);
private:
OfflineItemVisualsBridge();
......
......@@ -24,7 +24,8 @@ class OfflineContentProvider {
public:
using OfflineItemList = std::vector<OfflineItem>;
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 SingleItemCallback =
base::OnceCallback<void(const base::Optional<OfflineItem>&)>;
......
......@@ -103,19 +103,21 @@ void BackgroundFetchContext::StartFetch(
const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
data_manager_.CreateRegistration(
registration_id, requests, options,
registration_id, requests, options, icon,
base::BindOnce(&BackgroundFetchContext::DidCreateRegistration,
weak_factory_.GetWeakPtr(), registration_id, options,
weak_factory_.GetWeakPtr(), registration_id, options, icon,
std::move(callback)));
}
void BackgroundFetchContext::DidCreateRegistration(
const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback,
blink::mojom::BackgroundFetchError error,
std::unique_ptr<BackgroundFetchRegistration> registration) {
......@@ -129,7 +131,7 @@ void BackgroundFetchContext::DidCreateRegistration(
DCHECK(registration);
// 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());
}
......@@ -180,11 +182,12 @@ void BackgroundFetchContext::DidUpdateStoredUI(
void BackgroundFetchContext::CreateController(
const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
const BackgroundFetchRegistration& registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
auto controller = std::make_unique<BackgroundFetchJobController>(
&delegate_proxy_, registration_id, options, registration,
&delegate_proxy_, registration_id, options, icon, registration,
scheduler_.get(),
// Safe because JobControllers are destroyed before RegistrationNotifier.
base::BindRepeating(&BackgroundFetchRegistrationNotifier::Notify,
......
......@@ -71,6 +71,7 @@ class CONTENT_EXPORT BackgroundFetchContext
void StartFetch(const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback);
// Aborts the Background Fetch for the |registration_id|. The callback will be
......@@ -106,6 +107,7 @@ class CONTENT_EXPORT BackgroundFetchContext
// 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 BackgroundFetchRegistration& registration);
// Called when an existing registration has been retrieved from the data
......@@ -119,6 +121,7 @@ class CONTENT_EXPORT BackgroundFetchContext
void DidCreateRegistration(
const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchService::FetchCallback callback,
blink::mojom::BackgroundFetchError error,
std::unique_ptr<BackgroundFetchRegistration> registration);
......
......@@ -51,8 +51,9 @@ class BackgroundFetchDataManager::RegistrationData {
public:
RegistrationData(const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options)
: registration_id_(registration_id), options_(options) {
const BackgroundFetchOptions& options,
const SkBitmap& icon)
: registration_id_(registration_id), options_(options), icon_(icon) {
int request_index = 0;
// Convert the given |requests| to BackgroundFetchRequestInfo objects.
......@@ -124,6 +125,7 @@ class BackgroundFetchDataManager::RegistrationData {
private:
BackgroundFetchRegistrationId registration_id_;
BackgroundFetchOptions options_;
SkBitmap icon_;
// Number of bytes downloaded as part of completed downloads. (In-progress
// downloads are tracked elsewhere).
uint64_t complete_requests_downloaded_bytes_ = 0;
......@@ -178,6 +180,7 @@ void BackgroundFetchDataManager::CreateRegistration(
const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
GetRegistrationCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
......@@ -207,9 +210,9 @@ void BackgroundFetchDataManager::CreateRegistration(
registration_id.unique_id());
// Create the |RegistrationData|, and store it for easy access.
registrations_.emplace(
registration_id.unique_id(),
std::make_unique<RegistrationData>(registration_id, requests, options));
registrations_.emplace(registration_id.unique_id(),
std::make_unique<RegistrationData>(
registration_id, requests, options, icon));
// Re-use GetRegistration to compile the BackgroundFetchRegistration object.
// WARNING: GetRegistration doesn't use the |unique_id| when looking up the
......
......@@ -73,6 +73,7 @@ class CONTENT_EXPORT BackgroundFetchDataManager
const BackgroundFetchRegistrationId& registration_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
GetRegistrationCallback callback);
// Get the BackgroundFetchOptions for a registration.
......
......@@ -116,7 +116,7 @@ class BackgroundFetchDataManagerTest
base::RunLoop run_loop;
background_fetch_data_manager_->CreateRegistration(
registration_id, requests, options,
registration_id, requests, options, SkBitmap(),
base::BindOnce(&DidCreateRegistration, run_loop.QuitClosure(),
out_error));
run_loop.Run();
......@@ -545,7 +545,7 @@ TEST_P(BackgroundFetchDataManagerTest, CreateInParallel) {
base::GenerateGUID());
background_fetch_data_manager_->CreateRegistration(
registration_id, requests, options,
registration_id, requests, options, SkBitmap(),
base::BindOnce(&DidCreateRegistration, quit_once_all_finished_closure,
&errors[i]));
}
......
......@@ -14,6 +14,8 @@
#include "content/public/browser/background_fetch_response.h"
#include "content/public/browser/download_manager.h"
class SkBitmap;
namespace content {
// Internal functionality of the BackgroundFetchDelegateProxy that lives on the
......@@ -42,13 +44,14 @@ class BackgroundFetchDelegateProxy::Core
void CreateDownloadJob(const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts,
const std::vector<std::string>& current_guids) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (delegate_) {
delegate_->CreateDownloadJob(job_unique_id, title, origin,
delegate_->CreateDownloadJob(job_unique_id, title, origin, icon,
completed_parts, total_parts, current_guids);
}
}
......@@ -231,6 +234,7 @@ void BackgroundFetchDelegateProxy::CreateDownloadJob(
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
base::WeakPtr<Controller> controller,
int completed_parts,
int total_parts,
......@@ -243,7 +247,7 @@ void BackgroundFetchDelegateProxy::CreateDownloadJob(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
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));
}
......
......@@ -18,6 +18,8 @@
#include "content/public/browser/background_fetch_response.h"
#include "content/public/browser/browser_thread.h"
class SkBitmap;
namespace content {
class BackgroundFetchDelegate;
......@@ -65,6 +67,7 @@ class CONTENT_EXPORT BackgroundFetchDelegateProxy {
void CreateDownloadJob(const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
base::WeakPtr<Controller> controller,
int completed_parts,
int total_parts,
......
......@@ -30,6 +30,7 @@ class FakeBackgroundFetchDelegate : public BackgroundFetchDelegate {
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts,
const std::vector<std::string>& current_guids) override {}
......@@ -140,9 +141,9 @@ TEST_F(BackgroundFetchDelegateProxyTest, StartRequest) {
EXPECT_FALSE(controller.request_started_);
EXPECT_FALSE(controller.request_completed_);
delegate_proxy_.CreateDownloadJob(kExampleUniqueId, "Job 1", url::Origin(),
controller.weak_ptr_factory_.GetWeakPtr(),
0, 1, {});
delegate_proxy_.CreateDownloadJob(
kExampleUniqueId, "Job 1", url::Origin(), SkBitmap(),
controller.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request);
base::RunLoop().RunUntilIdle();
......@@ -160,9 +161,9 @@ TEST_F(BackgroundFetchDelegateProxyTest, StartRequest_NotCompleted) {
EXPECT_FALSE(controller.request_completed_);
delegate_.set_complete_downloads(false);
delegate_proxy_.CreateDownloadJob(kExampleUniqueId, "Job 1", url::Origin(),
controller.weak_ptr_factory_.GetWeakPtr(),
0, 1, {});
delegate_proxy_.CreateDownloadJob(
kExampleUniqueId, "Job 1", url::Origin(), SkBitmap(),
controller.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request);
base::RunLoop().RunUntilIdle();
......@@ -184,13 +185,13 @@ TEST_F(BackgroundFetchDelegateProxyTest, Abort) {
EXPECT_FALSE(controller2.request_started_);
EXPECT_FALSE(controller2.request_completed_);
delegate_proxy_.CreateDownloadJob(kExampleUniqueId, "Job 1", url::Origin(),
controller.weak_ptr_factory_.GetWeakPtr(),
0, 1, {});
delegate_proxy_.CreateDownloadJob(
kExampleUniqueId, "Job 1", url::Origin(), SkBitmap(),
controller.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.CreateDownloadJob(kExampleUniqueId2, "Job 2", url::Origin(),
controller2.weak_ptr_factory_.GetWeakPtr(),
0, 1, {});
delegate_proxy_.CreateDownloadJob(
kExampleUniqueId2, "Job 2", url::Origin(), SkBitmap(),
controller2.weak_ptr_factory_.GetWeakPtr(), 0, 1, {});
delegate_proxy_.StartRequest(kExampleUniqueId, url::Origin(), request);
delegate_proxy_.StartRequest(kExampleUniqueId2, url::Origin(), request2);
......
......@@ -16,6 +16,7 @@ BackgroundFetchJobController::BackgroundFetchJobController(
BackgroundFetchDelegateProxy* delegate_proxy,
const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
const BackgroundFetchRegistration& registration,
BackgroundFetchRequestManager* request_manager,
ProgressCallback progress_callback,
......@@ -23,6 +24,7 @@ BackgroundFetchJobController::BackgroundFetchJobController(
: BackgroundFetchScheduler::Controller(registration_id,
std::move(finished_callback)),
options_(options),
icon_(icon),
complete_requests_downloaded_bytes_cache_(registration.downloaded),
request_manager_(request_manager),
delegate_proxy_(delegate_proxy),
......@@ -44,9 +46,10 @@ void BackgroundFetchJobController::InitializeRequestStatus(
completed_downloads_ = completed_downloads;
total_downloads_ = total_downloads;
delegate_proxy_->CreateDownloadJob(
registration_id().unique_id(), options_.title, registration_id().origin(),
GetWeakPtr(), completed_downloads, total_downloads, outstanding_guids);
delegate_proxy_->CreateDownloadJob(registration_id().unique_id(),
options_.title, registration_id().origin(),
icon_, GetWeakPtr(), completed_downloads,
total_downloads, outstanding_guids);
}
BackgroundFetchJobController::~BackgroundFetchJobController() {
......
......@@ -20,6 +20,7 @@
#include "content/common/background_fetch/background_fetch_types.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace content {
......@@ -49,6 +50,7 @@ class CONTENT_EXPORT BackgroundFetchJobController final
BackgroundFetchDelegateProxy* delegate_proxy,
const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
const BackgroundFetchRegistration& registration,
BackgroundFetchRequestManager* request_manager,
ProgressCallback progress_callback,
......@@ -102,6 +104,9 @@ class CONTENT_EXPORT BackgroundFetchJobController final
// Options for the represented background fetch registration.
BackgroundFetchOptions options_;
// Icon for the represented background fetch registration.
SkBitmap icon_;
// Map from in-progress |download_guid|s to number of bytes downloaded.
base::flat_map<std::string, uint64_t> active_request_download_bytes_;
......
......@@ -156,7 +156,7 @@ class BackgroundFetchJobControllerTest : public BackgroundFetchTestBase {
auto controller = std::make_unique<BackgroundFetchJobController>(
delegate_proxy_.get(), registration_id, BackgroundFetchOptions(),
registration, &request_manager_,
SkBitmap(), registration, &request_manager_,
base::BindRepeating(
&BackgroundFetchJobControllerTest::DidUpdateProgress,
base::Unretained(this)),
......
......@@ -73,6 +73,7 @@ void BackgroundFetchServiceImpl::Fetch(
const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!ValidateDeveloperId(developer_id)) {
......@@ -96,7 +97,7 @@ void BackgroundFetchServiceImpl::Fetch(
base::GenerateGUID());
background_fetch_context_->StartFetch(registration_id, requests, options,
std::move(callback));
icon, std::move(callback));
}
void BackgroundFetchServiceImpl::UpdateUI(const std::string& unique_id,
......
......@@ -40,6 +40,7 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
FetchCallback callback) override;
void UpdateUI(const std::string& unique_id,
const std::string& title,
......
......@@ -93,6 +93,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchError* out_error,
BackgroundFetchRegistration* out_registration) {
DCHECK(out_error);
......@@ -100,7 +101,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
base::RunLoop run_loop;
service_->Fetch(
service_worker_registration_id, developer_id, requests, options,
service_worker_registration_id, developer_id, requests, options, icon,
base::BindOnce(&BackgroundFetchServiceTest::DidGetRegistration,
base::Unretained(this), run_loop.QuitClosure(),
out_error, out_registration));
......@@ -258,7 +259,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) {
BackgroundFetchRegistration registration;
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);
EXPECT_EQ("Invalid developer_id", bad_message_observer.last_error());
}
......@@ -273,7 +274,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) {
BackgroundFetchRegistration registration;
Fetch(42 /* service_worker_registration_id */, kExampleDeveloperId,
requests, options, &error, &registration);
requests, options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT);
EXPECT_EQ("Invalid requests", bad_message_observer.last_error());
}
......@@ -301,7 +302,7 @@ TEST_F(BackgroundFetchServiceTest, FetchRegistrationProperties) {
BackgroundFetchRegistration registration;
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options,
&error, &registration);
SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
// The |registration| should reflect the options given in |options|.
......@@ -341,7 +342,7 @@ TEST_F(BackgroundFetchServiceTest, FetchDuplicatedRegistrationFailure) {
// Create the first registration. This must succeed.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options,
&error, &registration);
SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
blink::mojom::BackgroundFetchError second_error;
......@@ -349,7 +350,7 @@ TEST_F(BackgroundFetchServiceTest, FetchDuplicatedRegistrationFailure) {
// Create the second registration with the same data. This must fail.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests, options,
&second_error, &second_registration);
SkBitmap(), &second_error, &second_registration);
ASSERT_EQ(second_error,
blink::mojom::BackgroundFetchError::DUPLICATED_DEVELOPER_ID);
}
......@@ -409,7 +410,7 @@ TEST_F(BackgroundFetchServiceTest, FetchSuccessEventDispatch) {
// Create the first registration. This must succeed.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration);
options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
}
......@@ -508,7 +509,7 @@ TEST_F(BackgroundFetchServiceTest, FetchFailEventDispatch) {
// Create the first registration. This must succeed.
Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration);
options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
}
......@@ -579,7 +580,7 @@ TEST_F(BackgroundFetchServiceTest, UpdateUI) {
// Create the registration.
BackgroundFetchRegistrationId registration_id =
Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration);
options, SkBitmap(), &error, &registration);
ASSERT_EQ(blink::mojom::BackgroundFetchError::NONE, error);
std::string second_title = "2nd title";
......@@ -615,7 +616,7 @@ TEST_F(BackgroundFetchServiceTest, Abort) {
// Create the registration. This must succeed.
BackgroundFetchRegistrationId registration_id =
Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration);
options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
blink::mojom::BackgroundFetchError abort_error;
......@@ -705,8 +706,9 @@ TEST_F(BackgroundFetchServiceTest, AbortEventDispatch) {
BackgroundFetchRegistration registration;
// Create the registration. This must succeed.
registration_id = Fetch(service_worker_registration_id, kExampleDeveloperId,
requests, options, &error, &registration);
registration_id =
Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
}
......@@ -751,7 +753,7 @@ TEST_F(BackgroundFetchServiceTest, UniqueId) {
BackgroundFetchRegistration aborted_registration;
BackgroundFetchRegistrationId aborted_registration_id =
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);
// Immediately abort the registration so it is no longer active (everything
......@@ -770,7 +772,7 @@ TEST_F(BackgroundFetchServiceTest, UniqueId) {
BackgroundFetchRegistration second_registration;
BackgroundFetchRegistrationId second_registration_id =
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);
// Now try to get the registration using its |developer_id|. This should
......@@ -865,7 +867,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
BackgroundFetchRegistration registration;
Fetch(service_worker_registration_id, kExampleDeveloperId, requests,
options, &error, &registration);
options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
}
......@@ -887,7 +889,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
BackgroundFetchRegistration registration;
Fetch(service_worker_registration_id, kAlternativeDeveloperId, requests,
options, &error, &registration);
options, SkBitmap(), &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
}
......
......@@ -59,6 +59,7 @@ void MockBackgroundFetchDelegate::CreateDownloadJob(
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts,
const std::vector<std::string>& current_guids) {}
......
......@@ -67,6 +67,7 @@ class MockBackgroundFetchDelegate : public BackgroundFetchDelegate {
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts,
const std::vector<std::string>& current_guids) override;
......
......@@ -15,6 +15,7 @@
#include "content/common/content_export.h"
class GURL;
class SkBitmap;
namespace net {
class HttpRequestHeaders;
......@@ -84,6 +85,7 @@ class CONTENT_EXPORT BackgroundFetchDelegate {
const std::string& job_unique_id,
const std::string& title,
const url::Origin& origin,
const SkBitmap& icon,
int completed_parts,
int total_parts,
const std::vector<std::string>& current_guids) = 0;
......
......@@ -44,10 +44,12 @@ BackgroundFetchBridge::~BackgroundFetchBridge() = default;
void BackgroundFetchBridge::Fetch(const String& developer_id,
Vector<WebServiceWorkerRequest> requests,
const BackgroundFetchOptions& options,
const SkBitmap& icon,
RegistrationCallback callback) {
GetService()->Fetch(
GetSupplementable()->WebRegistration()->RegistrationId(), developer_id,
std::move(requests), mojom::blink::BackgroundFetchOptions::From(options),
icon,
WTF::Bind(&BackgroundFetchBridge::DidGetRegistration,
WrapPersistent(this), WTF::Passed(std::move(callback))));
}
......
......@@ -53,6 +53,7 @@ class BackgroundFetchBridge final
void Fetch(const String& developer_id,
Vector<WebServiceWorkerRequest> requests,
const BackgroundFetchOptions&,
const SkBitmap& icon,
RegistrationCallback);
// Updates the user interface for the Background Fetch identified by
......
......@@ -275,8 +275,8 @@ void BackgroundFetchManager::DidLoadIcons(
Vector<WebServiceWorkerRequest> web_requests,
const BackgroundFetchOptions& options,
ScriptPromiseResolver* resolver,
const SkBitmap& bitmap) {
bridge_->Fetch(id, std::move(web_requests), options,
const SkBitmap& icon) {
bridge_->Fetch(id, std::move(web_requests), options, icon,
WTF::Bind(&BackgroundFetchManager::DidFetch,
WrapPersistent(this), WrapPersistent(resolver)));
}
......
......@@ -4,6 +4,7 @@
module blink.mojom;
import "skia/public/interfaces/bitmap.mojom";
import "third_party/WebKit/public/platform/modules/fetch/fetch_api_request.mojom";
enum BackgroundFetchError {
......@@ -59,13 +60,17 @@ interface BackgroundFetchRegistrationObserver {
uint64 downloaded);
};
// Interface for Background Fetch tasks. Lives in the browser process.
// Implements Background Fetch over Mojo IPC RFC.
interface BackgroundFetchService {
// Creates a new Background Fetch registration identified to the developer by
// |developer_id|, with the given |options| for the sequence of |requests|.
// Also passed along the |icon| to display.
Fetch(int64 service_worker_registration_id,
string developer_id,
array<FetchAPIRequest> requests,
BackgroundFetchOptions options)
BackgroundFetchOptions options,
skia.mojom.Bitmap? icon)
=> (BackgroundFetchError error,
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