diff options
author | thestig <thestig@chromium.org> | 2014-12-04 14:14:22 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-04 22:15:43 +0000 |
commit | 8badc79882ad8723e60cf47aeb41c56adb2789b3 (patch) | |
tree | 88e106bc35a3c7b53d0e0ac326c09b9cb0489b5b | |
parent | cde16351653d0bb86675647a67fca3326db8148b (diff) | |
download | chromium_src-8badc79882ad8723e60cf47aeb41c56adb2789b3.zip chromium_src-8badc79882ad8723e60cf47aeb41c56adb2789b3.tar.gz chromium_src-8badc79882ad8723e60cf47aeb41c56adb2789b3.tar.bz2 |
Cleanup: Get rid of more base::ASCIIToWide usage.
Also do some lint cleanups.
BUG=23581
Review URL: https://codereview.chromium.org/777623002
Cr-Commit-Position: refs/heads/master@{#306905}
-rw-r--r-- | base/command_line.cc | 42 | ||||
-rw-r--r-- | base/files/file_util_win.cc | 50 | ||||
-rw-r--r-- | base/memory/shared_memory_win.cc | 16 | ||||
-rw-r--r-- | base/test/launcher/test_launcher.cc | 38 | ||||
-rw-r--r-- | base/test/test_reg_util_win.cc | 2 | ||||
-rw-r--r-- | content/common/dwrite_font_platform_win.cc | 18 | ||||
-rw-r--r-- | courgette/encoded_program.cc | 17 |
7 files changed, 86 insertions, 97 deletions
diff --git a/base/command_line.cc b/base/command_line.cc index 1f5edce..fb7c813 100644 --- a/base/command_line.cc +++ b/base/command_line.cc @@ -70,7 +70,7 @@ bool IsSwitch(const CommandLine::StringType& string, } // Append switches and arguments, keeping switches before arguments. -void AppendSwitchesAndArguments(CommandLine& command_line, +void AppendSwitchesAndArguments(CommandLine* command_line, const CommandLine::StringVector& argv) { bool parse_switches = true; for (size_t i = 1; i < argv.size(); ++i) { @@ -82,13 +82,13 @@ void AppendSwitchesAndArguments(CommandLine& command_line, parse_switches &= (arg != kSwitchTerminator); if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { #if defined(OS_WIN) - command_line.AppendSwitchNative(UTF16ToASCII(switch_string), - switch_value); + command_line->AppendSwitchNative(UTF16ToASCII(switch_string), + switch_value); #elif defined(OS_POSIX) - command_line.AppendSwitchNative(switch_string, switch_value); + command_line->AppendSwitchNative(switch_string, switch_value); #endif } else { - command_line.AppendArgNative(arg); + command_line->AppendArgNative(arg); } } } @@ -96,7 +96,7 @@ void AppendSwitchesAndArguments(CommandLine& command_line, // Lowercase switches for backwards compatiblity *on Windows*. std::string LowerASCIIOnWindows(const std::string& string) { #if defined(OS_WIN) - return base::StringToLowerASCII(string); + return StringToLowerASCII(string); #elif defined(OS_POSIX) return string; #endif @@ -105,28 +105,27 @@ std::string LowerASCIIOnWindows(const std::string& string) { #if defined(OS_WIN) // Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*. -base::string16 QuoteForCommandLineToArgvW(const base::string16& arg, - bool quote_placeholders) { +string16 QuoteForCommandLineToArgvW(const string16& arg, + bool quote_placeholders) { // We follow the quoting rules of CommandLineToArgvW. // http://msdn.microsoft.com/en-us/library/17w5ykft.aspx - base::string16 quotable_chars(L" \\\""); + string16 quotable_chars(L" \\\""); // We may also be required to quote '%', which is commonly used in a command // line as a placeholder. (It may be substituted for a string with spaces.) if (quote_placeholders) quotable_chars.push_back(L'%'); - if (arg.find_first_of(quotable_chars) == base::string16::npos) { + if (arg.find_first_of(quotable_chars) == string16::npos) { // No quoting necessary. return arg; } - base::string16 out; + string16 out; out.push_back(L'"'); for (size_t i = 0; i < arg.size(); ++i) { if (arg[i] == '\\') { // Find the extent of this run of backslashes. size_t start = i, end = start + 1; - for (; end < arg.size() && arg[end] == '\\'; ++end) - /* empty */; + for (; end < arg.size() && arg[end] == '\\'; ++end) {} size_t backslash_count = end - start; // Backslashes are escapes only if the run is followed by a double quote. @@ -230,7 +229,7 @@ bool CommandLine::InitializedForCurrentProcess() { #if defined(OS_WIN) // static -CommandLine CommandLine::FromString(const base::string16& command_line) { +CommandLine CommandLine::FromString(const string16& command_line) { CommandLine cmd(NO_PROGRAM); cmd.ParseFromString(command_line); return cmd; @@ -250,7 +249,7 @@ void CommandLine::InitFromArgv(const StringVector& argv) { switches_.clear(); begin_args_ = 1; SetProgram(argv.empty() ? FilePath() : FilePath(argv[0])); - AppendSwitchesAndArguments(*this, argv); + AppendSwitchesAndArguments(this, argv); } FilePath CommandLine::GetProgram() const { @@ -304,7 +303,7 @@ void CommandLine::AppendSwitchNative(const std::string& switch_string, const CommandLine::StringType& value) { std::string switch_key(LowerASCIIOnWindows(switch_string)); #if defined(OS_WIN) - StringType combined_switch_string(ASCIIToWide(switch_key)); + StringType combined_switch_string(ASCIIToUTF16(switch_key)); #elif defined(OS_POSIX) StringType combined_switch_string(switch_string); #endif @@ -322,7 +321,7 @@ void CommandLine::AppendSwitchNative(const std::string& switch_string, void CommandLine::AppendSwitchASCII(const std::string& switch_string, const std::string& value_string) { #if defined(OS_WIN) - AppendSwitchNative(switch_string, ASCIIToWide(value_string)); + AppendSwitchNative(switch_string, ASCIIToUTF16(value_string)); #elif defined(OS_POSIX) AppendSwitchNative(switch_string, value_string); #endif @@ -369,7 +368,7 @@ void CommandLine::AppendArguments(const CommandLine& other, bool include_program) { if (include_program) SetProgram(other.GetProgram()); - AppendSwitchesAndArguments(*this, other.argv()); + AppendSwitchesAndArguments(this, other.argv()); } void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { @@ -385,8 +384,8 @@ void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { } #if defined(OS_WIN) -void CommandLine::ParseFromString(const base::string16& command_line) { - base::string16 command_line_string; +void CommandLine::ParseFromString(const string16& command_line) { + string16 command_line_string; TrimWhitespace(command_line, TRIM_ALL, &command_line_string); if (command_line_string.empty()) return; @@ -437,8 +436,7 @@ CommandLine::StringType CommandLine::GetArgumentsStringInternal( #endif params.append(kSwitchValueSeparator + switch_value); } - } - else { + } else { #if defined(OS_WIN) arg = QuoteForCommandLineToArgvW(arg, quote_placeholders); #endif diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc index b511d3c..e254232 100644 --- a/base/files/file_util_win.cc +++ b/base/files/file_util_win.cc @@ -480,7 +480,7 @@ bool DevicePathToDriveLetterPath(const FilePath& nt_device_path, } // Move to the next drive letter string, which starts one // increment after the '\0' that terminates the current string. - while (*drive_map_ptr++); + while (*drive_map_ptr++) {} } // No drive matched. The path does not start with a device junction @@ -496,7 +496,7 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { // code below to a call to GetFinalPathNameByHandle(). The method this // function uses is explained in the following msdn article: // http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx - base::win::ScopedHandle file_handle( + win::ScopedHandle file_handle( ::CreateFile(path.value().c_str(), GENERIC_READ, kFileShareAll, @@ -510,7 +510,7 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { // Create a file mapping object. Can't easily use MemoryMappedFile, because // we only map the first byte, and need direct access to the handle. You can // not map an empty file, this call fails in that case. - base::win::ScopedHandle file_map_handle( + win::ScopedHandle file_map_handle( ::CreateFileMapping(file_handle.Get(), NULL, PAGE_READONLY, @@ -575,7 +575,7 @@ bool GetFileInfo(const FilePath& file_path, File::Info* results) { FILE* OpenFile(const FilePath& filename, const char* mode) { ThreadRestrictions::AssertIOAllowed(); - std::wstring w_mode = ASCIIToWide(std::string(mode)); + string16 w_mode = ASCIIToUTF16(mode); return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); } @@ -595,13 +595,13 @@ FILE* FileToFILE(File file, const char* mode) { int ReadFile(const FilePath& filename, char* data, int max_size) { ThreadRestrictions::AssertIOAllowed(); - base::win::ScopedHandle file(CreateFile(filename.value().c_str(), - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_SEQUENTIAL_SCAN, - NULL)); + win::ScopedHandle file(CreateFile(filename.value().c_str(), + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_SEQUENTIAL_SCAN, + NULL)); if (!file.IsValid()) return -1; @@ -614,13 +614,13 @@ int ReadFile(const FilePath& filename, char* data, int max_size) { int WriteFile(const FilePath& filename, const char* data, int size) { ThreadRestrictions::AssertIOAllowed(); - base::win::ScopedHandle file(CreateFile(filename.value().c_str(), - GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - 0, - NULL)); + win::ScopedHandle file(CreateFile(filename.value().c_str(), + GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + 0, + NULL)); if (!file.IsValid()) { DPLOG(WARNING) << "CreateFile failed for path " << UTF16ToUTF8(filename.value()); @@ -646,13 +646,13 @@ int WriteFile(const FilePath& filename, const char* data, int size) { bool AppendToFile(const FilePath& filename, const char* data, int size) { ThreadRestrictions::AssertIOAllowed(); - base::win::ScopedHandle file(CreateFile(filename.value().c_str(), - FILE_APPEND_DATA, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL)); + win::ScopedHandle file(CreateFile(filename.value().c_str(), + FILE_APPEND_DATA, + 0, + NULL, + OPEN_EXISTING, + 0, + NULL)); if (!file.IsValid()) { VPLOG(1) << "CreateFile failed for path " << UTF16ToUTF8(filename.value()); return false; diff --git a/base/memory/shared_memory_win.cc b/base/memory/shared_memory_win.cc index eef7f03..5d2fa2a 100644 --- a/base/memory/shared_memory_win.cc +++ b/base/memory/shared_memory_win.cc @@ -118,8 +118,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { return false; size_t rounded_size = (options.size + kSectionMask) & ~kSectionMask; - name_ = ASCIIToWide(options.name_deprecated == NULL ? "" : - *options.name_deprecated); + name_ = options.name_deprecated ? + ASCIIToUTF16(*options.name_deprecated) : L""; SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, FALSE }; SECURITY_DESCRIPTOR sd; ACL dacl; @@ -137,10 +137,10 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { // Windows ignores DACLs on certain unnamed objects (like shared sections). // So, we generate a random name when we need to enforce read-only. uint64_t rand_values[4]; - base::RandBytes(&rand_values, sizeof(rand_values)); - name_ = base::StringPrintf(L"CrSharedMem_%016x%016x%016x%016x", - rand_values[0], rand_values[1], - rand_values[2], rand_values[3]); + RandBytes(&rand_values, sizeof(rand_values)); + name_ = StringPrintf(L"CrSharedMem_%016x%016x%016x%016x", + rand_values[0], rand_values[1], + rand_values[2], rand_values[3]); } mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), name_.c_str()); @@ -171,7 +171,7 @@ bool SharedMemory::Delete(const std::string& name) { bool SharedMemory::Open(const std::string& name, bool read_only) { DCHECK(!mapped_file_); - name_ = ASCIIToWide(name); + name_ = ASCIIToUTF16(name); read_only_ = read_only; mapped_file_ = OpenFileMapping( read_only_ ? FILE_MAP_READ : FILE_MAP_READ | FILE_MAP_WRITE, @@ -218,7 +218,7 @@ bool SharedMemory::Unmap() { } bool SharedMemory::ShareToProcessCommon(ProcessHandle process, - SharedMemoryHandle *new_handle, + SharedMemoryHandle* new_handle, bool close_self, ShareMode share_mode) { *new_handle = 0; diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc index 0d3eba9..707a4d7 100644 --- a/base/test/launcher/test_launcher.cc +++ b/base/test/launcher/test_launcher.cc @@ -228,7 +228,7 @@ CommandLine PrepareCommandLineForGTest(const CommandLine& command_line, // on a CommandLine with a wrapper is known to break. // TODO(phajdan.jr): Give it a try to support CommandLine removing switches. #if defined(OS_WIN) - new_command_line.PrependWrapper(ASCIIToWide(wrapper)); + new_command_line.PrependWrapper(ASCIIToUTF16(wrapper)); #elif defined(OS_POSIX) new_command_line.PrependWrapper(wrapper); #endif @@ -242,7 +242,7 @@ CommandLine PrepareCommandLineForGTest(const CommandLine& command_line, int LaunchChildTestProcessWithOptions(const CommandLine& command_line, const LaunchOptions& options, int flags, - base::TimeDelta timeout, + TimeDelta timeout, bool* was_timeout) { #if defined(OS_POSIX) // Make sure an option we rely on is present - see LaunchChildGTestProcess. @@ -287,7 +287,7 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line, new_options.allow_new_privs = true; #endif - base::ProcessHandle process_handle; + ProcessHandle process_handle; { // Note how we grab the lock before the process possibly gets created. @@ -295,21 +295,19 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line, // in the set. AutoLock lock(g_live_processes_lock.Get()); - if (!base::LaunchProcess(command_line, new_options, &process_handle)) + if (!LaunchProcess(command_line, new_options, &process_handle)) return -1; g_live_processes.Get().insert(std::make_pair(process_handle, command_line)); } int exit_code = 0; - if (!base::WaitForExitCodeWithTimeout(process_handle, - &exit_code, - timeout)) { + if (!WaitForExitCodeWithTimeout(process_handle, &exit_code, timeout)) { *was_timeout = true; exit_code = -1; // Set a non-zero exit code to signal a failure. // Ensure that the process terminates. - base::KillProcess(process_handle, -1, true); + KillProcess(process_handle, -1, true); } { @@ -324,14 +322,14 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line, // or due to it timing out, we need to clean up any child processes that // it might have created. On Windows, child processes are automatically // cleaned up using JobObjects. - base::KillProcessGroup(process_handle); + KillProcessGroup(process_handle); } #endif g_live_processes.Get().erase(process_handle); } - base::CloseProcessHandle(process_handle); + CloseProcessHandle(process_handle); return exit_code; } @@ -347,7 +345,7 @@ void RunCallback( void DoLaunchChildTestProcess( const CommandLine& command_line, - base::TimeDelta timeout, + TimeDelta timeout, int flags, bool redirect_stdio, scoped_refptr<MessageLoopProxy> message_loop_proxy, @@ -355,8 +353,8 @@ void DoLaunchChildTestProcess( TimeTicks start_time = TimeTicks::Now(); // Redirect child process output to a file. - base::FilePath output_file; - CHECK(base::CreateTemporaryFile(&output_file)); + FilePath output_file; + CHECK(CreateTemporaryFile(&output_file)); LaunchOptions options; #if defined(OS_WIN) @@ -385,8 +383,8 @@ void DoLaunchChildTestProcess( #elif defined(OS_POSIX) options.new_process_group = true; - base::FileHandleMappingVector fds_mapping; - base::ScopedFD output_file_fd; + FileHandleMappingVector fds_mapping; + ScopedFD output_file_fd; if (redirect_stdio) { output_file_fd.reset(open(output_file.value().c_str(), O_RDWR)); @@ -412,9 +410,9 @@ void DoLaunchChildTestProcess( } std::string output_file_contents; - CHECK(base::ReadFileToString(output_file, &output_file_contents)); + CHECK(ReadFileToString(output_file, &output_file_contents)); - if (!base::DeleteFile(output_file, false)) { + if (!DeleteFile(output_file, false)) { // This needs to be non-fatal at least for Windows. LOG(WARNING) << "Failed to delete " << output_file.AsUTF8Unsafe(); } @@ -519,7 +517,7 @@ bool TestLauncher::Run() { void TestLauncher::LaunchChildGTestProcess( const CommandLine& command_line, const std::string& wrapper, - base::TimeDelta timeout, + TimeDelta timeout, int flags, const LaunchChildGTestProcessCallback& callback) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -945,10 +943,8 @@ void TestLauncher::RunTests() { if (excluded) continue; - if (base::Hash(test_name) % total_shards_ != - static_cast<uint32>(shard_index_)) { + if (Hash(test_name) % total_shards_ != static_cast<uint32>(shard_index_)) continue; - } test_names.push_back(test_name); } diff --git a/base/test/test_reg_util_win.cc b/base/test/test_reg_util_win.cc index 2cbafef..e3b1ffc 100644 --- a/base/test/test_reg_util_win.cc +++ b/base/test/test_reg_util_win.cc @@ -54,7 +54,7 @@ base::string16 GenerateTempKeyPath(const base::string16& test_key_root, const base::Time& timestamp) { base::string16 key_path = test_key_root; key_path += L"\\" + base::Int64ToString16(timestamp.ToInternalValue()); - key_path += kTimestampDelimiter + base::ASCIIToWide(base::GenerateGUID()); + key_path += kTimestampDelimiter + base::ASCIIToUTF16(base::GenerateGUID()); return key_path; } diff --git a/content/common/dwrite_font_platform_win.cc b/content/common/dwrite_font_platform_win.cc index 7479c67..3981ff2 100644 --- a/content/common/dwrite_font_platform_win.cc +++ b/content/common/dwrite_font_platform_win.cc @@ -85,8 +85,8 @@ const double kArbitraryCacheFileSizeLimit = (20 * 1024 * 1024); const unsigned int kMaxFontFileNameLength = 34; const DWORD kCacheFileVersion = 101; -const DWORD kFileSignature = 0x4D4F5243; // CROM -const DWORD kMagicCompletionSignature = 0x454E4F44; // DONE +const DWORD kFileSignature = 0x4D4F5243; // CROM +const DWORD kMagicCompletionSignature = 0x454E4F44; // DONE const DWORD kUndefinedDWORDS = 36; @@ -151,7 +151,7 @@ class FontCollectionLoader public: FontCollectionLoader() : in_collection_building_mode_(false), - create_static_cache_(false) {}; + create_static_cache_(false) {} virtual ~FontCollectionLoader(); @@ -308,7 +308,7 @@ class FontCacheWriter { int bytes_written = static_cache_->Write(0, reinterpret_cast<const char*>(&header), sizeof(header)); - DCHECK(bytes_written != -1); + DCHECK_NE(bytes_written, -1); UMA_HISTOGRAM_MEMORY_KB("DirectWrite.Fonts.BuildCache.File.Size", static_cache_->GetLength() / 1024); @@ -562,7 +562,7 @@ class FontFileStream } FontFileStream::FontFileStream() : font_key_(0), cached_data_(false) { - }; + } HRESULT RuntimeClassInitialize(UINT32 font_key) { if (g_font_loader->InCollectionBuildingMode() && @@ -645,7 +645,6 @@ class FontFileLoader virtual ~FontFileLoader() {} private: - DISALLOW_COPY_AND_ASSIGN(FontFileLoader); }; @@ -699,7 +698,6 @@ class FontFileEnumerator UINT32 font_idx_; private: - DISALLOW_COPY_AND_ASSIGN(FontFileEnumerator); }; @@ -1160,15 +1158,15 @@ bool LoadFontCache(const base::FilePath& path) { if (!ValidateFontCacheFile(file.get())) return false; - std::string name(content::kFontCacheSharedSectionName); - name.append(base::UintToString(base::GetCurrentProcId())); + base::string16 name(base::ASCIIToUTF16(content::kFontCacheSharedSectionName)); + name.append(base::UintToString16(base::GetCurrentProcId())); HANDLE mapping = ::CreateFileMapping( file->GetPlatformFile(), NULL, PAGE_READONLY, 0, 0, - base::ASCIIToWide(name).c_str()); + name.c_str()); if (mapping == INVALID_HANDLE_VALUE) return false; diff --git a/courgette/encoded_program.cc b/courgette/encoded_program.cc index b120246..f198a1b 100644 --- a/courgette/encoded_program.cc +++ b/courgette/encoded_program.cc @@ -12,8 +12,8 @@ #include "base/environment.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" #include "courgette/courgette.h" #include "courgette/disassembler_elf_32_arm.h" #include "courgette/streams.h" @@ -292,17 +292,14 @@ enum FieldSelect { }; static FieldSelect GetFieldSelect() { -#if 1 // TODO(sra): Use better configuration. scoped_ptr<base::Environment> env(base::Environment::Create()); std::string s; env->GetVar("A_FIELDS", &s); - if (!s.empty()) { - return static_cast<FieldSelect>( - wcstoul(base::ASCIIToWide(s).c_str(), 0, 0)); - } -#endif - return static_cast<FieldSelect>(~0); + uint64 fields; + if (!base::StringToUint64(s, &fields)) + return static_cast<FieldSelect>(~0); + return static_cast<FieldSelect>(fields); } CheckBool EncodedProgram::WriteTo(SinkStreamSet* streams) { @@ -746,7 +743,7 @@ CheckBool EncodedProgram::GeneratePeRelocations(SinkStream* buffer, block.pod.page_rva = page_rva; } if (ok) - block.Add(((static_cast<uint16>(type)) << 12 ) | (rva & 0xFFF)); + block.Add(((static_cast<uint16>(type)) << 12) | (rva & 0xFFF)); } ok &= block.Flush(buffer); return ok; @@ -797,4 +794,4 @@ void DeleteEncodedProgram(EncodedProgram* encoded) { delete encoded; } -} // end namespace +} // namespace courgette |