Skip to content

Commit

Permalink
Remove ScopedVector from DefaultChannelIDStore, SQLiteChannelIDStore …
Browse files Browse the repository at this point in the history
…and QuotaPolicyChannelIDStore.

BUG=554289

Review URL: https://codereview.chromium.org/1476263004

Cr-Commit-Position: refs/heads/master@{#362657}
  • Loading branch information
olli.raula authored and Commit bot committed Dec 2, 2015
1 parent 88176a2 commit 4464294
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 51 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/net/quota_policy_channel_id_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ void QuotaPolicyChannelIDStore::OnLoad(
++channel_id) {
server_identifiers_.insert((*channel_id)->server_identifier());
}
loaded_callback.Run(channel_ids.Pass());
loaded_callback.Run(std::move(channel_ids));
}
4 changes: 3 additions & 1 deletion chrome/browser/net/quota_policy_channel_id_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <set>
#include <string>
#include <vector>

#include "base/callback_forward.h"
#include "base/compiler_specific.h"
Expand Down Expand Up @@ -50,7 +51,8 @@ class QuotaPolicyChannelIDStore
void SetForceKeepSessionState() override;

private:
typedef ScopedVector<net::DefaultChannelIDStore::ChannelID> ChannelIDVector;
typedef std::vector<scoped_ptr<net::DefaultChannelIDStore::ChannelID>>
ChannelIDVector;

~QuotaPolicyChannelIDStore() override;

Expand Down
28 changes: 16 additions & 12 deletions chrome/browser/net/quota_policy_channel_id_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
Expand Down Expand Up @@ -29,7 +31,8 @@ const base::FilePath::CharType kTestChannelIDFilename[] =

class QuotaPolicyChannelIDStoreTest : public testing::Test {
public:
void Load(ScopedVector<net::DefaultChannelIDStore::ChannelID>* channel_ids) {
void Load(std::vector<scoped_ptr<net::DefaultChannelIDStore::ChannelID>>*
channel_ids) {
base::RunLoop run_loop;
store_->Load(base::Bind(&QuotaPolicyChannelIDStoreTest::OnLoaded,
base::Unretained(this),
Expand All @@ -39,9 +42,10 @@ class QuotaPolicyChannelIDStoreTest : public testing::Test {
channel_ids_.clear();
}

void OnLoaded(base::RunLoop* run_loop,
scoped_ptr<ScopedVector<net::DefaultChannelIDStore::ChannelID> >
channel_ids) {
void OnLoaded(
base::RunLoop* run_loop,
scoped_ptr<std::vector<scoped_ptr<net::DefaultChannelIDStore::ChannelID>>>
channel_ids) {
channel_ids_.swap(*channel_ids);
run_loop->Quit();
}
Expand All @@ -53,7 +57,7 @@ class QuotaPolicyChannelIDStoreTest : public testing::Test {
temp_dir_.path().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(),
NULL);
ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<net::DefaultChannelIDStore::ChannelID>> channel_ids;
Load(&channel_ids);
ASSERT_EQ(0u, channel_ids.size());
}
Expand All @@ -65,7 +69,7 @@ class QuotaPolicyChannelIDStoreTest : public testing::Test {

base::ScopedTempDir temp_dir_;
scoped_refptr<QuotaPolicyChannelIDStore> store_;
ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids_;
std::vector<scoped_ptr<net::DefaultChannelIDStore::ChannelID>> channel_ids_;
base::MessageLoop loop_;
};

Expand All @@ -80,7 +84,7 @@ TEST_F(QuotaPolicyChannelIDStoreTest, TestPersistence) {
"foo.com", base::Time::FromInternalValue(3),
make_scoped_ptr(foo_key->Copy())));

ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<net::DefaultChannelIDStore::ChannelID>> channel_ids;
// Replace the store effectively destroying the current one and forcing it
// to write its data to disk. Then we can see if after loading it again it
// is still there.
Expand All @@ -98,11 +102,11 @@ TEST_F(QuotaPolicyChannelIDStoreTest, TestPersistence) {
net::DefaultChannelIDStore::ChannelID* goog_channel_id;
net::DefaultChannelIDStore::ChannelID* foo_channel_id;
if (channel_ids[0]->server_identifier() == "google.com") {
goog_channel_id = channel_ids[0];
foo_channel_id = channel_ids[1];
goog_channel_id = channel_ids[0].get();
foo_channel_id = channel_ids[1].get();
} else {
goog_channel_id = channel_ids[1];
foo_channel_id = channel_ids[0];
goog_channel_id = channel_ids[1].get();
foo_channel_id = channel_ids[0].get();
}
ASSERT_EQ("google.com", goog_channel_id->server_identifier());
EXPECT_TRUE(net::KeysEqual(goog_key.get(), goog_channel_id->key()));
Expand Down Expand Up @@ -137,7 +141,7 @@ TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) {
"nonpersistent.com", base::Time::FromInternalValue(3),
make_scoped_ptr(crypto::ECPrivateKey::Create())));

ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<net::DefaultChannelIDStore::ChannelID>> channel_ids;
// Replace the store effectively destroying the current one and forcing it
// to write its data to disk. Then we can see if after loading it again it
// is still there.
Expand Down
15 changes: 8 additions & 7 deletions net/extras/sqlite/sqlite_channel_id_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "net/extras/sqlite/sqlite_channel_id_store.h"

#include <set>
#include <vector>

#include "base/basictypes.h"
#include "base/bind.h"
Expand All @@ -13,7 +14,6 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -82,7 +82,7 @@ class SQLiteChannelIDStore::Backend
}

void LoadInBackground(
ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids);
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids);

// Database upgrade statements.
bool EnsureDatabaseVersion();
Expand Down Expand Up @@ -148,9 +148,10 @@ void SQLiteChannelIDStore::Backend::Load(
const LoadedCallback& loaded_callback) {
// This function should be called only once per instance.
DCHECK(!db_.get());
scoped_ptr<ScopedVector<DefaultChannelIDStore::ChannelID> > channel_ids(
new ScopedVector<DefaultChannelIDStore::ChannelID>());
ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids_ptr =
scoped_ptr<std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>>
channel_ids(
new std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>());
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids_ptr =
channel_ids.get();

background_task_runner_->PostTaskAndReply(
Expand All @@ -160,7 +161,7 @@ void SQLiteChannelIDStore::Backend::Load(
}

void SQLiteChannelIDStore::Backend::LoadInBackground(
ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids) {
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids) {
DCHECK(background_task_runner_->RunsTasksOnCurrentThread());

// This method should be called only once per instance.
Expand Down Expand Up @@ -230,7 +231,7 @@ void SQLiteChannelIDStore::Backend::LoadInBackground(
new DefaultChannelIDStore::ChannelID(
smt.ColumnString(0), // host
base::Time::FromInternalValue(smt.ColumnInt64(3)), key.Pass()));
channel_ids->push_back(channel_id.release());
channel_ids->push_back(std::move(channel_id));
}

UMA_HISTOGRAM_COUNTS_10000(
Expand Down
34 changes: 19 additions & 15 deletions net/extras/sqlite/sqlite_channel_id_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/thread_task_runner_handle.h"
#include "crypto/ec_private_key.h"
Expand All @@ -27,7 +29,8 @@ const base::FilePath::CharType kTestChannelIDFilename[] =

class SQLiteChannelIDStoreTest : public testing::Test {
public:
void Load(ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids) {
void Load(
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids) {
base::RunLoop run_loop;
store_->Load(base::Bind(&SQLiteChannelIDStoreTest::OnLoaded,
base::Unretained(this),
Expand All @@ -39,7 +42,8 @@ class SQLiteChannelIDStoreTest : public testing::Test {

void OnLoaded(
base::RunLoop* run_loop,
scoped_ptr<ScopedVector<DefaultChannelIDStore::ChannelID> > channel_ids) {
scoped_ptr<std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>>
channel_ids) {
channel_ids_.swap(*channel_ids);
run_loop->Quit();
}
Expand Down Expand Up @@ -101,7 +105,7 @@ class SQLiteChannelIDStoreTest : public testing::Test {
store_ = new SQLiteChannelIDStore(
temp_dir_.path().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get());
ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
Load(&channel_ids);
ASSERT_EQ(0u, channel_ids.size());
// Make sure the store gets written at least once.
Expand All @@ -113,7 +117,7 @@ class SQLiteChannelIDStoreTest : public testing::Test {

base::ScopedTempDir temp_dir_;
scoped_refptr<SQLiteChannelIDStore> store_;
ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids_;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids_;
scoped_ptr<crypto::ECPrivateKey> google_key_;
};

Expand All @@ -124,7 +128,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestPersistence) {
"foo.com", base::Time::FromInternalValue(3),
make_scoped_ptr(foo_key->Copy())));

ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
// Replace the store effectively destroying the current one and forcing it
// to write its data to disk. Then we can see if after loading it again it
// is still there.
Expand All @@ -141,11 +145,11 @@ TEST_F(SQLiteChannelIDStoreTest, TestPersistence) {
DefaultChannelIDStore::ChannelID* goog_channel_id;
DefaultChannelIDStore::ChannelID* foo_channel_id;
if (channel_ids[0]->server_identifier() == "google.com") {
goog_channel_id = channel_ids[0];
foo_channel_id = channel_ids[1];
goog_channel_id = channel_ids[0].get();
foo_channel_id = channel_ids[1].get();
} else {
goog_channel_id = channel_ids[1];
foo_channel_id = channel_ids[0];
goog_channel_id = channel_ids[1].get();
foo_channel_id = channel_ids[0].get();
}
ASSERT_EQ("google.com", goog_channel_id->server_identifier());
EXPECT_TRUE(KeysEqual(google_key_.get(), goog_channel_id->key()));
Expand Down Expand Up @@ -180,7 +184,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestDeleteAll) {
"foo.com", base::Time::FromInternalValue(3),
make_scoped_ptr(crypto::ECPrivateKey::Create())));

ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
// Replace the store effectively destroying the current one and forcing it
// to write its data to disk. Then we can see if after loading it again it
// is still there.
Expand Down Expand Up @@ -262,7 +266,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV1) {
for (int i = 0; i < 2; ++i) {
SCOPED_TRACE(i);

ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
store_ = new SQLiteChannelIDStore(v1_db_path,
base::ThreadTaskRunnerHandle::Get());

Expand Down Expand Up @@ -334,7 +338,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV2) {
for (int i = 0; i < 2; ++i) {
SCOPED_TRACE(i);

ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
store_ = new SQLiteChannelIDStore(v2_db_path,
base::ThreadTaskRunnerHandle::Get());

Expand Down Expand Up @@ -412,7 +416,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV3) {
for (int i = 0; i < 2; ++i) {
SCOPED_TRACE(i);

ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
store_ = new SQLiteChannelIDStore(v3_db_path,
base::ThreadTaskRunnerHandle::Get());

Expand Down Expand Up @@ -506,7 +510,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV4) {
for (int i = 0; i < 2; ++i) {
SCOPED_TRACE(i);

ScopedVector<DefaultChannelIDStore::ChannelID> channel_ids;
std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
store_ = new SQLiteChannelIDStore(v4_db_path,
base::ThreadTaskRunnerHandle::Get());

Expand Down
16 changes: 7 additions & 9 deletions net/ssl/default_channel_id_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ void DefaultChannelIDStore::InitStore() {
}

void DefaultChannelIDStore::OnLoaded(
scoped_ptr<ScopedVector<ChannelID> > channel_ids) {
scoped_ptr<std::vector<scoped_ptr<ChannelID>>> channel_ids) {
DCHECK(CalledOnValidThread());

for (std::vector<ChannelID*>::const_iterator it = channel_ids->begin();
for (std::vector<scoped_ptr<ChannelID>>::iterator it = channel_ids->begin();
it != channel_ids->end(); ++it) {
DCHECK(channel_ids_.find((*it)->server_identifier()) ==
channel_ids_.end());
channel_ids_[(*it)->server_identifier()] = *it;
std::string ident = (*it)->server_identifier();
channel_ids_[ident] = it->release();
}
channel_ids->weak_clear();
channel_ids->clear();

loaded_ = true;

Expand All @@ -327,10 +327,8 @@ void DefaultChannelIDStore::OnLoaded(
UMA_HISTOGRAM_COUNTS_100("DomainBoundCerts.TaskWaitCount",
waiting_tasks_.size());


for (ScopedVector<Task>::iterator i = waiting_tasks_.begin();
i != waiting_tasks_.end(); ++i)
(*i)->Run(this);
for (scoped_ptr<Task>& i : waiting_tasks_)
i->Run(this);
waiting_tasks_.clear();
}

Expand Down
6 changes: 3 additions & 3 deletions net/ssl/default_channel_id_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class NET_EXPORT DefaultChannelIDStore : public ChannelIDStore {
void InitStore();

// Callback for backing store loading completion.
void OnLoaded(scoped_ptr<ScopedVector<ChannelID> > certs);
void OnLoaded(scoped_ptr<std::vector<scoped_ptr<ChannelID>>> certs);

// Syncronous methods which do the actual work. Can only be called after
// initialization is complete.
Expand Down Expand Up @@ -127,7 +127,7 @@ class NET_EXPORT DefaultChannelIDStore : public ChannelIDStore {
bool loaded_;

// Tasks that are waiting to be run once we finish loading.
ScopedVector<Task> waiting_tasks_;
std::vector<scoped_ptr<Task>> waiting_tasks_;
base::TimeTicks waiting_tasks_start_time_;

scoped_refptr<PersistentStore> store_;
Expand All @@ -145,7 +145,7 @@ typedef base::RefCountedThreadSafe<DefaultChannelIDStore::PersistentStore>
class NET_EXPORT DefaultChannelIDStore::PersistentStore
: public RefcountedPersistentStore {
public:
typedef base::Callback<void(scoped_ptr<ScopedVector<ChannelID> >)>
typedef base::Callback<void(scoped_ptr<std::vector<scoped_ptr<ChannelID>>>)>
LoadedCallback;

// Initializes the store and retrieves the existing channel_ids. This will be
Expand Down
7 changes: 4 additions & 3 deletions net/ssl/default_channel_id_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ class MockPersistentStore
MockPersistentStore::MockPersistentStore() {}

void MockPersistentStore::Load(const LoadedCallback& loaded_callback) {
scoped_ptr<ScopedVector<DefaultChannelIDStore::ChannelID> >
channel_ids(new ScopedVector<DefaultChannelIDStore::ChannelID>());
scoped_ptr<std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>>
channel_ids(
new std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>());
ChannelIDMap::iterator it;

for (it = channel_ids_.begin(); it != channel_ids_.end(); ++it) {
channel_ids->push_back(
new DefaultChannelIDStore::ChannelID(it->second));
make_scoped_ptr(new DefaultChannelIDStore::ChannelID(it->second)));
}

base::ThreadTaskRunnerHandle::Get()->PostTask(
Expand Down

0 comments on commit 4464294

Please sign in to comment.