Commit 5c0e4242 authored by Alexandr Ilin's avatar Alexandr Ilin Committed by Commit Bot

predictors: Remove several new statements and raw pointer usages

There is a crash registered in AutocompleteActionPredictorTable::GetAllRows
probably due to null pointer access. Culprit object is created with raw
new that may be dangerous. This CL removes this and several other usages
of a new statement in c/b/predictors.

Bug: 771616
Change-Id: I30e87b470e623166d03c27694f232a5033b143bf
Reviewed-on: https://chromium-review.googlesource.com/700636
Commit-Queue: Alexandr Ilin <alexilin@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506398}
parent 429dbdc5
......@@ -324,14 +324,15 @@ void AutocompleteActionPredictor::CreateLocalCachesFromDatabase() {
// Create local caches using the database as loaded. We will garbage collect
// rows from the caches and the database once the history service is
// available.
std::vector<AutocompleteActionPredictorTable::Row>* rows =
new std::vector<AutocompleteActionPredictorTable::Row>();
auto rows =
std::make_unique<std::vector<AutocompleteActionPredictorTable::Row>>();
auto* rows_ptr = rows.get();
table_->GetTaskRunner()->PostTaskAndReply(
FROM_HERE,
base::BindOnce(&AutocompleteActionPredictorTable::GetAllRows, table_,
rows),
rows_ptr),
base::BindOnce(&AutocompleteActionPredictor::CreateCaches, AsWeakPtr(),
base::Owned(rows)));
std::move(rows)));
}
void AutocompleteActionPredictor::DeleteAllRows() {
......@@ -422,7 +423,7 @@ void AutocompleteActionPredictor::AddAndUpdateRows(
}
void AutocompleteActionPredictor::CreateCaches(
std::vector<AutocompleteActionPredictorTable::Row>* rows) {
std::unique_ptr<std::vector<AutocompleteActionPredictorTable::Row>> rows) {
CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK(!profile_->IsOffTheRecord());
DCHECK(!initialized_);
......
......@@ -187,7 +187,7 @@ class AutocompleteActionPredictor
// if the history service is available, or registers for the notification of
// it becoming available.
void CreateCaches(
std::vector<AutocompleteActionPredictorTable::Row>* row_buffer);
std::unique_ptr<std::vector<AutocompleteActionPredictorTable::Row>> rows);
// Attempts to call DeleteOldEntries if the in-memory database has been loaded
// by |service|.
......
......@@ -74,7 +74,7 @@ class PreconnectManagerTest : public testing::Test {
PreconnectManagerTest::PreconnectManagerTest()
: mock_delegate_(
base::MakeUnique<StrictMock<MockPreconnectManagerDelegate>>()),
context_getter_(new net::TestURLRequestContextGetter(
context_getter_(base::MakeRefCounted<net::TestURLRequestContextGetter>(
base::ThreadTaskRunnerHandle::Get())),
preconnect_manager_(base::MakeUnique<StrictMock<MockPreconnectManager>>(
mock_delegate_->AsWeakPtr(),
......
......@@ -62,6 +62,7 @@ void InitializeOriginStatFromOriginRequestSummary(
// Used to fetch the visit count for a URL from the History database.
class GetUrlVisitCountTask : public history::HistoryDBTask {
public:
~GetUrlVisitCountTask() override;
typedef base::OnceCallback<void(size_t, // URL visit count.
const PageRequestSummary&)>
VisitInfoCallback;
......@@ -75,8 +76,6 @@ class GetUrlVisitCountTask : public history::HistoryDBTask {
void DoneRunOnMainThread() override;
private:
~GetUrlVisitCountTask() override;
int visit_count_;
std::unique_ptr<PageRequestSummary> summary_;
VisitInfoCallback callback_;
......@@ -287,10 +286,10 @@ void ResourcePrefetchPredictor::RecordPageRequestSummary(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
DCHECK(history_service);
history_service->ScheduleDBTask(
std::unique_ptr<history::HistoryDBTask>(new GetUrlVisitCountTask(
std::make_unique<GetUrlVisitCountTask>(
std::move(summary),
base::BindOnce(&ResourcePrefetchPredictor::OnVisitCountLookup,
weak_factory_.GetWeakPtr()))),
weak_factory_.GetWeakPtr())),
&history_lookup_consumer_);
} else {
// We won't record the URL data anyway so avoid the hop to the history
......
......@@ -181,9 +181,10 @@ class ResourcePrefetchPredictorTest : public testing::Test {
ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest()
: profile_(base::MakeUnique<TestingProfile>()),
db_task_runner_(new base::TestSimpleTaskRunner()),
mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>(
db_task_runner_)) {}
db_task_runner_(base::MakeRefCounted<base::TestSimpleTaskRunner>()),
mock_tables_(
base::MakeRefCounted<StrictMock<MockResourcePrefetchPredictorTables>>(
db_task_runner_)) {}
ResourcePrefetchPredictorTest::~ResourcePrefetchPredictorTest() = default;
......
......@@ -233,8 +233,7 @@ void ResourcePrefetcher::FinishRequest(net::URLRequest* request) {
void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) {
int bytes_read = 0;
do {
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(
kResourceBufferSizeBytes));
auto buffer = base::MakeRefCounted<net::IOBuffer>(kResourceBufferSizeBytes);
bytes_read = request->Read(buffer.get(), kResourceBufferSizeBytes);
if (bytes_read == net::ERR_IO_PENDING) {
return;
......
......@@ -158,7 +158,7 @@ class ResourcePrefetcherTest : public testing::Test {
ResourcePrefetcherTest::ResourcePrefetcherTest()
: prefetcher_delegate_(),
context_getter_(new net::TestURLRequestContextGetter(
context_getter_(base::MakeRefCounted<net::TestURLRequestContextGetter>(
base::ThreadTaskRunnerHandle::Get())) {}
ResourcePrefetcherTest::~ResourcePrefetcherTest() {
......
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