Skip to content

Commit

Permalink
Rename tag to id in BackgroundFetchRegistration
Browse files Browse the repository at this point in the history
Matches recent change to spec:
WICG/background-fetch@15dd317

Bug: 752946
Change-Id: I4065564d79dd8a0d7aad5c7f49f6d87288e3b4f5
Reviewed-on: https://chromium-review.googlesource.com/603654
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Tsuyoshi Horo <horo@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#492924}
  • Loading branch information
danelphick authored and Commit Bot committed Aug 9, 2017
1 parent 6cd011a commit d5ae7f8
Show file tree
Hide file tree
Showing 61 changed files with 388 additions and 391 deletions.
12 changes: 6 additions & 6 deletions content/browser/background_fetch/background_fetch_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void BackgroundFetchContext::DidCreateRegistration(
// Create the BackgroundFetchRegistration the renderer process will receive,
// which enables it to resolve the promise telling the developer it worked.
BackgroundFetchRegistration registration;
registration.tag = registration_id.tag();
registration.id = registration_id.id();
registration.icons = options.icons;
registration.title = options.title;
registration.total_download_size = options.total_download_size;
Expand All @@ -104,25 +104,25 @@ void BackgroundFetchContext::DidCreateRegistration(
}

std::vector<std::string>
BackgroundFetchContext::GetActiveTagsForServiceWorkerRegistration(
BackgroundFetchContext::GetActiveIdsForServiceWorkerRegistration(
int64_t service_worker_registration_id,
const url::Origin& origin) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

std::vector<std::string> tags;
std::vector<std::string> ids;
for (const auto& pair : active_fetches_) {
const BackgroundFetchRegistrationId& registration_id =
pair.second->registration_id();

// Only return the tags when the origin and SW registration id match.
// Only return the ids when the origin and SW registration id match.
if (registration_id.origin() == origin &&
registration_id.service_worker_registration_id() ==
service_worker_registration_id) {
tags.push_back(pair.second->registration_id().tag());
ids.push_back(pair.second->registration_id().id());
}
}

return tags;
return ids;
}

BackgroundFetchJobController* BackgroundFetchContext::GetActiveFetch(
Expand Down
4 changes: 2 additions & 2 deletions content/browser/background_fetch/background_fetch_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class CONTENT_EXPORT BackgroundFetchContext
const BackgroundFetchOptions& options,
blink::mojom::BackgroundFetchService::FetchCallback callback);

// Returns a vector with the tags of the active fetches for the given |origin|
// Returns a vector with the ids of the active fetches for the given |origin|
// and |service_worker_registration_id|.
std::vector<std::string> GetActiveTagsForServiceWorkerRegistration(
std::vector<std::string> GetActiveIdsForServiceWorkerRegistration(
int64_t service_worker_registration_id,
const url::Origin& origin) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void BackgroundFetchDataManager::CreateRegistration(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

if (registrations_.find(registration_id) != registrations_.end()) {
std::move(callback).Run(blink::mojom::BackgroundFetchError::DUPLICATED_TAG);
std::move(callback).Run(blink::mojom::BackgroundFetchError::DUPLICATED_ID);
return;
}

Expand Down Expand Up @@ -293,7 +293,7 @@ void BackgroundFetchDataManager::DeleteRegistration(

auto iter = registrations_.find(registration_id);
if (iter == registrations_.end()) {
std::move(callback).Run(blink::mojom::BackgroundFetchError::INVALID_TAG);
std::move(callback).Run(blink::mojom::BackgroundFetchError::INVALID_ID);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace content {
namespace {

const char kExampleTag[] = "my-example-tag";
const char kExampleId[] = "my-example-id";

} // namespace

Expand Down Expand Up @@ -87,7 +87,7 @@ TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) {
// registration that's already known to the system.

BackgroundFetchRegistrationId registration_id;
ASSERT_TRUE(CreateRegistrationId(kExampleTag, &registration_id));
ASSERT_TRUE(CreateRegistrationId(kExampleId, &registration_id));

std::vector<ServiceWorkerFetchRequest> requests;
BackgroundFetchOptions options;
Expand All @@ -96,7 +96,7 @@ TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) {

// Deleting the not-yet-created registration should fail.
ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error));
EXPECT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_TAG);
EXPECT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ID);

// Creating the initial registration should succeed.
ASSERT_NO_FATAL_FAILURE(
Expand All @@ -106,7 +106,7 @@ TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) {
// Attempting to create it again should yield an error.
ASSERT_NO_FATAL_FAILURE(
CreateRegistration(registration_id, requests, options, &error));
EXPECT_EQ(error, blink::mojom::BackgroundFetchError::DUPLICATED_TAG);
EXPECT_EQ(error, blink::mojom::BackgroundFetchError::DUPLICATED_ID);

// Deleting the registration should succeed.
ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ BackgroundFetchEmbeddedWorkerTestHelper::
~BackgroundFetchEmbeddedWorkerTestHelper() = default;

void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent(
const std::string& tag,
const std::string& id,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback) {
last_tag_ = tag;
last_id_ = id;

if (fail_abort_event_) {
std::move(callback).Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
Expand All @@ -37,11 +37,11 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent(
}

void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
const std::string& tag,
const std::string& id,
mojom::BackgroundFetchState state,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchClickEventCallback callback) {
last_tag_ = tag;
last_id_ = id;
last_state_ = state;

if (fail_click_event_) {
Expand All @@ -56,11 +56,11 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
}

void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
const std::string& tag,
const std::string& id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback) {
last_tag_ = tag;
last_id_ = id;
last_fetches_ = fetches;

if (fail_fetch_fail_event_) {
Expand All @@ -75,11 +75,11 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
}

void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchedEvent(
const std::string& tag,
const std::string& id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::DispatchBackgroundFetchedEventCallback
callback) {
last_tag_ = tag;
last_id_ = id;
last_fetches_ = fetches;

if (fail_fetched_event_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BackgroundFetchEmbeddedWorkerTestHelper
fetched_event_closure_ = closure;
}

const base::Optional<std::string>& last_tag() const { return last_tag_; }
const base::Optional<std::string>& last_id() const { return last_id_; }
const base::Optional<mojom::BackgroundFetchState>& last_state() const {
return last_state_;
}
Expand All @@ -62,21 +62,21 @@ class BackgroundFetchEmbeddedWorkerTestHelper
protected:
// EmbeddedWorkerTestHelper overrides:
void OnBackgroundFetchAbortEvent(
const std::string& tag,
const std::string& id,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback) override;
void OnBackgroundFetchClickEvent(
const std::string& tag,
const std::string& id,
mojom::BackgroundFetchState state,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchClickEventCallback callback) override;
void OnBackgroundFetchFailEvent(
const std::string& tag,
const std::string& id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback) override;
void OnBackgroundFetchedEvent(
const std::string& tag,
const std::string& id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchedEventCallback callback) override;
Expand All @@ -92,7 +92,7 @@ class BackgroundFetchEmbeddedWorkerTestHelper
base::Closure fetch_fail_event_closure_;
base::Closure fetched_event_closure_;

base::Optional<std::string> last_tag_;
base::Optional<std::string> last_id_;
base::Optional<mojom::BackgroundFetchState> last_state_;
base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ void BackgroundFetchEventDispatcher::DispatchBackgroundFetchAbortEvent(
std::move(finished_closure),
base::Bind(
&BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchAbortEvent,
registration_id.tag()));
registration_id.id()));
}

void BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchAbortEvent(
const std::string& tag,
const std::string& id,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id) {
DCHECK(service_worker_version);
service_worker_version->event_dispatcher()->DispatchBackgroundFetchAbortEvent(
tag, service_worker_version->CreateSimpleEventCallback(request_id));
id, service_worker_version->CreateSimpleEventCallback(request_id));
}

void BackgroundFetchEventDispatcher::DispatchBackgroundFetchClickEvent(
Expand All @@ -105,18 +105,17 @@ void BackgroundFetchEventDispatcher::DispatchBackgroundFetchClickEvent(
std::move(finished_closure),
base::Bind(
&BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchClickEvent,
registration_id.tag(), state));
registration_id.id(), state));
}

void BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchClickEvent(
const std::string& tag,
const std::string& id,
mojom::BackgroundFetchState state,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id) {
DCHECK(service_worker_version);
service_worker_version->event_dispatcher()->DispatchBackgroundFetchClickEvent(
tag, state,
service_worker_version->CreateSimpleEventCallback(request_id));
id, state, service_worker_version->CreateSimpleEventCallback(request_id));
}

void BackgroundFetchEventDispatcher::DispatchBackgroundFetchFailEvent(
Expand All @@ -129,17 +128,17 @@ void BackgroundFetchEventDispatcher::DispatchBackgroundFetchFailEvent(
std::move(finished_closure),
base::Bind(
&BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchFailEvent,
registration_id.tag(), fetches));
registration_id.id(), fetches));
}

void BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchFailEvent(
const std::string& tag,
const std::string& id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id) {
DCHECK(service_worker_version);
service_worker_version->event_dispatcher()->DispatchBackgroundFetchFailEvent(
tag, fetches,
id, fetches,
service_worker_version->CreateSimpleEventCallback(request_id));
}

Expand All @@ -153,17 +152,17 @@ void BackgroundFetchEventDispatcher::DispatchBackgroundFetchedEvent(
std::move(finished_closure),
base::Bind(
&BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchedEvent,
registration_id.tag(), fetches));
registration_id.id(), fetches));
}

void BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchedEvent(
const std::string& tag,
const std::string& id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id) {
DCHECK(service_worker_version);
service_worker_version->event_dispatcher()->DispatchBackgroundFetchedEvent(
tag, fetches,
id, fetches,
service_worker_version->CreateSimpleEventCallback(request_id));
}

Expand Down
Loading

0 comments on commit d5ae7f8

Please sign in to comment.