Skip to content

Commit

Permalink
[Background Fetch] Remove AddGarbageCollectionCallback.
Browse files Browse the repository at this point in the history
https://chromium-review.googlesource.com/c/chromium/src/+/1216066
removed the usage of AddGarbageCollectionCallback.
This CL removes the implementation + unit test.

Bug: 881885
Change-Id: I1d1b066b9596c1174ad4fafc46b057fbab322ff0
Reviewed-on: https://chromium-review.googlesource.com/1216068
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591684}
  • Loading branch information
Mugdha Lakhani authored and Commit Bot committed Sep 17, 2018
1 parent 08c20e4 commit 8cf0805
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "content/browser/background_fetch/background_fetch_registration_notifier.h"

#include "base/bind.h"
#include "base/stl_util.h"

namespace content {

Expand Down Expand Up @@ -55,15 +54,6 @@ void BackgroundFetchRegistrationNotifier::NotifyRecordsUnavailable(
}
}

void BackgroundFetchRegistrationNotifier::AddGarbageCollectionCallback(
const std::string& unique_id,
base::OnceClosure callback) {
if (!observers_.count(unique_id))
std::move(callback).Run();
else
garbage_collection_callbacks_.emplace(unique_id, std::move(callback));
}

void BackgroundFetchRegistrationNotifier::OnConnectionError(
const std::string& unique_id,
blink::mojom::BackgroundFetchRegistrationObserver* observer) {
Expand All @@ -72,13 +62,6 @@ void BackgroundFetchRegistrationNotifier::OnConnectionError(
[observer](const auto& unique_id_observer_ptr_pair) {
return unique_id_observer_ptr_pair.second.get() == observer;
});

auto callback_iter = garbage_collection_callbacks_.find(unique_id);
if (callback_iter != garbage_collection_callbacks_.end() &&
!observers_.count(unique_id)) {
std::move(callback_iter->second).Run();
garbage_collection_callbacks_.erase(callback_iter);
}
}

} // namespace content
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ class CONTENT_EXPORT BackgroundFetchRegistrationNotifier {
// |unique_id| that the records for the fetch are no longer available.
void NotifyRecordsUnavailable(const std::string& unique_id);

// Runs |callback| when the last observer for |unique_id| is removed, or
// immediately if there are already no observers. Callback will never be run
// if the browser is shutdown before the last observer is removed.
// TODO(crbug.com/881885): Delete this method + update unit tests.
void AddGarbageCollectionCallback(const std::string& unique_id,
base::OnceClosure callback);

base::WeakPtr<BackgroundFetchRegistrationNotifier> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
Expand All @@ -64,10 +57,6 @@ class CONTENT_EXPORT BackgroundFetchRegistrationNotifier {
blink::mojom::BackgroundFetchRegistrationObserverPtr>
observers_;

// Map from registration |unique_id| to callback to run when last observer is
// removed.
std::map<std::string, base::OnceClosure> garbage_collection_callbacks_;

base::WeakPtrFactory<BackgroundFetchRegistrationNotifier> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(BackgroundFetchRegistrationNotifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,12 @@ class BackgroundFetchRegistrationNotifierTest : public ::testing::Test {
task_runner_->RunUntilIdle();
}

void CollectGarbage() { garbage_collected_ = true; }

protected:
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::ThreadTaskRunnerHandle handle_;

std::unique_ptr<BackgroundFetchRegistrationNotifier> notifier_;

bool garbage_collected_ = false;

private:
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchRegistrationNotifierTest);
};
Expand Down Expand Up @@ -206,39 +202,6 @@ TEST_F(BackgroundFetchRegistrationNotifierTest, NotifyWithoutObservers) {
EXPECT_EQ(observer->progress_updates().size(), 0u);
}

TEST_F(BackgroundFetchRegistrationNotifierTest,
AddGarbageCollectionCallback_NoObservers) {
notifier_->AddGarbageCollectionCallback(
kPrimaryUniqueId,
base::BindOnce(&BackgroundFetchRegistrationNotifierTest::CollectGarbage,
base::Unretained(this)));

ASSERT_TRUE(garbage_collected_)
<< "Garbage should be collected when there are no observers";
}

TEST_F(BackgroundFetchRegistrationNotifierTest,
AddGarbageCollectionCallback_OneObserver) {
auto observer = std::make_unique<TestRegistrationObserver>();

auto foo = observer->GetPtr();
notifier_->AddObserver(kPrimaryUniqueId, std::move(foo));
notifier_->AddGarbageCollectionCallback(
kPrimaryUniqueId,
base::BindOnce(&BackgroundFetchRegistrationNotifierTest::CollectGarbage,
base::Unretained(this)));

ASSERT_FALSE(garbage_collected_)
<< "Garbage should not be collected when there is an observer";

observer->Close();

// TODO(crbug.com/777764): Add this back when non-exceptional binding closures
// are detected properly.
// ASSERT_TRUE(garbage_collected_) << "Garbage should be collected when the
// "observer is closed.";
}

TEST_F(BackgroundFetchRegistrationNotifierTest, NotifyRecordsUnavailable) {
auto observer = std::make_unique<TestRegistrationObserver>();

Expand Down

0 comments on commit 8cf0805

Please sign in to comment.