Commit 794bf2c3 authored by Alexander Yashkin's avatar Alexander Yashkin Committed by Commit Bot

Fixed memory leak in tests.

This patch fixes memory leak in BrowsingHistoryServiceTest tests
detected by ASAN build. Also changed TestingProfile to use already
implemented and correct(non leaking) version of
BlockUntilHistoryProcessesPendingRequests.
Leaking object was QuittingHistoryDBTask which is created and
passed to ScheduleDBTask function of HistoryService. To delete
this object HistoryBackend posts DeletePoiner task back to original
loop in ~QueuedHistoryDBTask. Yet nobody processes this task in
tests and its leakage is catched by ASAN.
history::BlockUntilHistoryProcessesPendingRequests in
history_service_test_util.cc calls HistoryService::FlushForTest
which does not create any objects in heap and is leak safe.

Change-Id: I76040ab9f52656d4c92b874d24ba0bc514e6a031
Reviewed-on: https://chromium-review.googlesource.com/789112
Commit-Queue: Alexander Yashkin <a-v-y@yandex-team.ru>
Reviewed-by: default avatarBrett Wilson <brettw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519592}
parent 73ab6901
...@@ -65,8 +65,8 @@ ...@@ -65,8 +65,8 @@
#include "components/history/core/browser/history_backend.h" #include "components/history/core/browser/history_backend.h"
#include "components/history/core/browser/history_constants.h" #include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_database_params.h" #include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_service.h"
#include "components/history/core/test/history_service_test_util.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/offline_pages/features/features.h" #include "components/offline_pages/features/features.h"
...@@ -148,28 +148,6 @@ namespace { ...@@ -148,28 +148,6 @@ namespace {
// Default profile name // Default profile name
const char kTestingProfile[] = "testing_profile"; const char kTestingProfile[] = "testing_profile";
// Task used to make sure history has finished processing a request. Intended
// for use with BlockUntilHistoryProcessesPendingRequests.
class QuittingHistoryDBTask : public history::HistoryDBTask {
public:
QuittingHistoryDBTask() {}
bool RunOnDBThread(history::HistoryBackend* backend,
history::HistoryDatabase* db) override {
return true;
}
void DoneRunOnMainThread() override {
base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
private:
~QuittingHistoryDBTask() override {}
DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
};
class TestExtensionURLRequestContext : public net::URLRequestContext { class TestExtensionURLRequestContext : public net::URLRequestContext {
public: public:
TestExtensionURLRequestContext() { TestExtensionURLRequestContext() {
...@@ -925,13 +903,7 @@ void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { ...@@ -925,13 +903,7 @@ void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
HistoryServiceFactory::GetForProfile(this, HistoryServiceFactory::GetForProfile(this,
ServiceAccessType::EXPLICIT_ACCESS); ServiceAccessType::EXPLICIT_ACCESS);
DCHECK(history_service); DCHECK(history_service);
DCHECK(base::MessageLoop::current()); history::BlockUntilHistoryProcessesPendingRequests(history_service);
base::CancelableTaskTracker tracker;
history_service->ScheduleDBTask(
std::unique_ptr<history::HistoryDBTask>(new QuittingHistoryDBTask()),
&tracker);
base::RunLoop().Run();
} }
chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() { chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/timer/mock_timer.h" #include "base/timer/mock_timer.h"
#include "base/values.h" #include "base/values.h"
#include "components/history/core/browser/browsing_history_driver.h" #include "components/history/core/browser/browsing_history_driver.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_service.h"
#include "components/history/core/test/fake_web_history_service.h" #include "components/history/core/test/fake_web_history_service.h"
#include "components/history/core/test/history_service_test_util.h" #include "components/history/core/test/history_service_test_util.h"
...@@ -57,23 +56,6 @@ struct TestResult { ...@@ -57,23 +56,6 @@ struct TestResult {
// Used to bind a callback. // Used to bind a callback.
void DoNothing(bool ignored) {} void DoNothing(bool ignored) {}
class QuittingHistoryDBTask : public HistoryDBTask {
public:
explicit QuittingHistoryDBTask(base::OnceClosure done_closure)
: done_closure_(std::move(done_closure)) {}
// HistoryDBTask implementation.
bool RunOnDBThread(history::HistoryBackend* backend,
history::HistoryDatabase* db) override {
return true;
}
void DoneRunOnMainThread() override { std::move(done_closure_).Run(); }
private:
base::OnceClosure done_closure_;
DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
};
class TestSyncService : public syncer::FakeSyncService { class TestSyncService : public syncer::FakeSyncService {
public: public:
int GetObserverCount() { return observer_count_; } int GetObserverCount() { return observer_count_; }
...@@ -232,12 +214,7 @@ class BrowsingHistoryServiceTest : public ::testing::Test { ...@@ -232,12 +214,7 @@ class BrowsingHistoryServiceTest : public ::testing::Test {
} }
void BlockUntilHistoryProcessesPendingRequests() { void BlockUntilHistoryProcessesPendingRequests() {
base::CancelableTaskTracker tracker; history::BlockUntilHistoryProcessesPendingRequests(local_history());
base::RunLoop run_loop;
local_history_->ScheduleDBTask(
std::make_unique<QuittingHistoryDBTask>(run_loop.QuitWhenIdleClosure()),
&tracker);
run_loop.Run();
} }
Time OffsetToTime(int64_t hour_offset) { Time OffsetToTime(int64_t hour_offset) {
......
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