Various fixes for the Windows build Change-Id: I4c52923c71966e0254f27ccf1c88886cb62750d8 Reviewed-on: https://gn-review.googlesource.com/1560 Commit-Queue: Scott Graham <scottmg@chromium.org> Reviewed-by: Brett Wilson <brettw@chromium.org>
diff --git a/base/files/file_proxy.cc b/base/files/file_proxy.cc deleted file mode 100644 index f16e594..0000000 --- a/base/files/file_proxy.cc +++ /dev/null
@@ -1,358 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/files/file_proxy.h" - -#include <utility> - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/files/file.h" -#include "base/files/file_util.h" -#include "base/location.h" -#include "base/macros.h" -#include "base/task_runner.h" -#include "base/task_runner_util.h" - -namespace { - -void FileDeleter(base::File file) { -} - -} // namespace - -namespace base { - -class FileHelper { - public: - FileHelper(FileProxy* proxy, File file) - : file_(std::move(file)), - error_(File::FILE_ERROR_FAILED), - task_runner_(proxy->task_runner()), - proxy_(AsWeakPtr(proxy)) { - } - - void PassFile() { - if (proxy_) - proxy_->SetFile(std::move(file_)); - else if (file_.IsValid()) - task_runner_->PostTask(FROM_HERE, - BindOnce(&FileDeleter, std::move(file_))); - } - - protected: - File file_; - File::Error error_; - - private: - scoped_refptr<TaskRunner> task_runner_; - WeakPtr<FileProxy> proxy_; - DISALLOW_COPY_AND_ASSIGN(FileHelper); -}; - -namespace { - -class GenericFileHelper : public FileHelper { - public: - GenericFileHelper(FileProxy* proxy, File file) - : FileHelper(proxy, std::move(file)) { - } - - void Close() { - file_.Close(); - error_ = File::FILE_OK; - } - - void SetTimes(Time last_access_time, Time last_modified_time) { - bool rv = file_.SetTimes(last_access_time, last_modified_time); - error_ = rv ? File::FILE_OK : File::FILE_ERROR_FAILED; - } - - void SetLength(int64_t length) { - if (file_.SetLength(length)) - error_ = File::FILE_OK; - } - - void Flush() { - if (file_.Flush()) - error_ = File::FILE_OK; - } - - void Reply(FileProxy::StatusCallback callback) { - PassFile(); - if (!callback.is_null()) - std::move(callback).Run(error_); - } - - private: - DISALLOW_COPY_AND_ASSIGN(GenericFileHelper); -}; - -class CreateOrOpenHelper : public FileHelper { - public: - CreateOrOpenHelper(FileProxy* proxy, File file) - : FileHelper(proxy, std::move(file)) { - } - - void RunWork(const FilePath& file_path, int file_flags) { - file_.Initialize(file_path, file_flags); - error_ = file_.IsValid() ? File::FILE_OK : file_.error_details(); - } - - void Reply(FileProxy::StatusCallback callback) { - DCHECK(!callback.is_null()); - PassFile(); - std::move(callback).Run(error_); - } - - private: - DISALLOW_COPY_AND_ASSIGN(CreateOrOpenHelper); -}; - -class CreateTemporaryHelper : public FileHelper { - public: - CreateTemporaryHelper(FileProxy* proxy, File file) - : FileHelper(proxy, std::move(file)) { - } - - void RunWork(uint32_t additional_file_flags) { - // TODO(darin): file_util should have a variant of CreateTemporaryFile - // that returns a FilePath and a File. - if (!CreateTemporaryFile(&file_path_)) { - // TODO(davidben): base::CreateTemporaryFile should preserve the error - // code. - error_ = File::FILE_ERROR_FAILED; - return; - } - - uint32_t file_flags = File::FLAG_WRITE | File::FLAG_TEMPORARY | - File::FLAG_CREATE_ALWAYS | additional_file_flags; - - file_.Initialize(file_path_, file_flags); - if (file_.IsValid()) { - error_ = File::FILE_OK; - } else { - error_ = file_.error_details(); - DeleteFile(file_path_, false); - file_path_.clear(); - } - } - - void Reply(FileProxy::CreateTemporaryCallback callback) { - DCHECK(!callback.is_null()); - PassFile(); - std::move(callback).Run(error_, file_path_); - } - - private: - FilePath file_path_; - DISALLOW_COPY_AND_ASSIGN(CreateTemporaryHelper); -}; - -class GetInfoHelper : public FileHelper { - public: - GetInfoHelper(FileProxy* proxy, File file) - : FileHelper(proxy, std::move(file)) { - } - - void RunWork() { - if (file_.GetInfo(&file_info_)) - error_ = File::FILE_OK; - } - - void Reply(FileProxy::GetFileInfoCallback callback) { - PassFile(); - DCHECK(!callback.is_null()); - std::move(callback).Run(error_, file_info_); - } - - private: - File::Info file_info_; - DISALLOW_COPY_AND_ASSIGN(GetInfoHelper); -}; - -class ReadHelper : public FileHelper { - public: - ReadHelper(FileProxy* proxy, File file, int bytes_to_read) - : FileHelper(proxy, std::move(file)), - buffer_(new char[bytes_to_read]), - bytes_to_read_(bytes_to_read), - bytes_read_(0) { - } - - void RunWork(int64_t offset) { - bytes_read_ = file_.Read(offset, buffer_.get(), bytes_to_read_); - error_ = (bytes_read_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK; - } - - void Reply(FileProxy::ReadCallback callback) { - PassFile(); - DCHECK(!callback.is_null()); - std::move(callback).Run(error_, buffer_.get(), bytes_read_); - } - - private: - std::unique_ptr<char[]> buffer_; - int bytes_to_read_; - int bytes_read_; - DISALLOW_COPY_AND_ASSIGN(ReadHelper); -}; - -class WriteHelper : public FileHelper { - public: - WriteHelper(FileProxy* proxy, - File file, - const char* buffer, int bytes_to_write) - : FileHelper(proxy, std::move(file)), - buffer_(new char[bytes_to_write]), - bytes_to_write_(bytes_to_write), - bytes_written_(0) { - memcpy(buffer_.get(), buffer, bytes_to_write); - } - - void RunWork(int64_t offset) { - bytes_written_ = file_.Write(offset, buffer_.get(), bytes_to_write_); - error_ = (bytes_written_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK; - } - - void Reply(FileProxy::WriteCallback callback) { - PassFile(); - if (!callback.is_null()) - std::move(callback).Run(error_, bytes_written_); - } - - private: - std::unique_ptr<char[]> buffer_; - int bytes_to_write_; - int bytes_written_; - DISALLOW_COPY_AND_ASSIGN(WriteHelper); -}; - -} // namespace - -FileProxy::FileProxy(TaskRunner* task_runner) : task_runner_(task_runner) { -} - -FileProxy::~FileProxy() { - if (file_.IsValid()) - task_runner_->PostTask(FROM_HERE, BindOnce(&FileDeleter, std::move(file_))); -} - -bool FileProxy::CreateOrOpen(const FilePath& file_path, - uint32_t file_flags, - StatusCallback callback) { - DCHECK(!file_.IsValid()); - CreateOrOpenHelper* helper = new CreateOrOpenHelper(this, File()); - return task_runner_->PostTaskAndReply( - FROM_HERE, - BindOnce(&CreateOrOpenHelper::RunWork, Unretained(helper), file_path, - file_flags), - BindOnce(&CreateOrOpenHelper::Reply, Owned(helper), std::move(callback))); -} - -bool FileProxy::CreateTemporary(uint32_t additional_file_flags, - CreateTemporaryCallback callback) { - DCHECK(!file_.IsValid()); - CreateTemporaryHelper* helper = new CreateTemporaryHelper(this, File()); - return task_runner_->PostTaskAndReply( - FROM_HERE, - BindOnce(&CreateTemporaryHelper::RunWork, Unretained(helper), - additional_file_flags), - BindOnce(&CreateTemporaryHelper::Reply, Owned(helper), - std::move(callback))); -} - -bool FileProxy::IsValid() const { - return file_.IsValid(); -} - -void FileProxy::SetFile(File file) { - DCHECK(!file_.IsValid()); - file_ = std::move(file); -} - -File FileProxy::TakeFile() { - return std::move(file_); -} - -File FileProxy::DuplicateFile() { - return file_.Duplicate(); -} - -PlatformFile FileProxy::GetPlatformFile() const { - return file_.GetPlatformFile(); -} - -bool FileProxy::Close(StatusCallback callback) { - DCHECK(file_.IsValid()); - GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); - return task_runner_->PostTaskAndReply( - FROM_HERE, BindOnce(&GenericFileHelper::Close, Unretained(helper)), - BindOnce(&GenericFileHelper::Reply, Owned(helper), std::move(callback))); -} - -bool FileProxy::GetInfo(GetFileInfoCallback callback) { - DCHECK(file_.IsValid()); - GetInfoHelper* helper = new GetInfoHelper(this, std::move(file_)); - return task_runner_->PostTaskAndReply( - FROM_HERE, BindOnce(&GetInfoHelper::RunWork, Unretained(helper)), - BindOnce(&GetInfoHelper::Reply, Owned(helper), std::move(callback))); -} - -bool FileProxy::Read(int64_t offset, int bytes_to_read, ReadCallback callback) { - DCHECK(file_.IsValid()); - if (bytes_to_read < 0) - return false; - - ReadHelper* helper = new ReadHelper(this, std::move(file_), bytes_to_read); - return task_runner_->PostTaskAndReply( - FROM_HERE, BindOnce(&ReadHelper::RunWork, Unretained(helper), offset), - BindOnce(&ReadHelper::Reply, Owned(helper), std::move(callback))); -} - -bool FileProxy::Write(int64_t offset, - const char* buffer, - int bytes_to_write, - WriteCallback callback) { - DCHECK(file_.IsValid()); - if (bytes_to_write <= 0 || buffer == nullptr) - return false; - - WriteHelper* helper = - new WriteHelper(this, std::move(file_), buffer, bytes_to_write); - return task_runner_->PostTaskAndReply( - FROM_HERE, BindOnce(&WriteHelper::RunWork, Unretained(helper), offset), - BindOnce(&WriteHelper::Reply, Owned(helper), std::move(callback))); -} - -bool FileProxy::SetTimes(Time last_access_time, - Time last_modified_time, - StatusCallback callback) { - DCHECK(file_.IsValid()); - GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); - return task_runner_->PostTaskAndReply( - FROM_HERE, - BindOnce(&GenericFileHelper::SetTimes, Unretained(helper), - last_access_time, last_modified_time), - BindOnce(&GenericFileHelper::Reply, Owned(helper), std::move(callback))); -} - -bool FileProxy::SetLength(int64_t length, StatusCallback callback) { - DCHECK(file_.IsValid()); - GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); - return task_runner_->PostTaskAndReply( - FROM_HERE, - BindOnce(&GenericFileHelper::SetLength, Unretained(helper), length), - BindOnce(&GenericFileHelper::Reply, Owned(helper), std::move(callback))); -} - -bool FileProxy::Flush(StatusCallback callback) { - DCHECK(file_.IsValid()); - GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); - return task_runner_->PostTaskAndReply( - FROM_HERE, BindOnce(&GenericFileHelper::Flush, Unretained(helper)), - BindOnce(&GenericFileHelper::Reply, Owned(helper), std::move(callback))); -} - -} // namespace base
diff --git a/base/files/file_proxy.h b/base/files/file_proxy.h deleted file mode 100644 index d17e4d3..0000000 --- a/base/files/file_proxy.h +++ /dev/null
@@ -1,142 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_FILES_FILE_PROXY_H_ -#define BASE_FILES_FILE_PROXY_H_ - -#include <stdint.h> - -#include "base/base_export.h" -#include "base/callback_forward.h" -#include "base/files/file.h" -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" - -namespace base { - -class TaskRunner; -class Time; - -// This class provides asynchronous access to a File. All methods follow the -// same rules of the equivalent File method, as they are implemented by bouncing -// the operation to File using a TaskRunner. -// -// This class performs automatic proxying to close the underlying file at -// destruction. -// -// The TaskRunner is in charge of any sequencing of the operations, but a single -// operation can be proxied at a time, regardless of the use of a callback. -// In other words, having a sequence like -// -// proxy.Write(...); -// proxy.Write(...); -// -// means the second Write will always fail. -class BASE_EXPORT FileProxy : public SupportsWeakPtr<FileProxy> { - public: - // This callback is used by methods that report only an error code. It is - // valid to pass a null callback to some functions that takes a - // StatusCallback, in which case the operation will complete silently. - using StatusCallback = OnceCallback<void(File::Error)>; - using CreateTemporaryCallback = - OnceCallback<void(File::Error, const FilePath&)>; - using GetFileInfoCallback = - OnceCallback<void(File::Error, const File::Info&)>; - using ReadCallback = - OnceCallback<void(File::Error, const char* data, int bytes_read)>; - using WriteCallback = OnceCallback<void(File::Error, int bytes_written)>; - - FileProxy(); - explicit FileProxy(TaskRunner* task_runner); - ~FileProxy(); - - // Creates or opens a file with the given flags. It is invalid to pass a null - // callback. If File::FLAG_CREATE is set in |file_flags| it always tries to - // create a new file at the given |file_path| and fails if the file already - // exists. - // - // This returns false if task posting to |task_runner| has failed. - bool CreateOrOpen(const FilePath& file_path, - uint32_t file_flags, - StatusCallback callback); - - // Creates a temporary file for writing. The path and an open file are - // returned. It is invalid to pass a null callback. The additional file flags - // will be added on top of the default file flags which are: - // File::FLAG_CREATE_ALWAYS - // File::FLAG_WRITE - // File::FLAG_TEMPORARY. - // - // This returns false if task posting to |task_runner| has failed. - bool CreateTemporary(uint32_t additional_file_flags, - CreateTemporaryCallback callback); - - // Returns true if the underlying |file_| is valid. - bool IsValid() const; - - // Returns true if a new file was created (or an old one truncated to zero - // length to simulate a new file), and false otherwise. - bool created() const { return file_.created(); } - - // Claims ownership of |file|. It is an error to call this method when - // IsValid() returns true. - void SetFile(File file); - - File TakeFile(); - - // Returns a new File object that is a duplicate of the underlying |file_|. - // See the comment at File::Duplicate for caveats. - File DuplicateFile(); - - PlatformFile GetPlatformFile() const; - - // Proxies File::Close. The callback can be null. - // This returns false if task posting to |task_runner| has failed. - bool Close(StatusCallback callback); - - // Proxies File::GetInfo. The callback can't be null. - // This returns false if task posting to |task_runner| has failed. - bool GetInfo(GetFileInfoCallback callback); - - // Proxies File::Read. The callback can't be null. - // This returns false if |bytes_to_read| is less than zero, or - // if task posting to |task_runner| has failed. - bool Read(int64_t offset, int bytes_to_read, ReadCallback callback); - - // Proxies File::Write. The callback can be null. - // This returns false if |bytes_to_write| is less than or equal to zero, - // if |buffer| is NULL, or if task posting to |task_runner| has failed. - bool Write(int64_t offset, - const char* buffer, - int bytes_to_write, - WriteCallback callback); - - // Proxies File::SetTimes. The callback can be null. - // This returns false if task posting to |task_runner| has failed. - bool SetTimes(Time last_access_time, - Time last_modified_time, - StatusCallback callback); - - // Proxies File::SetLength. The callback can be null. - // This returns false if task posting to |task_runner| has failed. - bool SetLength(int64_t length, StatusCallback callback); - - // Proxies File::Flush. The callback can be null. - // This returns false if task posting to |task_runner| has failed. - bool Flush(StatusCallback callback); - - private: - friend class FileHelper; - TaskRunner* task_runner() { return task_runner_.get(); } - - scoped_refptr<TaskRunner> task_runner_; - File file_; - DISALLOW_COPY_AND_ASSIGN(FileProxy); -}; - -} // namespace base - -#endif // BASE_FILES_FILE_PROXY_H_
diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc index 1f95001..23b3e26 100644 --- a/base/files/file_util_win.cc +++ b/base/files/file_util_win.cc
@@ -20,15 +20,14 @@ #include "base/files/file_enumerator.h" #include "base/files/file_path.h" -#include "base/guid.h" #include "base/logging.h" #include "base/macros.h" -#include "base/metrics/histogram_functions.h" #include "base/process/process_handle.h" #include "base/rand_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" #include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" #include "base/time/time.h" @@ -42,67 +41,6 @@ const DWORD kFileShareAll = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; -// Records a sample in a histogram named -// "Windows.PostOperationState.|operation|" indicating the state of |path| -// following the named operation. If |operation_succeeded| is true, the -// "operation succeeded" sample is recorded. Otherwise, the state of |path| is -// queried and the most meaningful sample is recorded. -void RecordPostOperationState(const FilePath& path, - StringPiece operation, - bool operation_succeeded) { - // The state of a filesystem item after an operation. - // These values are persisted to logs. Entries should not be renumbered and - // numeric values should never be reused. - enum class PostOperationState { - kOperationSucceeded = 0, - kFileNotFoundAfterFailure = 1, - kPathNotFoundAfterFailure = 2, - kAccessDeniedAfterFailure = 3, - kNoAttributesAfterFailure = 4, - kEmptyDirectoryAfterFailure = 5, - kNonEmptyDirectoryAfterFailure = 6, - kNotDirectoryAfterFailure = 7, - kCount - } metric = PostOperationState::kOperationSucceeded; - - if (!operation_succeeded) { - const DWORD attributes = ::GetFileAttributes(path.value().c_str()); - if (attributes == INVALID_FILE_ATTRIBUTES) { - // On failure to delete, one might expect the file/directory to still be - // in place. Slice a failure to get its attributes into a few common error - // buckets. - const DWORD error_code = ::GetLastError(); - if (error_code == ERROR_FILE_NOT_FOUND) - metric = PostOperationState::kFileNotFoundAfterFailure; - else if (error_code == ERROR_PATH_NOT_FOUND) - metric = PostOperationState::kPathNotFoundAfterFailure; - else if (error_code == ERROR_ACCESS_DENIED) - metric = PostOperationState::kAccessDeniedAfterFailure; - else - metric = PostOperationState::kNoAttributesAfterFailure; - } else if (attributes & FILE_ATTRIBUTE_DIRECTORY) { - if (IsDirectoryEmpty(path)) - metric = PostOperationState::kEmptyDirectoryAfterFailure; - else - metric = PostOperationState::kNonEmptyDirectoryAfterFailure; - } else { - metric = PostOperationState::kNotDirectoryAfterFailure; - } - } - - std::string histogram_name = "Windows.PostOperationState."; - operation.AppendToString(&histogram_name); - UmaHistogramEnumeration(histogram_name, metric, PostOperationState::kCount); -} - -// Records the sample |error| in a histogram named -// "Windows.FilesystemError.|operation|". -void RecordFilesystemError(StringPiece operation, DWORD error) { - std::string histogram_name = "Windows.FilesystemError."; - operation.AppendToString(&histogram_name); - UmaHistogramSparse(histogram_name, error); -} - // Deletes all files and directories in a path. // Returns ERROR_SUCCESS on success or the Windows error code corresponding to // the first error encountered. @@ -322,6 +260,37 @@ : ::GetLastError(); } +std::string RandomDataToGUIDString(const uint64_t bytes[2]) { + return base::StringPrintf( + "%08x-%04x-%04x-%04x-%012llx", static_cast<unsigned int>(bytes[0] >> 32), + static_cast<unsigned int>((bytes[0] >> 16) & 0x0000ffff), + static_cast<unsigned int>(bytes[0] & 0x0000ffff), + static_cast<unsigned int>(bytes[1] >> 48), + bytes[1] & 0x0000ffff'ffffffffULL); +} + +std::string GenerateGUID() { + uint64_t sixteen_bytes[2]; + // Use base::RandBytes instead of crypto::RandBytes, because crypto calls the + // base version directly, and to prevent the dependency from base/ to crypto/. + base::RandBytes(&sixteen_bytes, sizeof(sixteen_bytes)); + + // Set the GUID to version 4 as described in RFC 4122, section 4.4. + // The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, + // where y is one of [8, 9, A, B]. + + // Clear the version bits and set the version to 4: + sixteen_bytes[0] &= 0xffffffff'ffff0fffULL; + sixteen_bytes[0] |= 0x00000000'00004000ULL; + + // Set the two most significant bits (bits 6 and 7) of the + // clock_seq_hi_and_reserved to zero and one, respectively: + sixteen_bytes[1] &= 0x3fffffff'ffffffffULL; + sixteen_bytes[1] |= 0x80000000'00000000ULL; + + return RandomDataToGUIDString(sixteen_bytes); +} + } // namespace FilePath MakeAbsoluteFilePath(const FilePath& input) { @@ -344,12 +313,7 @@ // current code so that any improvements or regressions resulting from // subsequent code changes can be detected. const DWORD error = DoDeleteFile(path, recursive); - RecordPostOperationState(path, operation, error == ERROR_SUCCESS); - if (error == ERROR_SUCCESS) - return true; - - RecordFilesystemError(operation, error); - return false; + return error == ERROR_SUCCESS; } bool DeleteFileAfterReboot(const FilePath& path) {
diff --git a/base/files/file_win.cc b/base/files/file_win.cc index d7bffc3..46b4b75 100644 --- a/base/files/file_win.cc +++ b/base/files/file_win.cc
@@ -8,7 +8,6 @@ #include <stdint.h> #include "base/logging.h" -#include "base/metrics/histogram_functions.h" #include "base/threading/thread_restrictions.h" #include <windows.h> @@ -313,7 +312,6 @@ case ERROR_DISK_CORRUPT: return FILE_ERROR_IO; default: - UmaHistogramSparse("PlatformFile.UnknownErrors.Windows", last_error); // This function should only be called for errors. DCHECK_NE(static_cast<DWORD>(ERROR_SUCCESS), last_error); return FILE_ERROR_FAILED;
diff --git a/base/message_loop/message_pump_win.cc b/base/message_loop/message_pump_win.cc index af0c7db..d278ffc 100644 --- a/base/message_loop/message_pump_win.cc +++ b/base/message_loop/message_pump_win.cc
@@ -9,8 +9,8 @@ #include <limits> +#include "base/bind.h" #include "base/memory/ptr_util.h" -#include "base/metrics/histogram_macros.h" #include "base/strings/stringprintf.h" #include "base/win/current_module.h" #include "base/win/wrapped_window_proc.h" @@ -114,8 +114,6 @@ // Clarify that we didn't really insert. InterlockedExchange(&work_state_, READY); - UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", MESSAGE_POST_ERROR, - MESSAGE_LOOP_PROBLEM_MAX); state_->schedule_work_error_count++; state_->last_schedule_work_error_time = Time::Now(); } @@ -315,11 +313,6 @@ UINT_PTR ret = SetTimer(message_window_.hwnd(), 0, delay_msec, nullptr); if (ret) return; - // If we can't set timers, we are in big trouble... but cross our fingers - // for now. - // TODO(jar): If we don't see this error, use a CHECK() here instead. - UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR, - MESSAGE_LOOP_PROBLEM_MAX); } } @@ -345,8 +338,6 @@ // WM_QUIT is the standard way to exit a GetMessage() loop. Our MessageLoop // has its own quit mechanism, so WM_QUIT is unexpected and should be // ignored. - UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", - RECEIVED_WM_QUIT_ERROR, MESSAGE_LOOP_PROBLEM_MAX); return true; } @@ -422,8 +413,6 @@ // See comment in MessagePumpForUI::ScheduleWork() for this error recovery. InterlockedExchange(&work_state_, READY); // Clarify that we didn't succeed. - UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", COMPLETION_POST_ERROR, - MESSAGE_LOOP_PROBLEM_MAX); state_->schedule_work_error_count++; state_->last_schedule_work_error_time = Time::Now(); }
diff --git a/base/process/launch_win.cc b/base/process/launch_win.cc index 3ee81b1..839db17 100644 --- a/base/process/launch_win.cc +++ b/base/process/launch_win.cc
@@ -18,7 +18,6 @@ #include "base/bind_helpers.h" #include "base/command_line.h" #include "base/logging.h" -#include "base/metrics/histogram.h" #include "base/process/kill.h" #include "base/strings/utf_string_conversions.h" #include "base/sys_info.h" @@ -87,10 +86,6 @@ } base::win::ScopedProcessInformation proc_info(temp_process_info); - base::debug::GlobalActivityTracker* tracker = - base::debug::GlobalActivityTracker::Get(); - if (tracker) - tracker->RecordProcessLaunch(proc_info.process_id(), cl.as_string()); // Close our writing end of pipe now. Otherwise later read would not be able // to detect end of child's output. @@ -114,8 +109,6 @@ base::TerminationStatus status = GetTerminationStatus( proc_info.process_handle(), exit_code); - base::debug::GlobalActivityTracker::RecordProcessExitIfEnabled( - proc_info.process_id(), *exit_code); return status != base::TERMINATION_STATUS_PROCESS_CRASHED && status != base::TERMINATION_STATUS_ABNORMAL_TERMINATION; } @@ -328,8 +321,6 @@ if (options.wait) WaitForSingleObject(process_info.process_handle(), INFINITE); - base::debug::GlobalActivityTracker::RecordProcessLaunchIfEnabled( - process_info.process_id(), cmdline); return Process(process_info.TakeProcessHandle()); } @@ -357,8 +348,6 @@ if (options.wait) WaitForSingleObject(shex_info.hProcess, INFINITE); - base::debug::GlobalActivityTracker::RecordProcessLaunchIfEnabled( - GetProcessId(shex_info.hProcess), file, arguments); return Process(shex_info.hProcess); }
diff --git a/base/process/process_win.cc b/base/process/process_win.cc index 2ef4daf..3763d0f 100644 --- a/base/process/process_win.cc +++ b/base/process/process_win.cc
@@ -167,9 +167,6 @@ if (!timeout.is_zero()) internal::AssertBaseSyncPrimitivesAllowed(); - // Record the event that this thread is blocking upon (for hang diagnosis). - base::debug::ScopedProcessWaitActivity process_activity(this); - // Limit timeout to INFINITE. DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); if (::WaitForSingleObject(Handle(), timeout_ms) != WAIT_OBJECT_0) @@ -187,8 +184,6 @@ } void Process::Exited(int exit_code) const { - base::debug::GlobalActivityTracker::RecordProcessExitIfEnabled(Pid(), - exit_code); } bool Process::IsProcessBackgrounded() const {
diff --git a/base/synchronization/lock_impl_win.cc b/base/synchronization/lock_impl_win.cc index fe9c664..d99dac1 100644 --- a/base/synchronization/lock_impl_win.cc +++ b/base/synchronization/lock_impl_win.cc
@@ -19,18 +19,6 @@ } void LockImpl::Lock() { - // The ScopedLockAcquireActivity below is relatively expensive and so its - // actions can become significant due to the very large number of locks - // that tend to be used throughout the build. To avoid this cost in the - // vast majority of the calls, simply "try" the lock first and only do the - // (tracked) blocking call if that fails. Since "try" itself is a system - // call, and thus also somewhat expensive, don't bother with it unless - // tracking is actually enabled. - if (base::debug::GlobalActivityTracker::IsEnabled()) - if (Try()) - return; - - base::debug::ScopedLockAcquireActivity lock_activity(this); ::AcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&native_handle_)); }
diff --git a/base/synchronization/waitable_event_win.cc b/base/synchronization/waitable_event_win.cc index 60126f2..1ee6c5f 100644 --- a/base/synchronization/waitable_event_win.cc +++ b/base/synchronization/waitable_event_win.cc
@@ -54,8 +54,6 @@ void WaitableEvent::Wait() { internal::AssertBaseSyncPrimitivesAllowed(); ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK); - // Record the event that this thread is blocking upon (for hang diagnosis). - base::debug::ScopedEventWaitActivity event_activity(this); DWORD result = WaitForSingleObject(handle_.Get(), INFINITE); // It is most unexpected that this should ever fail. Help consumers learn @@ -107,8 +105,6 @@ return IsSignaled(); internal::AssertBaseSyncPrimitivesAllowed(); - // Record the event that this thread is blocking upon (for hang diagnosis). - base::debug::ScopedEventWaitActivity event_activity(this); TimeTicks now(TimeTicks::Now()); // TimeTicks takes care of overflow including the cases when wait_delta @@ -121,8 +117,6 @@ return IsSignaled(); internal::AssertBaseSyncPrimitivesAllowed(); - // Record the event that this thread is blocking upon (for hang diagnosis). - base::debug::ScopedEventWaitActivity event_activity(this); TimeTicks now(TimeTicks::Now()); if (end_time <= now) @@ -137,8 +131,6 @@ internal::AssertBaseSyncPrimitivesAllowed(); ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK); - // Record an event (the first) that this thread is blocking upon. - base::debug::ScopedEventWaitActivity event_activity(events[0]); HANDLE handles[MAXIMUM_WAIT_OBJECTS]; CHECK_LE(count, static_cast<size_t>(MAXIMUM_WAIT_OBJECTS))
diff --git a/base/sys_info.h b/base/sys_info.h index 19ed0e4..03fb647 100644 --- a/base/sys_info.h +++ b/base/sys_info.h
@@ -168,7 +168,6 @@ private: FRIEND_TEST_ALL_PREFIXES(SysInfoTest, AmountOfAvailablePhysicalMemory); - FRIEND_TEST_ALL_PREFIXES(debug::SystemMetricsTest, ParseMeminfo); static int64_t AmountOfPhysicalMemoryImpl(); static int64_t AmountOfAvailablePhysicalMemoryImpl();
diff --git a/base/threading/platform_thread_win.cc b/base/threading/platform_thread_win.cc index d45211f..9b72bd5 100644 --- a/base/threading/platform_thread_win.cc +++ b/base/threading/platform_thread_win.cc
@@ -7,7 +7,6 @@ #include <stddef.h> #include "base/logging.h" -#include "base/metrics/histogram_macros.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_id_name_manager.h" #include "base/threading/thread_restrictions.h" @@ -115,8 +114,6 @@ void* thread_handle; { - SCOPED_UMA_HISTOGRAM_TIMER("Windows.CreateThreadTime"); - // Using CreateThread here vs _beginthreadex makes thread creation a bit // faster and doesn't require the loader lock to be available. Our code // will have to work running on CreateThread() threads anyway, since we run @@ -234,9 +231,6 @@ if (!thread_id) last_error = ::GetLastError(); - // Record the event that this thread is blocking upon (for hang diagnosis). - base::debug::ScopedThreadJoinActivity thread_activity(&thread_handle); - // Wait for the thread to exit. It should already have terminated but make // sure this assumption is valid. CHECK_EQ(WAIT_OBJECT_0,
diff --git a/base/timer/hi_res_timer_manager.h b/base/timer/hi_res_timer_manager.h index 8939cd2..13477c0 100644 --- a/base/timer/hi_res_timer_manager.h +++ b/base/timer/hi_res_timer_manager.h
@@ -8,7 +8,6 @@ #include "base/base_export.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/power_monitor/power_observer.h" #include "base/timer/timer.h" #include "build_config.h" @@ -16,15 +15,10 @@ // Ensures that the Windows high resolution timer is only used // when not running on battery power. -class BASE_EXPORT HighResolutionTimerManager : public base::PowerObserver { +class BASE_EXPORT HighResolutionTimerManager { public: HighResolutionTimerManager(); - ~HighResolutionTimerManager() override; - - // base::PowerObserver methods. - void OnPowerStateChange(bool on_battery_power) override; - void OnSuspend() override; - void OnResume() override; + ~HighResolutionTimerManager(); // Returns true if the hi resolution clock could be used right now. bool hi_res_clock_available() const { return hi_res_clock_available_; }
diff --git a/base/timer/hi_res_timer_manager_win.cc b/base/timer/hi_res_timer_manager_win.cc index 5474373..9c3a78e 100644 --- a/base/timer/hi_res_timer_manager_win.cc +++ b/base/timer/hi_res_timer_manager_win.cc
@@ -7,8 +7,6 @@ #include <algorithm> #include "base/atomicops.h" -#include "base/metrics/histogram_macros.h" -#include "base/power_monitor/power_monitor.h" #include "base/task_scheduler/post_task.h" #include "base/time/time.h" @@ -19,8 +17,6 @@ constexpr TimeDelta kUsageSampleInterval = TimeDelta::FromMinutes(10); void ReportHighResolutionTimerUsage() { - UMA_HISTOGRAM_PERCENTAGE("Windows.HighResolutionTimerUsage", - Time::GetHighResolutionTimerUsage()); // Reset usage for the next interval. Time::ResetHighResolutionTimerUsage(); } @@ -29,11 +25,6 @@ HighResolutionTimerManager::HighResolutionTimerManager() : hi_res_clock_available_(false) { - PowerMonitor* power_monitor = PowerMonitor::Get(); - DCHECK(power_monitor != NULL); - power_monitor->AddObserver(this); - UseHiResClock(!power_monitor->IsOnBatteryPower()); - // Start polling the high resolution timer usage. Time::ResetHighResolutionTimerUsage(); timer_.Start(FROM_HERE, kUsageSampleInterval, @@ -41,25 +32,9 @@ } HighResolutionTimerManager::~HighResolutionTimerManager() { - PowerMonitor::Get()->RemoveObserver(this); UseHiResClock(false); } -void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) { - UseHiResClock(!on_battery_power); -} - -void HighResolutionTimerManager::OnSuspend() { - // Stop polling the usage to avoid including the standby time. - timer_.Stop(); -} - -void HighResolutionTimerManager::OnResume() { - // Resume polling the usage. - Time::ResetHighResolutionTimerUsage(); - timer_.Reset(); -} - void HighResolutionTimerManager::UseHiResClock(bool use) { if (use == hi_res_clock_available_) return;
diff --git a/base/win/scoped_handle.cc b/base/win/scoped_handle.cc index 4f54df5..b47183e 100644 --- a/base/win/scoped_handle.cc +++ b/base/win/scoped_handle.cc
@@ -3,37 +3,32 @@ // found in the LICENSE file. #include "base/win/scoped_handle.h" -#include "base/win/scoped_handle_verifier.h" #include "base/win/windows_types.h" +#include <windows.h> + namespace base { namespace win { -using base::win::internal::ScopedHandleVerifier; - // Static. bool HandleTraits::CloseHandle(HANDLE handle) { - return ScopedHandleVerifier::Get()->CloseHandle(handle); + return ::CloseHandle(handle); } // Static. void VerifierTraits::StartTracking(HANDLE handle, const void* owner, const void* pc1, const void* pc2) { - return ScopedHandleVerifier::Get()->StartTracking(handle, owner, pc1, pc2); } // Static. void VerifierTraits::StopTracking(HANDLE handle, const void* owner, const void* pc1, const void* pc2) { - return ScopedHandleVerifier::Get()->StopTracking(handle, owner, pc1, pc2); } void DisableHandleVerifier() { - return ScopedHandleVerifier::Get()->Disable(); } void OnHandleBeingClosed(HANDLE handle) { - return ScopedHandleVerifier::Get()->OnHandleBeingClosed(handle); } } // namespace win
diff --git a/base/win/scoped_handle_verifier.cc b/base/win/scoped_handle_verifier.cc deleted file mode 100644 index 080bdbc..0000000 --- a/base/win/scoped_handle_verifier.cc +++ /dev/null
@@ -1,216 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/win/scoped_handle_verifier.h" - -#include <stddef.h> -#include <windows.h> - -#include <unordered_map> - -#include "base/synchronization/lock_impl.h" -#include "base/win/current_module.h" - -extern "C" { -__declspec(dllexport) void* GetHandleVerifier(); - -void* GetHandleVerifier() { - return base::win::internal::ScopedHandleVerifier::Get(); -} -} // extern C - -namespace { - -base::win::internal::ScopedHandleVerifier* g_active_verifier = NULL; -typedef void* (*GetHandleVerifierFn)(); -typedef std::unordered_map<HANDLE, - base::win::internal::ScopedHandleVerifierInfo, - base::win::internal::HandleHash> - HandleMap; -typedef base::internal::LockImpl NativeLock; - -NativeLock* GetLock() { - static auto* native_lock = new NativeLock(); - return native_lock; -} - -// Simple automatic locking using a native critical section so it supports -// recursive locking. -class AutoNativeLock { - public: - explicit AutoNativeLock(NativeLock& lock) : lock_(lock) { lock_.Lock(); } - - ~AutoNativeLock() { lock_.Unlock(); } - - private: - NativeLock& lock_; - DISALLOW_COPY_AND_ASSIGN(AutoNativeLock); -}; - -} // namespace - -namespace base { -namespace win { -namespace internal { - -ScopedHandleVerifier::ScopedHandleVerifier(bool enabled) - : enabled_(enabled), lock_(GetLock()) {} - -// static -ScopedHandleVerifier* ScopedHandleVerifier::Get() { - if (!g_active_verifier) - ScopedHandleVerifier::InstallVerifier(); - - return g_active_verifier; -} - -bool CloseHandleWrapper(HANDLE handle) { - if (!::CloseHandle(handle)) - CHECK(false); // CloseHandle failed. - return true; -} - -// Assigns the g_active_verifier global within the GetLock() lock. -// If |existing_verifier| is non-null then |enabled| is ignored. -void ThreadSafeAssignOrCreateScopedHandleVerifier( - ScopedHandleVerifier* existing_verifier, - bool enabled) { - AutoNativeLock lock(*GetLock()); - // Another thread in this module might be trying to assign the global - // verifier, so check that within the lock here. - if (g_active_verifier) - return; - g_active_verifier = - existing_verifier ? existing_verifier : new ScopedHandleVerifier(enabled); -} - -// static -void ScopedHandleVerifier::InstallVerifier() { - // If you are reading this, wondering why your process seems deadlocked, take - // a look at your DllMain code and remove things that should not be done - // there, like doing whatever gave you that nice windows handle you are trying - // to store in a ScopedHandle. - HMODULE main_module = ::GetModuleHandle(NULL); - GetHandleVerifierFn get_handle_verifier = - reinterpret_cast<GetHandleVerifierFn>( - ::GetProcAddress(main_module, "GetHandleVerifier")); - - // This should only happen if running in a DLL is linked with base but the - // hosting EXE is not. In this case, create an ScopedHandleVerifier for the - // current - // module but leave it disabled. - if (!get_handle_verifier) { - ThreadSafeAssignOrCreateScopedHandleVerifier(nullptr, false); - return; - } - - // Check if in the main module. - if (get_handle_verifier == GetHandleVerifier) { - ThreadSafeAssignOrCreateScopedHandleVerifier(nullptr, true); - return; - } - - ScopedHandleVerifier* main_module_verifier = - reinterpret_cast<ScopedHandleVerifier*>(get_handle_verifier()); - - // Main module should always on-demand create a verifier. - DCHECK(main_module_verifier); - - ThreadSafeAssignOrCreateScopedHandleVerifier(main_module_verifier, false); -} - -bool ScopedHandleVerifier::CloseHandle(HANDLE handle) { - if (!enabled_) - return CloseHandleWrapper(handle); - - closing_.Set(true); - CloseHandleWrapper(handle); - closing_.Set(false); - - return true; -} - -// static -NativeLock* ScopedHandleVerifier::GetLock() { - return ::GetLock(); -} - -void ScopedHandleVerifier::StartTracking(HANDLE handle, - const void* owner, - const void* pc1, - const void* pc2) { - if (!enabled_) - return; - - // Grab the thread id before the lock. - DWORD thread_id = GetCurrentThreadId(); - - AutoNativeLock lock(*lock_); - - ScopedHandleVerifierInfo handle_info = {owner, pc1, pc2, - base::debug::StackTrace(), thread_id}; - std::pair<HANDLE, ScopedHandleVerifierInfo> item(handle, handle_info); - std::pair<HandleMap::iterator, bool> result = map_.insert(item); - if (!result.second) { - ScopedHandleVerifierInfo other = result.first->second; - auto creation_stack = creation_stack_; - CHECK(false); // Attempt to start tracking already tracked handle. - } -} - -void ScopedHandleVerifier::StopTracking(HANDLE handle, - const void* owner, - const void* pc1, - const void* pc2) { - if (!enabled_) - return; - - AutoNativeLock lock(*lock_); - HandleMap::iterator i = map_.find(handle); - if (i == map_.end()) { - auto creation_stack = creation_stack_; - CHECK(false); // Attempting to close an untracked handle. - } - - ScopedHandleVerifierInfo other = i->second; - if (other.owner != owner) { - auto creation_stack = creation_stack_; - CHECK(false); // Attempting to close a handle not owned by opener. - } - - map_.erase(i); -} - -void ScopedHandleVerifier::Disable() { - enabled_ = false; -} - -void ScopedHandleVerifier::OnHandleBeingClosed(HANDLE handle) { - if (!enabled_) - return; - - if (closing_.Get()) - return; - - AutoNativeLock lock(*lock_); - HandleMap::iterator i = map_.find(handle); - if (i == map_.end()) - return; - - ScopedHandleVerifierInfo other = i->second; - auto creation_stack = creation_stack_; - CHECK(false); // CloseHandle called on tracked handle. -} - -HMODULE ScopedHandleVerifier::GetModule() const { - return CURRENT_MODULE(); -} - -HMODULE GetHandleVerifierModuleForTesting() { - return g_active_verifier->GetModule(); -} - -} // namespace internal -} // namespace win -} // namespace base
diff --git a/base/win/scoped_handle_verifier.h b/base/win/scoped_handle_verifier.h deleted file mode 100644 index a7c131e..0000000 --- a/base/win/scoped_handle_verifier.h +++ /dev/null
@@ -1,89 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_WIN_SCOPED_HANDLE_VERIFIER_H_ -#define BASE_WIN_SCOPED_HANDLE_VERIFIER_H_ - -#include "base/win/windows_types.h" - -#include <unordered_map> - -#include "base/base_export.h" -#include "base/hash.h" -#include "base/synchronization/lock_impl.h" -#include "base/threading/thread_local.h" - -namespace base { -namespace win { -namespace internal { - -struct HandleHash { - size_t operator()(const HANDLE& handle) const { - char buffer[sizeof(handle)]; - memcpy(buffer, &handle, sizeof(handle)); - return base::Hash(buffer, sizeof(buffer)); - } -}; - -struct ScopedHandleVerifierInfo { - const void* owner; - const void* pc1; - const void* pc2; - base::debug::StackTrace stack; - DWORD thread_id; -}; - -// Implements the actual object that is verifying handles for this process. -// The active instance is shared across the module boundary but there is no -// way to delete this object from the wrong side of it (or any side, actually). -// We need [[clang::lto_visibility_public]] because instances of this class are -// passed across module boundaries. This means different modules must have -// compatible definitions of the class even when whole program optimization is -// enabled - which is what this attribute accomplishes. The pragma stops MSVC -// from emitting an unrecognized attribute warning. -#pragma warning(push) -#pragma warning(disable : 5030) -class [[clang::lto_visibility_public]] ScopedHandleVerifier { -#pragma warning(pop) - public: - explicit ScopedHandleVerifier(bool enabled); - - // Retrieves the current verifier. - static ScopedHandleVerifier* Get(); - - // The methods required by HandleTraits. They are virtual because we need to - // forward the call execution to another module, instead of letting the - // compiler call the version that is linked in the current module. - virtual bool CloseHandle(HANDLE handle); - virtual void StartTracking(HANDLE handle, const void* owner, const void* pc1, - const void* pc2); - virtual void StopTracking(HANDLE handle, const void* owner, const void* pc1, - const void* pc2); - virtual void Disable(); - virtual void OnHandleBeingClosed(HANDLE handle); - virtual HMODULE GetModule() const; - - private: - ~ScopedHandleVerifier(); // Not implemented. - - static base::internal::LockImpl* GetLock(); - static void InstallVerifier(); - - base::debug::StackTrace creation_stack_; - bool enabled_; - base::ThreadLocalBoolean closing_; - base::internal::LockImpl* lock_; - std::unordered_map<HANDLE, ScopedHandleVerifierInfo, HandleHash> map_; - DISALLOW_COPY_AND_ASSIGN(ScopedHandleVerifier); -}; - -// This testing function returns the module that the ActiveVerifier concrete -// implementation was instantiated in. -BASE_EXPORT HMODULE GetHandleVerifierModuleForTesting(); - -} // namespace internal -} // namespace win -} // namespace base - -#endif // BASE_WIN_SCOPED_HANDLE_VERIFIER_H_
diff --git a/base/win/win_util.cc b/base/win/win_util.cc index 01b7544..c6cb3e8 100644 --- a/base/win/win_util.cc +++ b/base/win/win_util.cc
@@ -39,7 +39,6 @@ #include "base/files/file_path.h" #include "base/logging.h" #include "base/macros.h" -#include "base/scoped_native_library.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -529,60 +528,6 @@ return is_tablet; } -enum DomainEnrollmentState {UNKNOWN = -1, NOT_ENROLLED, ENROLLED}; -static volatile long int g_domain_state = UNKNOWN; - -bool IsEnrolledToDomain() { - // Doesn't make any sense to retry inside a user session because joining a - // domain will only kick in on a restart. - if (g_domain_state == UNKNOWN) { - ::InterlockedCompareExchange(&g_domain_state, - IsOS(OS_DOMAINMEMBER) ? - ENROLLED : NOT_ENROLLED, - UNKNOWN); - } - - return g_domain_state == ENROLLED; -} - -bool IsDeviceRegisteredWithManagement() { - static bool is_device_registered_with_management = []() { - ScopedNativeLibrary library( - FilePath(FILE_PATH_LITERAL("MDMRegistration.dll"))); - if (!library.is_valid()) - return false; - - using IsDeviceRegisteredWithManagementFunction = - decltype(&::IsDeviceRegisteredWithManagement); - IsDeviceRegisteredWithManagementFunction - is_device_registered_with_management_function = - reinterpret_cast<IsDeviceRegisteredWithManagementFunction>( - library.GetFunctionPointer("IsDeviceRegisteredWithManagement")); - if (!is_device_registered_with_management_function) - return false; - - BOOL is_managed = false; - HRESULT hr = - is_device_registered_with_management_function(&is_managed, 0, nullptr); - return SUCCEEDED(hr) && is_managed; - }(); - return is_device_registered_with_management; -} - -bool IsEnterpriseManaged() { - // TODO(rogerta): this function should really be: - // - // return IsEnrolledToDomain() || IsDeviceRegisteredWithManagement(); - // - // However, for now it is decided to collect some UMA metrics about - // IsDeviceRegisteredWithMdm() before changing chrome's behavior. - return IsEnrolledToDomain(); -} - -void SetDomainStateForTesting(bool state) { - g_domain_state = state ? ENROLLED : NOT_ENROLLED; -} - bool IsUser32AndGdi32Available() { static auto is_user32_and_gdi32_available = []() { // If win32k syscalls aren't disabled, then user32 and gdi32 are available.
diff --git a/base/win/win_util.h b/base/win/win_util.h index 9d2f858..dc996fd 100644 --- a/base/win/win_util.h +++ b/base/win/win_util.h
@@ -150,17 +150,6 @@ offsetof(struct_name, member) + \ (sizeof static_cast<struct_name*>(NULL)->member) -// Returns true if the machine is enrolled to a domain. -BASE_EXPORT bool IsEnrolledToDomain(); - -// Returns true if the machine is being managed by an MDM system. -BASE_EXPORT bool IsDeviceRegisteredWithManagement(); - -// Returns true if the current machine is considered enterprise managed in some -// fashion. A machine is considered managed if it is either domain enrolled -// or registered with an MDM. -BASE_EXPORT bool IsEnterpriseManaged(); - // Used by tests to mock any wanted state. Call with |state| set to true to // simulate being in a domain and false otherwise. BASE_EXPORT void SetDomainStateForTesting(bool state);
diff --git a/base/win/windows_version.cc b/base/win/windows_version.cc index a74c80a..6b7be76 100644 --- a/base/win/windows_version.cc +++ b/base/win/windows_version.cc
@@ -8,7 +8,6 @@ #include <memory> -#include "base/file_version_info_win.h" #include "base/files/file_path.h" #include "base/logging.h" #include "base/strings/utf_string_conversions.h" @@ -74,28 +73,6 @@ return VERSION_PRE_XP; } -// Retrieve a version from kernel32. This is useful because when running in -// compatibility mode for a down-level version of the OS, the file version of -// kernel32 will still be the "real" version. -Version GetVersionFromKernel32() { - std::unique_ptr<FileVersionInfoWin> file_version_info( - static_cast<FileVersionInfoWin*>( - FileVersionInfoWin::CreateFileVersionInfo( - base::FilePath(FILE_PATH_LITERAL("kernel32.dll"))))); - if (file_version_info) { - const int major = - HIWORD(file_version_info->fixed_file_info()->dwFileVersionMS); - const int minor = - LOWORD(file_version_info->fixed_file_info()->dwFileVersionMS); - const int build = - HIWORD(file_version_info->fixed_file_info()->dwFileVersionLS); - return MajorMinorBuildToVersion(major, minor, build); - } - - NOTREACHED(); - return VERSION_WIN_LAST; -} - // Returns the the "UBR" value from the registry. Introduced in Windows 10, // this undocumented value appears to be similar to a patch number. // Returns 0 if the value does not exist or it could not be read. @@ -138,7 +115,6 @@ OSInfo::OSInfo() : version_(VERSION_PRE_XP), kernel32_version_(VERSION_PRE_XP), - got_kernel32_version_(false), architecture_(OTHER_ARCHITECTURE), wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { OSVERSIONINFOEX version_info = { sizeof version_info }; @@ -240,14 +216,6 @@ OSInfo::~OSInfo() { } -Version OSInfo::Kernel32Version() const { - if (!got_kernel32_version_) { - kernel32_version_ = GetVersionFromKernel32(); - got_kernel32_version_ = true; - } - return kernel32_version_; -} - std::string OSInfo::processor_model_name() { if (processor_model_name_.empty()) { const wchar_t kProcessorNameString[] =
diff --git a/base/win/windows_version.h b/base/win/windows_version.h index 978df3d..28c7c89 100644 --- a/base/win/windows_version.h +++ b/base/win/windows_version.h
@@ -99,7 +99,6 @@ static OSInfo* GetInstance(); Version version() const { return version_; } - Version Kernel32Version() const; // The next two functions return arrays of values, [major, minor(, build)]. VersionNumber version_number() const { return version_number_; } VersionType version_type() const { return version_type_; } @@ -121,7 +120,6 @@ Version version_; mutable Version kernel32_version_; - mutable bool got_kernel32_version_; VersionNumber version_number_; VersionType version_type_; ServicePack service_pack_;
diff --git a/build/gen.py b/build/gen.py index 02278d1..8840652 100755 --- a/build/gen.py +++ b/build/gen.py
@@ -693,7 +693,6 @@ 'base/win/scoped_bstr.cc', 'base/win/scoped_com_initializer.cc', 'base/win/scoped_handle.cc', - 'base/win/scoped_handle_verifier.cc', 'base/win/scoped_process_information.cc', 'base/win/scoped_variant.cc', 'base/win/shortcut.cc',
diff --git a/src/exe_path.cc b/src/exe_path.cc index 84f9aba..88c88ea 100644 --- a/src/exe_path.cc +++ b/src/exe_path.cc
@@ -11,6 +11,11 @@ #if defined(OS_MACOSX) #include <mach-o/dyld.h> +#elif defined(OS_WIN) +#include <windows.h> +#endif + +#if defined(OS_MACOSX) base::FilePath GetExePath() { // Executable path can have relative references ("..") depending on @@ -33,7 +38,14 @@ #elif defined(OS_WIN) -#error +base::FilePath GetExePath() { + wchar_t system_buffer[MAX_PATH]; + system_buffer[0] = 0; + if (GetModuleFileName(NULL, system_buffer, MAX_PATH) == 0) { + return base::FilePath(); + } + return base::FilePath(system_buffer); +} #else
diff --git a/tools/gn/command_format_unittest.cc b/tools/gn/command_format_unittest.cc index df24425..d2e7f3a 100644 --- a/tools/gn/command_format_unittest.cc +++ b/tools/gn/command_format_unittest.cc
@@ -19,7 +19,8 @@ ::Setup setup; \ std::string out; \ std::string expected; \ - base::FilePath src_dir = GetExePath().DirName().Append(".."); \ + base::FilePath src_dir = \ + GetExePath().DirName().Append(FILE_PATH_LITERAL("..")); \ base::SetCurrentDirectory(src_dir); \ EXPECT_TRUE(commands::FormatFileToString( \ &setup, SourceFile("//tools/gn/format_test_data/" #n ".gn"), false, \