Skip to content

Commit

Permalink
//[chrome/browser/]net: Change ScopedTempDir::path() to GetPath()
Browse files Browse the repository at this point in the history
path() is being deprecated, GetPath() has better checking against wrong use.

For more context, see https://codereview.chromium.org/2275553005/.

R=mmenke@chromium.org
BUG=640599

Review-Url: https://codereview.chromium.org/2319513003
Cr-Commit-Position: refs/heads/master@{#417533}
  • Loading branch information
vabr authored and Commit bot committed Sep 9, 2016
1 parent 2deef68 commit b858232
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 148 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/net/errorpage_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, FileNotFound) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
GURL non_existent_file_url =
net::FilePathToFileURL(temp_dir.path().AppendASCII("marmoset"));
net::FilePathToFileURL(temp_dir.GetPath().AppendASCII("marmoset"));

ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), non_existent_file_url, 1);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/net/file_downloader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FileDownloaderTest : public testing::Test {

void SetUp() override {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
path_ = dir_.path().AppendASCII(kFilename);
path_ = dir_.GetPath().AppendASCII(kFilename);
ASSERT_FALSE(base::PathExists(path_));
}

Expand Down
25 changes: 10 additions & 15 deletions chrome/browser/net/quota_policy_channel_id_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ class QuotaPolicyChannelIDStoreTest : public testing::Test {
void SetUp() override {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
store_ = new QuotaPolicyChannelIDStore(
temp_dir_.path().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(),
NULL);
temp_dir_.GetPath().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(), NULL);
std::vector<std::unique_ptr<net::DefaultChannelIDStore::ChannelID>>
channel_ids;
Load(&channel_ids);
Expand Down Expand Up @@ -96,9 +95,8 @@ TEST_F(QuotaPolicyChannelIDStoreTest, TestPersistence) {
// Make sure we wait until the destructor has run.
base::RunLoop().RunUntilIdle();
store_ = new QuotaPolicyChannelIDStore(
temp_dir_.path().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(),
NULL);
temp_dir_.GetPath().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(), NULL);

// Reload and test for persistence
Load(&channel_ids);
Expand Down Expand Up @@ -127,9 +125,8 @@ TEST_F(QuotaPolicyChannelIDStoreTest, TestPersistence) {
base::RunLoop().RunUntilIdle();
channel_ids.clear();
store_ = new QuotaPolicyChannelIDStore(
temp_dir_.path().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(),
NULL);
temp_dir_.GetPath().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(), NULL);

// Reload and check if the channel ID has been removed.
Load(&channel_ids);
Expand Down Expand Up @@ -160,9 +157,8 @@ TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) {
net::cookie_util::CookieOriginToURL("nonpersistent.com", true));
// Reload store, it should still have both channel IDs.
store_ = new QuotaPolicyChannelIDStore(
temp_dir_.path().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(),
storage_policy);
temp_dir_.GetPath().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(), storage_policy);
Load(&channel_ids);
ASSERT_EQ(2U, channel_ids.size());

Expand All @@ -185,9 +181,8 @@ TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) {
base::RunLoop().RunUntilIdle();
channel_ids.clear();
store_ = new QuotaPolicyChannelIDStore(
temp_dir_.path().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(),
NULL);
temp_dir_.GetPath().Append(kTestChannelIDFilename),
base::ThreadTaskRunnerHandle::Get(), NULL);

// Reload and check that the nonpersistent.com channel IDs have been removed.
Load(&channel_ids);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/net/sdch_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class SdchBrowserTest : public InProcessBrowserTest,
return false;

second_profile_ = g_browser_process->profile_manager()->GetProfile(
second_profile_data_dir_.path());
second_profile_data_dir_.GetPath());
if (!second_profile_) return false;

second_browser_ = new Browser(Browser::CreateParams(second_profile_));
Expand Down
16 changes: 7 additions & 9 deletions net/base/directory_lister_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class DirectoryListerTest : public PlatformTest {
// directory.
std::list<std::pair<base::FilePath, int> > directories;
ASSERT_TRUE(temp_root_dir_.CreateUniqueTempDir());
directories.push_back(std::make_pair(temp_root_dir_.path(), 0));
directories.push_back(std::make_pair(temp_root_dir_.GetPath(), 0));
while (!directories.empty()) {
std::pair<base::FilePath, int> dir_data = directories.front();
directories.pop_front();
Expand All @@ -154,7 +154,7 @@ class DirectoryListerTest : public PlatformTest {
base::File::FLAG_CREATE | base::File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
++total_created_file_system_objects_in_temp_root_dir_;
if (dir_data.first == temp_root_dir_.path())
if (dir_data.first == temp_root_dir_.GetPath())
++created_file_system_objects_in_temp_root_dir_;
}
if (dir_data.second < kMaxDepth - 1) {
Expand All @@ -163,7 +163,7 @@ class DirectoryListerTest : public PlatformTest {
base::FilePath dir_path = dir_data.first.AppendASCII(dir_name);
ASSERT_TRUE(base::CreateDirectory(dir_path));
++total_created_file_system_objects_in_temp_root_dir_;
if (dir_data.first == temp_root_dir_.path())
if (dir_data.first == temp_root_dir_.GetPath())
++created_file_system_objects_in_temp_root_dir_;
directories.push_back(std::make_pair(dir_path, dir_data.second + 1));
}
Expand All @@ -172,9 +172,7 @@ class DirectoryListerTest : public PlatformTest {
PlatformTest::SetUp();
}

const base::FilePath& root_path() const {
return temp_root_dir_.path();
}
const base::FilePath& root_path() const { return temp_root_dir_.GetPath(); }

int expected_list_length_recursive() const {
// List should include everything but the top level directory, and does not
Expand Down Expand Up @@ -223,7 +221,7 @@ TEST_F(DirectoryListerTest, EmptyDirTest) {
EXPECT_TRUE(tempDir.CreateUniqueTempDir());

ListerDelegate delegate(DirectoryLister::ALPHA_DIRS_FIRST);
DirectoryLister lister(tempDir.path(), &delegate);
DirectoryLister lister(tempDir.GetPath(), &delegate);
delegate.Run(&lister);

EXPECT_TRUE(delegate.done());
Expand Down Expand Up @@ -275,7 +273,7 @@ TEST_F(DirectoryListerTest, CancelOnLastElementTest) {
EXPECT_TRUE(tempDir.CreateUniqueTempDir());

ListerDelegate delegate(DirectoryLister::ALPHA_DIRS_FIRST);
DirectoryLister lister(tempDir.path(), &delegate);
DirectoryLister lister(tempDir.GetPath(), &delegate);
delegate.set_cancel_lister_on_list_file(true);
delegate.Run(&lister);

Expand All @@ -290,7 +288,7 @@ TEST_F(DirectoryListerTest, NoSuchDirTest) {

ListerDelegate delegate(DirectoryLister::ALPHA_DIRS_FIRST);
DirectoryLister lister(
tempDir.path().AppendASCII("this_path_does_not_exist"), &delegate);
tempDir.GetPath().AppendASCII("this_path_does_not_exist"), &delegate);
delegate.Run(&lister);

EXPECT_THAT(delegate.error(), IsError(ERR_FILE_NOT_FOUND));
Expand Down
36 changes: 18 additions & 18 deletions net/base/elements_upload_data_stream_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ TEST_F(ElementsUploadDataStreamTest, ConsumeAllBytes) {

TEST_F(ElementsUploadDataStreamTest, File) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));

Expand Down Expand Up @@ -216,8 +216,8 @@ TEST_F(ElementsUploadDataStreamTest, File) {

TEST_F(ElementsUploadDataStreamTest, FileSmallerThanLength) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));
const uint64_t kFakeSize = kTestDataSize * 2;
Expand Down Expand Up @@ -335,8 +335,8 @@ TEST_F(ElementsUploadDataStreamTest, ReadErrorAsync) {

TEST_F(ElementsUploadDataStreamTest, FileAndBytes) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));

Expand Down Expand Up @@ -555,8 +555,8 @@ void ElementsUploadDataStreamTest::FileChangedHelper(

TEST_F(ElementsUploadDataStreamTest, FileChanged) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));

Expand All @@ -574,8 +574,8 @@ TEST_F(ElementsUploadDataStreamTest, FileChanged) {

TEST_F(ElementsUploadDataStreamTest, MultipleInit) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));

Expand Down Expand Up @@ -618,8 +618,8 @@ TEST_F(ElementsUploadDataStreamTest, MultipleInit) {

TEST_F(ElementsUploadDataStreamTest, MultipleInitAsync) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));
TestCompletionCallback test_callback;
Expand Down Expand Up @@ -661,8 +661,8 @@ TEST_F(ElementsUploadDataStreamTest, MultipleInitAsync) {

TEST_F(ElementsUploadDataStreamTest, InitToReset) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));

Expand Down Expand Up @@ -719,8 +719,8 @@ TEST_F(ElementsUploadDataStreamTest, InitToReset) {

TEST_F(ElementsUploadDataStreamTest, InitDuringAsyncInit) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));

Expand Down Expand Up @@ -767,8 +767,8 @@ TEST_F(ElementsUploadDataStreamTest, InitDuringAsyncInit) {

TEST_F(ElementsUploadDataStreamTest, InitDuringAsyncRead) {
base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
base::WriteFile(temp_file_path, kTestData, kTestDataSize));

Expand Down
4 changes: 2 additions & 2 deletions net/base/upload_file_element_reader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class UploadFileElementReaderTest : public PlatformTest {

ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());

ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&temp_file_path_));
ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path_));
ASSERT_EQ(
static_cast<int>(bytes_.size()),
base::WriteFile(temp_file_path_, &bytes_[0], bytes_.size()));
Expand Down
36 changes: 9 additions & 27 deletions net/disk_cache/backend_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -595,15 +595,9 @@ TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) {

net::TestCompletionCallback cb;
std::unique_ptr<disk_cache::Backend> extra_cache;
int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
net::CACHE_BACKEND_DEFAULT,
store.path(),
0,
false,
base::ThreadTaskRunnerHandle::Get(),
NULL,
&extra_cache,
cb.callback());
int rv = disk_cache::CreateCacheBackend(
net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store.GetPath(), 0, false,
base::ThreadTaskRunnerHandle::Get(), NULL, &extra_cache, cb.callback());
ASSERT_THAT(cb.GetResult(rv), IsOk());
ASSERT_TRUE(extra_cache.get() != NULL);

Expand Down Expand Up @@ -3230,25 +3224,13 @@ TEST_F(DiskCacheTest, MultipleInstances) {
const int kNumberOfCaches = 2;
std::unique_ptr<disk_cache::Backend> cache[kNumberOfCaches];

int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
net::CACHE_BACKEND_DEFAULT,
store1.path(),
0,
false,
cache_thread.task_runner(),
NULL,
&cache[0],
cb.callback());
int rv = disk_cache::CreateCacheBackend(
net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store1.GetPath(), 0, false,
cache_thread.task_runner(), NULL, &cache[0], cb.callback());
ASSERT_THAT(cb.GetResult(rv), IsOk());
rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE,
net::CACHE_BACKEND_DEFAULT,
store2.path(),
0,
false,
cache_thread.task_runner(),
NULL,
&cache[1],
cb.callback());
rv = disk_cache::CreateCacheBackend(
net::MEDIA_CACHE, net::CACHE_BACKEND_DEFAULT, store2.GetPath(), 0, false,
cache_thread.task_runner(), NULL, &cache[1], cb.callback());
ASSERT_THAT(cb.GetResult(rv), IsOk());

ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL);
Expand Down
4 changes: 2 additions & 2 deletions net/disk_cache/cache_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CacheUtilTest : public PlatformTest {
void SetUp() override {
PlatformTest::SetUp();
ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
cache_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("Cache"));
cache_dir_ = tmp_dir_.GetPath().Append(FILE_PATH_LITERAL("Cache"));
file1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("file01")));
file2_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL(".file02")));
dir1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("dir01")));
Expand All @@ -31,7 +31,7 @@ class CacheUtilTest : public PlatformTest {
fp = base::OpenFile(file3_, "w");
ASSERT_TRUE(fp != NULL);
base::CloseFile(fp);
dest_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("old_Cache_001"));
dest_dir_ = tmp_dir_.GetPath().Append(FILE_PATH_LITERAL("old_Cache_001"));
dest_file1_ = base::FilePath(dest_dir_.Append(FILE_PATH_LITERAL("file01")));
dest_file2_ =
base::FilePath(dest_dir_.Append(FILE_PATH_LITERAL(".file02")));
Expand Down
2 changes: 1 addition & 1 deletion net/disk_cache/disk_cache_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using net::test::IsOk;

DiskCacheTest::DiskCacheTest() {
CHECK(temp_dir_.CreateUniqueTempDir());
cache_path_ = temp_dir_.path();
cache_path_ = temp_dir_.GetPath();
if (!base::MessageLoop::current())
message_loop_.reset(new base::MessageLoopForIO());
}
Expand Down
14 changes: 7 additions & 7 deletions net/disk_cache/simple/simple_index_file_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ TEST_F(SimpleIndexFileTest, LegacyIsIndexFileStale) {
base::ScopedTempDir cache_dir;
ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
base::Time cache_mtime;
const base::FilePath cache_path = cache_dir.path();
const base::FilePath cache_path = cache_dir.GetPath();

ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime));
WrappedSimpleIndexFile simple_index_file(cache_path);
Expand Down Expand Up @@ -249,17 +249,17 @@ TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) {
const uint64_t kCacheSize = 456U;
net::TestClosure closure;
{
WrappedSimpleIndexFile simple_index_file(cache_dir.path());
WrappedSimpleIndexFile simple_index_file(cache_dir.GetPath());
simple_index_file.WriteToDisk(SimpleIndex::INDEX_WRITE_REASON_SHUTDOWN,
entries, kCacheSize, base::TimeTicks(), false,
closure.closure());
closure.WaitForResult();
EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath()));
}

WrappedSimpleIndexFile simple_index_file(cache_dir.path());
WrappedSimpleIndexFile simple_index_file(cache_dir.GetPath());
base::Time fake_cache_mtime;
ASSERT_TRUE(simple_util::GetMTime(cache_dir.path(), &fake_cache_mtime));
ASSERT_TRUE(simple_util::GetMTime(cache_dir.GetPath(), &fake_cache_mtime));
SimpleIndexLoadResult load_index_result;
simple_index_file.LoadIndexEntries(fake_cache_mtime, closure.closure(),
&load_index_result);
Expand All @@ -278,7 +278,7 @@ TEST_F(SimpleIndexFileTest, LoadCorruptIndex) {
base::ScopedTempDir cache_dir;
ASSERT_TRUE(cache_dir.CreateUniqueTempDir());

WrappedSimpleIndexFile simple_index_file(cache_dir.path());
WrappedSimpleIndexFile simple_index_file(cache_dir.GetPath());
ASSERT_TRUE(simple_index_file.CreateIndexFileDirectory());
const base::FilePath& index_path = simple_index_file.GetIndexFilePath();
const std::string kDummyData = "nothing to be seen here";
Expand All @@ -304,7 +304,7 @@ TEST_F(SimpleIndexFileTest, LoadCorruptIndex) {
TEST_F(SimpleIndexFileTest, SimpleCacheUpgrade) {
base::ScopedTempDir cache_dir;
ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
const base::FilePath cache_path = cache_dir.path();
const base::FilePath cache_path = cache_dir.GetPath();

// Write an old fake index file.
base::File file(cache_path.AppendASCII("index"),
Expand Down Expand Up @@ -374,7 +374,7 @@ TEST_F(SimpleIndexFileTest, SimpleCacheUpgrade) {
TEST_F(SimpleIndexFileTest, OverwritesStaleTempFile) {
base::ScopedTempDir cache_dir;
ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
const base::FilePath cache_path = cache_dir.path();
const base::FilePath cache_path = cache_dir.GetPath();
WrappedSimpleIndexFile simple_index_file(cache_path);
ASSERT_TRUE(simple_index_file.CreateIndexFileDirectory());

Expand Down
Loading

0 comments on commit b858232

Please sign in to comment.