Skip to content

Commit

Permalink
Cleanup arraysize usage in //storage
Browse files Browse the repository at this point in the history
This CL cleanup arraysize usage in //storage with:
- Range based for-loops when iterating
- Replace with base::size()

Bug: 837308
Change-Id: Id4c9eedf4371b819e61d735b6cdbb68eeeb7594c
Reviewed-on: https://chromium-review.googlesource.com/c/1377474
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#616708}
  • Loading branch information
ZhuoyuQian authored and inexorabletash committed Dec 14, 2018
1 parent f06cb3f commit 711d61d
Show file tree
Hide file tree
Showing 24 changed files with 181 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,8 @@ TEST(LocalFileSystemCopyOrMoveOperationTest,
{false, FILE_PATH_LITERAL("file 3"), 0},
};

helper.VerifyTestCaseFiles(dest,
kMoveDirResultCases,
arraysize(kMoveDirResultCases));
helper.VerifyTestCaseFiles(dest, kMoveDirResultCases,
base::size(kMoveDirResultCases));
}

TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFileNoValidator) {
Expand Down Expand Up @@ -736,7 +735,7 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper) {
base::FilePath dest_path = temp_dir.GetPath().AppendASCII("dest");
const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789";
base::WriteFile(source_path, kTestData,
arraysize(kTestData) - 1); // Exclude trailing '\0'.
base::size(kTestData) - 1); // Exclude trailing '\0'.

base::MessageLoopForIO message_loop;
base::Thread file_thread("file_thread");
Expand Down Expand Up @@ -792,8 +791,7 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelperWithFlush) {
base::FilePath dest_path = temp_dir.GetPath().AppendASCII("dest");
const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789";
base::WriteFile(source_path, kTestData,
arraysize(kTestData) - 1); // Exclude trailing '\0'.

base::size(kTestData) - 1); // Exclude trailing '\0'.

base::MessageLoopForIO message_loop;
base::Thread file_thread("file_thread");
Expand Down Expand Up @@ -845,7 +843,7 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper_Cancel) {
base::FilePath dest_path = temp_dir.GetPath().AppendASCII("dest");
const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789";
base::WriteFile(source_path, kTestData,
arraysize(kTestData) - 1); // Exclude trailing '\0'.
base::size(kTestData) - 1); // Exclude trailing '\0'.

base::MessageLoopForIO message_loop;
base::Thread file_thread("file_thread");
Expand Down
7 changes: 4 additions & 3 deletions storage/browser/fileapi/dragged_file_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/services/filesystem/public/interfaces/types.mojom.h"
Expand Down Expand Up @@ -268,7 +269,7 @@ class DraggedFileUtilTest : public testing::Test {
// to simulate a drop with multiple directories.
if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) {
base::FilePath root = root_path().Append(
kRootPaths[(root_path_index++) % arraysize(kRootPaths)]);
kRootPaths[(root_path_index++) % base::size(kRootPaths)]);
toplevel_root_map_[toplevel] = root;
toplevels.AddPath(root.Append(path), nullptr);
}
Expand Down Expand Up @@ -325,7 +326,7 @@ TEST_F(DraggedFileUtilTest, UnregisteredPathsTest) {
{false, FILE_PATH_LITERAL("bar"), 20},
};

for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) {
for (size_t i = 0; i < base::size(kUnregisteredCases); ++i) {
SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i);
const FileSystemTestCaseRecord& test_case = kUnregisteredCases[i];

Expand All @@ -340,7 +341,7 @@ TEST_F(DraggedFileUtilTest, UnregisteredPathsTest) {
ASSERT_EQ(test_case.is_directory, info.is_directory);
}

for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) {
for (size_t i = 0; i < base::size(kUnregisteredCases); ++i) {
SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i);
const FileSystemTestCaseRecord& test_case = kUnregisteredCases[i];
FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path));
Expand Down
36 changes: 17 additions & 19 deletions storage/browser/fileapi/external_mount_points_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "storage/browser/fileapi/file_system_url.h"
#include "storage/common/fileapi/file_system_mount_option.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -110,19 +111,16 @@ TEST(ExternalMountPointsTest, AddMountPoint) {
};

// Test adding mount points.
for (size_t i = 0; i < arraysize(kTestCases); ++i) {
EXPECT_EQ(
kTestCases[i].success,
mount_points->RegisterFileSystem(kTestCases[i].name,
storage::kFileSystemTypeNativeLocal,
storage::FileSystemMountOption(),
base::FilePath(kTestCases[i].path)))
<< "Adding mount point: " << kTestCases[i].name << " with path "
<< kTestCases[i].path;
for (const auto& test : kTestCases) {
EXPECT_EQ(test.success,
mount_points->RegisterFileSystem(
test.name, storage::kFileSystemTypeNativeLocal,
storage::FileSystemMountOption(), base::FilePath(test.path)))
<< "Adding mount point: " << test.name << " with path " << test.path;
}

// Test that final mount point presence state is as expected.
for (size_t i = 0; i < arraysize(kTestCases); ++i) {
for (size_t i = 0; i < base::size(kTestCases); ++i) {
base::FilePath found_path;
EXPECT_EQ(kTestCases[i].registered_path != nullptr,
mount_points->GetRegisteredPath(kTestCases[i].name, &found_path))
Expand Down Expand Up @@ -218,22 +216,22 @@ TEST(ExternalMountPointsTest, GetVirtualPath) {
#endif
};

for (size_t i = 0; i < arraysize(kTestCases); ++i) {
for (const auto& test_case : kTestCases) {
// Initialize virtual path with a value.
base::FilePath virtual_path(DRIVE FPL("/mount"));
base::FilePath local_path(kTestCases[i].local_path);
EXPECT_EQ(kTestCases[i].success,
base::FilePath local_path(test_case.local_path);
EXPECT_EQ(test_case.success,
mount_points->GetVirtualPath(local_path, &virtual_path))
<< "Resolving " << kTestCases[i].local_path;
<< "Resolving " << test_case.local_path;

// There are no guarantees for |virtual_path| value if |GetVirtualPath|
// fails.
if (!kTestCases[i].success)
if (!test_case.success)
continue;

base::FilePath expected_virtual_path(kTestCases[i].virtual_path);
base::FilePath expected_virtual_path(test_case.virtual_path);
EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path)
<< "Resolving " << kTestCases[i].local_path;
<< "Resolving " << test_case.local_path;
}
}

Expand Down Expand Up @@ -349,7 +347,7 @@ TEST(ExternalMountPointsTest, CreateCrackedFileSystemURL) {
#endif
};

for (size_t i = 0; i < arraysize(kTestCases); ++i) {
for (size_t i = 0; i < base::size(kTestCases); ++i) {
FileSystemURL cracked = mount_points->CreateCrackedFileSystemURL(
kTestOrigin,
storage::kFileSystemTypeExternal,
Expand Down Expand Up @@ -443,7 +441,7 @@ TEST(ExternalMountPointsTest, CrackVirtualPath) {
#endif
};

for (size_t i = 0; i < arraysize(kTestCases); ++i) {
for (size_t i = 0; i < base::size(kTestCases); ++i) {
std::string cracked_name;
storage::FileSystemType cracked_type;
std::string cracked_id;
Expand Down
8 changes: 4 additions & 4 deletions storage/browser/fileapi/file_system_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,10 @@ void FileSystemContext::RegisterBackend(FileSystemBackend* backend) {
kFileSystemTypeExternal,
};
// Register file system backends for public mount types.
for (size_t j = 0; j < arraysize(mount_types); ++j) {
if (backend->CanHandleType(mount_types[j])) {
const bool inserted = backend_map_.insert(
std::make_pair(mount_types[j], backend)).second;
for (const auto& mount_type : mount_types) {
if (backend->CanHandleType(mount_type)) {
const bool inserted =
backend_map_.insert(std::make_pair(mount_type, backend)).second;
DCHECK(inserted);
}
}
Expand Down
3 changes: 2 additions & 1 deletion storage/browser/fileapi/file_system_context_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -289,7 +290,7 @@ TEST_F(FileSystemContextTest, CrackFileSystemURL) {
FPL(""), std::string()},
};

for (size_t i = 0; i < arraysize(kTestCases); ++i) {
for (size_t i = 0; i < base::size(kTestCases); ++i) {
const base::FilePath virtual_path =
base::FilePath::FromUTF8Unsafe(
kTestCases[i].root).Append(kVirtualPathNoRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
Expand All @@ -38,7 +39,7 @@ namespace {
const char kURLOrigin[] = "http://remote/";
const char kTestFileName[] = "test.dat";
const char kTestData[] = "0123456789";
const int kTestDataSize = arraysize(kTestData) - 1;
const int kTestDataSize = base::size(kTestData) - 1;

void ReadFromReader(storage::FileSystemFileStreamReader* reader,
std::string* data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -823,7 +824,7 @@ TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) {
base::FilePath src_local_disk_file_path;
base::CreateTemporaryFile(&src_local_disk_file_path);
const char test_data[] = "foo";
int data_size = arraysize(test_data);
int data_size = base::size(test_data);
base::WriteFile(src_local_disk_file_path, test_data, data_size);

FileSystemURL dest_dir(CreateDirectory("dest"));
Expand Down Expand Up @@ -854,7 +855,7 @@ TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) {
base::FilePath src_local_disk_file_path;
base::CreateTemporaryFile(&src_local_disk_file_path);
const char test_data[] = "foo";
base::WriteFile(src_local_disk_file_path, test_data, arraysize(test_data));
base::WriteFile(src_local_disk_file_path, test_data, base::size(test_data));

FileSystemURL dest_dir(CreateDirectory("dest"));

Expand Down
Loading

0 comments on commit 711d61d

Please sign in to comment.