Use base::size rather than arraysize

https://bugs.chromium.org/p/chromium/issues/detail?id=837308
This commit is contained in:
deepak1556 2019-01-21 23:56:33 +05:30
parent a913e396d5
commit abec938b0a
9 changed files with 23 additions and 19 deletions

View file

@ -478,7 +478,7 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
switches::kServiceWorkerSchemes}; switches::kServiceWorkerSchemes};
command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(), command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
kCommonSwitchNames, kCommonSwitchNames,
arraysize(kCommonSwitchNames)); base::size(kCommonSwitchNames));
#if defined(OS_WIN) #if defined(OS_WIN)
// Append --app-user-model-id. // Append --app-user-model-id.

View file

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "base/stl_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
@ -103,7 +104,7 @@ const FontDefault kFontDefaults[] = {
IDS_FIXED_FONT_FAMILY_TRADITIONAL_HAN}, IDS_FIXED_FONT_FAMILY_TRADITIONAL_HAN},
#endif #endif
}; };
const size_t kFontDefaultsLength = arraysize(kFontDefaults); const size_t kFontDefaultsLength = base::size(kFontDefaults);
// ^^^^^ DO NOT EDIT ^^^^^ // ^^^^^ DO NOT EDIT ^^^^^

View file

@ -16,6 +16,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/strings/pattern.h" #include "base/strings/pattern.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
@ -109,7 +110,7 @@ void SetZoomLevelForWebContents(content::WebContents* web_contents,
double GetNextZoomLevel(double level, bool out) { double GetNextZoomLevel(double level, bool out) {
double factor = content::ZoomLevelToZoomFactor(level); double factor = content::ZoomLevelToZoomFactor(level);
size_t size = arraysize(kPresetZoomFactors); size_t size = base::size(kPresetZoomFactors);
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (!content::ZoomValuesEqual(kPresetZoomFactors[i], factor)) if (!content::ZoomValuesEqual(kPresetZoomFactors[i], factor))
continue; continue;

View file

@ -83,7 +83,7 @@ bool ConvertShellLinkToJumpListItem(IShellLink* shell_link,
item->type = JumpListItem::Type::TASK; item->type = JumpListItem::Type::TASK;
wchar_t path[MAX_PATH]; wchar_t path[MAX_PATH];
if (FAILED(shell_link->GetPath(path, arraysize(path), nullptr, 0))) if (FAILED(shell_link->GetPath(path, MAX_PATH, nullptr, 0)))
return false; return false;
CComQIPtr<IPropertyStore> property_store = shell_link; CComQIPtr<IPropertyStore> property_store = shell_link;
@ -100,14 +100,13 @@ bool ConvertShellLinkToJumpListItem(IShellLink* shell_link,
} }
int icon_index; int icon_index;
if (SUCCEEDED( if (SUCCEEDED(shell_link->GetIconLocation(path, MAX_PATH, &icon_index))) {
shell_link->GetIconLocation(path, arraysize(path), &icon_index))) {
item->icon_path = base::FilePath(path); item->icon_path = base::FilePath(path);
item->icon_index = icon_index; item->icon_index = icon_index;
} }
wchar_t item_desc[INFOTIPSIZE]; wchar_t item_desc[INFOTIPSIZE];
if (SUCCEEDED(shell_link->GetDescription(item_desc, arraysize(item_desc)))) if (SUCCEEDED(shell_link->GetDescription(item_desc, INFOTIPSIZE)))
item->description = item_desc; item->description = item_desc;
return true; return true;

View file

@ -13,6 +13,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/time/time.h" #include "base/time/time.h"
@ -414,7 +415,7 @@ DWORD CrashService::AsyncSendDump(void* context) {
const DWORD kSleepSchedule[] = {24 * kOneHour, 8 * kOneHour, 4 * kOneHour, const DWORD kSleepSchedule[] = {24 * kOneHour, 8 * kOneHour, 4 * kOneHour,
kOneHour, 15 * kOneMinute, 0}; kOneHour, 15 * kOneMinute, 0};
int retry_round = arraysize(kSleepSchedule) - 1; int retry_round = base::size(kSleepSchedule) - 1;
do { do {
::Sleep(kSleepSchedule[retry_round]); ::Sleep(kSleepSchedule[retry_round]);

View file

@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/callback.h"
#include "base/stl_util.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
@ -151,7 +152,7 @@ v8::Local<v8::Value> BindFunctionWith(v8::Isolate* isolate,
v8::Local<v8::Function> bind_func = v8::Local<v8::Function> bind_func =
v8::Local<v8::Function>::Cast(bind.ToLocalChecked()); v8::Local<v8::Function>::Cast(bind.ToLocalChecked());
v8::Local<v8::Value> converted[] = {func, arg1, arg2}; v8::Local<v8::Value> converted[] = {func, arg1, arg2};
return bind_func->Call(context, func, arraysize(converted), converted) return bind_func->Call(context, func, base::size(converted), converted)
.ToLocalChecked(); .ToLocalChecked();
} }

View file

@ -29,7 +29,6 @@
#undef DISALLOW_COPY_AND_ASSIGN #undef DISALLOW_COPY_AND_ASSIGN
#undef NO_RETURN #undef NO_RETURN
#undef LIKELY #undef LIKELY
#undef arraysize
#undef debug_string // This is defined in macOS SDK in AssertMacros.h. #undef debug_string // This is defined in macOS SDK in AssertMacros.h.
#undef require_string // This is defined in macOS SDK in AssertMacros.h. #undef require_string // This is defined in macOS SDK in AssertMacros.h.
#include "env-inl.h" #include "env-inl.h"

View file

@ -20,6 +20,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h" #include "base/win/registry.h"
@ -263,7 +264,7 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
const ITEMIDLIST* highlight[] = {file_item}; const ITEMIDLIST* highlight[] = {file_item};
hr = SHOpenFolderAndSelectItems(dir_item, arraysize(highlight), highlight, hr = SHOpenFolderAndSelectItems(dir_item, base::size(highlight), highlight,
NULL); NULL);
if (!FAILED(hr)) if (!FAILED(hr))
return true; return true;

View file

@ -76,6 +76,7 @@
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/sequenced_task_runner_helpers.h" #include "base/sequenced_task_runner_helpers.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
@ -114,7 +115,7 @@ const char kACKToken[] = "ACK";
const char kShutdownToken[] = "SHUTDOWN"; const char kShutdownToken[] = "SHUTDOWN";
const char kTokenDelimiter = '\0'; const char kTokenDelimiter = '\0';
const int kMaxMessageLength = 32 * 1024; const int kMaxMessageLength = 32 * 1024;
const int kMaxACKMessageLength = arraysize(kShutdownToken) - 1; const int kMaxACKMessageLength = base::size(kShutdownToken) - 1;
const char kLockDelimiter = '-'; const char kLockDelimiter = '-';
@ -225,9 +226,9 @@ ssize_t ReadFromSocket(int fd,
// Set up a sockaddr appropriate for messaging. // Set up a sockaddr appropriate for messaging.
void SetupSockAddr(const std::string& path, struct sockaddr_un* addr) { void SetupSockAddr(const std::string& path, struct sockaddr_un* addr) {
addr->sun_family = AF_UNIX; addr->sun_family = AF_UNIX;
CHECK(path.length() < arraysize(addr->sun_path)) CHECK(path.length() < base::size(addr->sun_path))
<< "Socket path too long: " << path; << "Socket path too long: " << path;
base::strlcpy(addr->sun_path, path.c_str(), arraysize(addr->sun_path)); base::strlcpy(addr->sun_path, path.c_str(), base::size(addr->sun_path));
} }
// Set up a socket appropriate for messaging. // Set up a socket appropriate for messaging.
@ -604,13 +605,13 @@ void ProcessSingleton::LinuxWatcher::HandleMessage(
if (parent_->notification_callback_.Run(argv, base::FilePath(current_dir))) { if (parent_->notification_callback_.Run(argv, base::FilePath(current_dir))) {
// Send back "ACK" message to prevent the client process from starting up. // Send back "ACK" message to prevent the client process from starting up.
reader->FinishWithACK(kACKToken, arraysize(kACKToken) - 1); reader->FinishWithACK(kACKToken, base::size(kACKToken) - 1);
} else { } else {
LOG(WARNING) << "Not handling interprocess notification as browser" LOG(WARNING) << "Not handling interprocess notification as browser"
" is shutting down"; " is shutting down";
// Send back "SHUTDOWN" message, so that the client process can start up // Send back "SHUTDOWN" message, so that the client process can start up
// without killing this process. // without killing this process.
reader->FinishWithACK(kShutdownToken, arraysize(kShutdownToken) - 1); reader->FinishWithACK(kShutdownToken, base::size(kShutdownToken) - 1);
return; return;
} }
} }
@ -654,7 +655,7 @@ void ProcessSingleton::LinuxWatcher::SocketReader::
} }
// Validate the message. The shortest message is kStartToken\0x\0x // Validate the message. The shortest message is kStartToken\0x\0x
const size_t kMinMessageLength = arraysize(kStartToken) + 4; const size_t kMinMessageLength = base::size(kStartToken) + 4;
if (bytes_read_ < kMinMessageLength) { if (bytes_read_ < kMinMessageLength) {
buf_[bytes_read_] = 0; buf_[bytes_read_] = 0;
LOG(ERROR) << "Invalid socket message (wrong length):" << buf_; LOG(ERROR) << "Invalid socket message (wrong length):" << buf_;
@ -857,10 +858,10 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout(
} }
buf[len] = '\0'; buf[len] = '\0';
if (strncmp(buf, kShutdownToken, arraysize(kShutdownToken) - 1) == 0) { if (strncmp(buf, kShutdownToken, base::size(kShutdownToken) - 1) == 0) {
// The other process is shutting down, it's safe to start a new process. // The other process is shutting down, it's safe to start a new process.
return PROCESS_NONE; return PROCESS_NONE;
} else if (strncmp(buf, kACKToken, arraysize(kACKToken) - 1) == 0) { } else if (strncmp(buf, kACKToken, base::size(kACKToken) - 1) == 0) {
#if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) && !defined(OS_CHROMEOS) #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Likely NULL in unit tests. // Likely NULL in unit tests.
views::LinuxUI* linux_ui = views::LinuxUI::instance(); views::LinuxUI* linux_ui = views::LinuxUI::instance();