Remove some more of base/win
Change-Id: I62154119766de036b63a91af0bdd42765c2a58d8
Reviewed-on: https://gn-review.googlesource.com/1701
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/base/win/current_module.h b/base/win/current_module.h
deleted file mode 100644
index ee141db..0000000
--- a/base/win/current_module.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2016 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_CURRENT_MODULE_H_
-#define BASE_WIN_CURRENT_MODULE_H_
-
-#include <windows.h>
-
-// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
-extern "C" IMAGE_DOS_HEADER __ImageBase;
-
-// Returns the HMODULE of the dll the macro was expanded in.
-// Only use in cc files, not in h files.
-#define CURRENT_MODULE() reinterpret_cast<HMODULE>(&__ImageBase)
-
-#endif // BASE_WIN_CURRENT_MODULE_H_
diff --git a/base/win/event_trace_consumer.h b/base/win/event_trace_consumer.h
deleted file mode 100644
index 93e8a24..0000000
--- a/base/win/event_trace_consumer.h
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright (c) 2012 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.
-//
-// Declaration of a Windows event trace consumer base class.
-#ifndef BASE_WIN_EVENT_TRACE_CONSUMER_H_
-#define BASE_WIN_EVENT_TRACE_CONSUMER_H_
-
-#include <evntrace.h>
-#include <stddef.h>
-#include <windows.h>
-#include <wmistr.h>
-#include <vector>
-
-#include "base/macros.h"
-
-namespace base {
-namespace win {
-
-// This class is a base class that makes it easier to consume events
-// from realtime or file sessions. Concrete consumers need to subclass
-// a specialization of this class and override the ProcessEvent and/or
-// the ProcessBuffer methods to implement the event consumption logic.
-// Usage might look like:
-// class MyConsumer: public EtwTraceConsumerBase<MyConsumer, 1> {
-// protected:
-// static VOID WINAPI ProcessEvent(PEVENT_TRACE event);
-// };
-//
-// MyConsumer consumer;
-// consumer.OpenFileSession(file_path);
-// consumer.Consume();
-template <class ImplClass>
-class EtwTraceConsumerBase {
- public:
- // Constructs a closed consumer.
- EtwTraceConsumerBase() {}
-
- ~EtwTraceConsumerBase() { Close(); }
-
- // Opens the named realtime session, which must be existent.
- // Note: You can use OpenRealtimeSession or OpenFileSession
- // to open as many as MAXIMUM_WAIT_OBJECTS (63) sessions at
- // any one time, though only one of them may be a realtime
- // session.
- HRESULT OpenRealtimeSession(const wchar_t* session_name);
-
- // Opens the event trace log in "file_name", which must be a full or
- // relative path to an existing event trace log file.
- // Note: You can use OpenRealtimeSession or OpenFileSession
- // to open as many as kNumSessions at any one time.
- HRESULT OpenFileSession(const wchar_t* file_name);
-
- // Consume all open sessions from beginning to end.
- HRESULT Consume();
-
- // Close all open sessions.
- HRESULT Close();
-
- protected:
- // Override in subclasses to handle events.
- static void ProcessEvent(EVENT_TRACE* event) {}
- // Override in subclasses to handle buffers.
- static bool ProcessBuffer(EVENT_TRACE_LOGFILE* buffer) {
- return true; // keep going
- }
-
- protected:
- // Currently open sessions.
- std::vector<TRACEHANDLE> trace_handles_;
-
- private:
- // These delegate to ImplClass callbacks with saner signatures.
- static void WINAPI ProcessEventCallback(EVENT_TRACE* event) {
- ImplClass::ProcessEvent(event);
- }
- static ULONG WINAPI ProcessBufferCallback(PEVENT_TRACE_LOGFILE buffer) {
- return ImplClass::ProcessBuffer(buffer);
- }
-
- DISALLOW_COPY_AND_ASSIGN(EtwTraceConsumerBase);
-};
-
-template <class ImplClass>
-inline HRESULT EtwTraceConsumerBase<ImplClass>::OpenRealtimeSession(
- const wchar_t* session_name) {
- EVENT_TRACE_LOGFILE logfile = {};
- logfile.LoggerName = const_cast<wchar_t*>(session_name);
- logfile.LogFileMode = EVENT_TRACE_REAL_TIME_MODE;
- logfile.BufferCallback = &ProcessBufferCallback;
- logfile.EventCallback = &ProcessEventCallback;
- logfile.Context = this;
- TRACEHANDLE trace_handle = ::OpenTrace(&logfile);
- if (reinterpret_cast<TRACEHANDLE>(INVALID_HANDLE_VALUE) == trace_handle)
- return HRESULT_FROM_WIN32(::GetLastError());
-
- trace_handles_.push_back(trace_handle);
- return S_OK;
-}
-
-template <class ImplClass>
-inline HRESULT EtwTraceConsumerBase<ImplClass>::OpenFileSession(
- const wchar_t* file_name) {
- EVENT_TRACE_LOGFILE logfile = {};
- logfile.LogFileName = const_cast<wchar_t*>(file_name);
- logfile.BufferCallback = &ProcessBufferCallback;
- logfile.EventCallback = &ProcessEventCallback;
- logfile.Context = this;
- TRACEHANDLE trace_handle = ::OpenTrace(&logfile);
- if (reinterpret_cast<TRACEHANDLE>(INVALID_HANDLE_VALUE) == trace_handle)
- return HRESULT_FROM_WIN32(::GetLastError());
-
- trace_handles_.push_back(trace_handle);
- return S_OK;
-}
-
-template <class ImplClass>
-inline HRESULT EtwTraceConsumerBase<ImplClass>::Consume() {
- ULONG err =
- ::ProcessTrace(&trace_handles_[0],
- static_cast<ULONG>(trace_handles_.size()), NULL, NULL);
- return HRESULT_FROM_WIN32(err);
-}
-
-template <class ImplClass>
-inline HRESULT EtwTraceConsumerBase<ImplClass>::Close() {
- HRESULT hr = S_OK;
- for (size_t i = 0; i < trace_handles_.size(); ++i) {
- if (NULL != trace_handles_[i]) {
- ULONG ret = ::CloseTrace(trace_handles_[i]);
- trace_handles_[i] = NULL;
-
- if (FAILED(HRESULT_FROM_WIN32(ret)))
- hr = HRESULT_FROM_WIN32(ret);
- }
- }
- trace_handles_.clear();
-
- return hr;
-}
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_EVENT_TRACE_CONSUMER_H_
diff --git a/base/win/patch_util.cc b/base/win/patch_util.cc
deleted file mode 100644
index c53a8e4..0000000
--- a/base/win/patch_util.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 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/patch_util.h"
-
-#include "base/logging.h"
-
-namespace base {
-namespace win {
-namespace internal {
-
-DWORD ModifyCode(void* destination, const void* source, int length) {
- if ((NULL == destination) || (NULL == source) || (0 == length)) {
- NOTREACHED();
- return ERROR_INVALID_PARAMETER;
- }
-
- // Change the page protection so that we can write.
- MEMORY_BASIC_INFORMATION memory_info;
- DWORD error = NO_ERROR;
- DWORD old_page_protection = 0;
-
- if (!VirtualQuery(destination, &memory_info, sizeof(memory_info))) {
- error = GetLastError();
- return error;
- }
-
- DWORD is_executable = (PAGE_EXECUTE | PAGE_EXECUTE_READ |
- PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) &
- memory_info.Protect;
-
- if (VirtualProtect(destination, length,
- is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE,
- &old_page_protection)) {
- // Write the data.
- CopyMemory(destination, source, length);
-
- // Restore the old page protection.
- error = ERROR_SUCCESS;
- VirtualProtect(destination, length, old_page_protection,
- &old_page_protection);
- } else {
- error = GetLastError();
- }
-
- return error;
-}
-
-} // namespace internal
-} // namespace win
-} // namespace base
diff --git a/base/win/patch_util.h b/base/win/patch_util.h
deleted file mode 100644
index 6668273..0000000
--- a/base/win/patch_util.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 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_PATCH_UTIL_H_
-#define BASE_WIN_PATCH_UTIL_H_
-
-#include <windows.h>
-
-namespace base {
-namespace win {
-namespace internal {
-
-// Copies |length| bytes from |source| to |destination|, temporarily setting
-// |destination| to writable. Returns a Windows error code or NO_ERROR if
-// successful.
-DWORD ModifyCode(void* destination, const void* source, int length);
-
-} // namespace internal
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_PATCH_UTIL_H_
diff --git a/base/win/scoped_co_mem.h b/base/win/scoped_co_mem.h
deleted file mode 100644
index 3c31f3f..0000000
--- a/base/win/scoped_co_mem.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2011 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_CO_MEM_H_
-#define BASE_WIN_SCOPED_CO_MEM_H_
-
-#include <objbase.h>
-
-#include "base/logging.h"
-#include "base/macros.h"
-
-namespace base {
-namespace win {
-
-// Simple scoped memory releaser class for COM allocated memory.
-// Example:
-// base::win::ScopedCoMem<ITEMIDLIST> file_item;
-// SHGetSomeInfo(&file_item, ...);
-// ...
-// return; <-- memory released
-template <typename T>
-class ScopedCoMem {
- public:
- ScopedCoMem() : mem_ptr_(NULL) {}
- ~ScopedCoMem() { Reset(NULL); }
-
- T** operator&() { // NOLINT
- DCHECK(mem_ptr_ == NULL); // To catch memory leaks.
- return &mem_ptr_;
- }
-
- operator T*() { return mem_ptr_; }
-
- T* operator->() {
- DCHECK(mem_ptr_ != NULL);
- return mem_ptr_;
- }
-
- const T* operator->() const {
- DCHECK(mem_ptr_ != NULL);
- return mem_ptr_;
- }
-
- void Reset(T* ptr) {
- if (mem_ptr_)
- CoTaskMemFree(mem_ptr_);
- mem_ptr_ = ptr;
- }
-
- T* get() const { return mem_ptr_; }
-
- private:
- T* mem_ptr_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedCoMem);
-};
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_SCOPED_CO_MEM_H_
diff --git a/base/win/scoped_gdi_object.h b/base/win/scoped_gdi_object.h
deleted file mode 100644
index 9d8465b..0000000
--- a/base/win/scoped_gdi_object.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2010 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_GDI_OBJECT_H_
-#define BASE_WIN_SCOPED_GDI_OBJECT_H_
-
-#include <windows.h>
-
-#include "base/scoped_generic.h"
-
-namespace base {
-namespace win {
-
-namespace internal {
-
-template <class T>
-struct ScopedGDIObjectTraits {
- static T InvalidValue() { return nullptr; }
- static void Free(T object) { DeleteObject(object); }
-};
-
-// An explicit specialization for HICON because we have to call DestroyIcon()
-// instead of DeleteObject() for HICON.
-template <>
-void inline ScopedGDIObjectTraits<HICON>::Free(HICON icon) {
- DestroyIcon(icon);
-}
-
-} // namespace internal
-
-// Like ScopedHandle but for GDI objects.
-template <class T>
-using ScopedGDIObject = ScopedGeneric<T, internal::ScopedGDIObjectTraits<T>>;
-
-// Typedefs for some common use cases.
-typedef ScopedGDIObject<HBITMAP> ScopedBitmap;
-typedef ScopedGDIObject<HRGN> ScopedRegion;
-typedef ScopedGDIObject<HFONT> ScopedHFONT;
-typedef ScopedGDIObject<HICON> ScopedHICON;
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_SCOPED_GDI_OBJECT_H_
diff --git a/base/win/scoped_handle_test_dll.cc b/base/win/scoped_handle_test_dll.cc
deleted file mode 100644
index 9603d68..0000000
--- a/base/win/scoped_handle_test_dll.cc
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2016 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 <windows.h>
-
-#include <vector>
-
-#include "base/win/base_win_buildflags.h"
-#include "base/win/current_module.h"
-#include "base/win/scoped_handle.h"
-#include "base/win/scoped_handle_verifier.h"
-
-namespace base {
-namespace win {
-namespace testing {
-
-extern "C" bool __declspec(dllexport) RunTest();
-
-namespace {
-
-struct ThreadParams {
- HANDLE ready_event;
- HANDLE start_event;
-};
-
-// Note, this must use all native functions to avoid instantiating the
-// ActiveVerifier. e.g. can't use base::Thread or even base::PlatformThread.
-DWORD __stdcall ThreadFunc(void* params) {
- ThreadParams* thread_params = reinterpret_cast<ThreadParams*>(params);
- HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
-
- ::SetEvent(thread_params->ready_event);
- ::WaitForSingleObject(thread_params->start_event, INFINITE);
- ScopedHandle handle_holder(handle);
- return 0;
-}
-
-bool InternalRunThreadTest() {
- std::vector<HANDLE> threads_;
- // From manual testing, the bug fixed by crrev.com/678736a starts reliably
- // causing handle verifier asserts to trigger at around 100 threads, so make
- // it 200 to be sure to detect any future regressions.
- const size_t kNumThreads = 200;
-
- // bManualReset is set to true to allow signalling multiple threads.
- HANDLE start_event = ::CreateEvent(nullptr, true, false, nullptr);
- if (!start_event)
- return false;
-
- HANDLE ready_event = CreateEvent(nullptr, false, false, nullptr);
- if (!ready_event)
- return false;
-
- ThreadParams thread_params = {ready_event, start_event};
-
- for (size_t i = 0; i < kNumThreads; i++) {
- HANDLE thread_handle =
- ::CreateThread(nullptr, 0, ThreadFunc,
- reinterpret_cast<void*>(&thread_params), 0, nullptr);
- if (!thread_handle)
- break;
- ::WaitForSingleObject(ready_event, INFINITE);
- threads_.push_back(thread_handle);
- }
-
- ::CloseHandle(ready_event);
-
- if (threads_.size() != kNumThreads) {
- for (auto* thread : threads_)
- ::CloseHandle(thread);
- ::CloseHandle(start_event);
- return false;
- }
-
- ::SetEvent(start_event);
- ::CloseHandle(start_event);
- for (auto* thread : threads_) {
- ::WaitForSingleObject(thread, INFINITE);
- ::CloseHandle(thread);
- }
-
- return true;
-}
-
-bool InternalRunLocationTest() {
- // Create a new handle and then set LastError again.
- HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
- if (!handle)
- return false;
- ScopedHandle handle_holder(handle);
-
- HMODULE verifier_module =
- base::win::internal::GetHandleVerifierModuleForTesting();
- if (!verifier_module)
- return false;
-
- // Get my module
- HMODULE my_module = CURRENT_MODULE();
- if (!my_module)
- return false;
-
- HMODULE main_module = ::GetModuleHandle(NULL);
-
- // In a non-component build, ActiveVerifier should always be created in the
- // version of base linked with the main executable.
- if (verifier_module == my_module || verifier_module != main_module)
- return false;
- return true;
-}
-
-} // namespace
-
-bool RunTest() {
- return InternalRunThreadTest() && InternalRunLocationTest();
-}
-
-} // namespace testing
-} // namespace win
-} // namespace base
diff --git a/base/win/scoped_hdc.h b/base/win/scoped_hdc.h
deleted file mode 100644
index 226b0b9..0000000
--- a/base/win/scoped_hdc.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) 2012 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_HDC_H_
-#define BASE_WIN_SCOPED_HDC_H_
-
-#include <windows.h>
-
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/win/scoped_handle.h"
-
-namespace base {
-namespace win {
-
-// Like ScopedHandle but for HDC. Only use this on HDCs returned from
-// GetDC.
-class ScopedGetDC {
- public:
- explicit ScopedGetDC(HWND hwnd) : hwnd_(hwnd), hdc_(GetDC(hwnd)) {
- if (hwnd_) {
- DCHECK(IsWindow(hwnd_));
- DCHECK(hdc_);
- } else {
- // If GetDC(NULL) returns NULL, something really bad has happened, like
- // GDI handle exhaustion. In this case Chrome is going to behave badly no
- // matter what, so we may as well just force a crash now.
- if (!hdc_)
- base::debug::CollectGDIUsageAndDie();
- }
- }
-
- ~ScopedGetDC() {
- if (hdc_)
- ReleaseDC(hwnd_, hdc_);
- }
-
- operator HDC() { return hdc_; }
-
- private:
- HWND hwnd_;
- HDC hdc_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedGetDC);
-};
-
-// Like ScopedHandle but for HDC. Only use this on HDCs returned from
-// CreateCompatibleDC, CreateDC and CreateIC.
-class CreateDCTraits {
- public:
- typedef HDC Handle;
-
- static bool CloseHandle(HDC handle) { return ::DeleteDC(handle) != FALSE; }
-
- static bool IsHandleValid(HDC handle) { return handle != NULL; }
-
- static HDC NullHandle() { return NULL; }
-
- private:
- DISALLOW_IMPLICIT_CONSTRUCTORS(CreateDCTraits);
-};
-
-typedef GenericScopedHandle<CreateDCTraits, DummyVerifierTraits> ScopedCreateDC;
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_SCOPED_HDC_H_
diff --git a/base/win/scoped_hglobal.h b/base/win/scoped_hglobal.h
deleted file mode 100644
index 2fa8aaa..0000000
--- a/base/win/scoped_hglobal.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2010 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_HGLOBAL_H_
-#define BASE_WIN_SCOPED_HGLOBAL_H_
-
-#include <stddef.h>
-#include <windows.h>
-
-#include "base/macros.h"
-
-namespace base {
-namespace win {
-
-// Like ScopedHandle except for HGLOBAL.
-template <class T>
-class ScopedHGlobal {
- public:
- explicit ScopedHGlobal(HGLOBAL glob) : glob_(glob) {
- data_ = static_cast<T>(GlobalLock(glob_));
- }
- ~ScopedHGlobal() { GlobalUnlock(glob_); }
-
- T get() { return data_; }
-
- size_t Size() const { return GlobalSize(glob_); }
-
- T operator->() const {
- assert(data_ != 0);
- return data_;
- }
-
- T release() {
- T data = data_;
- data_ = NULL;
- return data;
- }
-
- private:
- HGLOBAL glob_;
-
- T data_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedHGlobal);
-};
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_SCOPED_HGLOBAL_H_
diff --git a/base/win/scoped_hstring.cc b/base/win/scoped_hstring.cc
deleted file mode 100644
index 89d1f49..0000000
--- a/base/win/scoped_hstring.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2017 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_hstring.h"
-
-#include <winstring.h>
-
-#include "base/strings/string_piece.h"
-#include "base/strings/utf_string_conversions.h"
-
-namespace base {
-
-namespace {
-
-static bool g_load_succeeded = false;
-
-FARPROC LoadComBaseFunction(const char* function_name) {
- static HMODULE const handle = ::LoadLibrary(L"combase.dll");
- return handle ? ::GetProcAddress(handle, function_name) : nullptr;
-}
-
-decltype(&::WindowsCreateString) GetWindowsCreateString() {
- static decltype(&::WindowsCreateString) const function =
- reinterpret_cast<decltype(&::WindowsCreateString)>(
- LoadComBaseFunction("WindowsCreateString"));
- return function;
-}
-
-decltype(&::WindowsDeleteString) GetWindowsDeleteString() {
- static decltype(&::WindowsDeleteString) const function =
- reinterpret_cast<decltype(&::WindowsDeleteString)>(
- LoadComBaseFunction("WindowsDeleteString"));
- return function;
-}
-
-decltype(&::WindowsGetStringRawBuffer) GetWindowsGetStringRawBuffer() {
- static decltype(&::WindowsGetStringRawBuffer) const function =
- reinterpret_cast<decltype(&::WindowsGetStringRawBuffer)>(
- LoadComBaseFunction("WindowsGetStringRawBuffer"));
- return function;
-}
-
-HRESULT WindowsCreateString(const base::char16* src,
- uint32_t len,
- HSTRING* out_hstr) {
- decltype(&::WindowsCreateString) create_string_func =
- GetWindowsCreateString();
- if (!create_string_func)
- return E_FAIL;
- return create_string_func(src, len, out_hstr);
-}
-
-HRESULT WindowsDeleteString(HSTRING hstr) {
- decltype(&::WindowsDeleteString) delete_string_func =
- GetWindowsDeleteString();
- if (!delete_string_func)
- return E_FAIL;
- return delete_string_func(hstr);
-}
-
-const base::char16* WindowsGetStringRawBuffer(HSTRING hstr, uint32_t* out_len) {
- decltype(&::WindowsGetStringRawBuffer) get_string_raw_buffer_func =
- GetWindowsGetStringRawBuffer();
- if (!get_string_raw_buffer_func) {
- *out_len = 0;
- return nullptr;
- }
- return get_string_raw_buffer_func(hstr, out_len);
-}
-
-} // namespace
-
-namespace internal {
-
-// static
-void ScopedHStringTraits::Free(HSTRING hstr) {
- base::WindowsDeleteString(hstr);
-}
-
-} // namespace internal
-
-namespace win {
-
-// static
-ScopedHString ScopedHString::Create(StringPiece16 str) {
- DCHECK(g_load_succeeded);
- HSTRING hstr;
- HRESULT hr = base::WindowsCreateString(str.data(), str.length(), &hstr);
- if (SUCCEEDED(hr))
- return ScopedHString(hstr);
- DLOG(ERROR) << "Failed to create HSTRING" << std::hex << hr;
- return ScopedHString(nullptr);
-}
-
-ScopedHString ScopedHString::Create(StringPiece str) {
- return Create(UTF8ToWide(str));
-}
-
-ScopedHString::ScopedHString(HSTRING hstr) : ScopedGeneric(hstr) {
- DCHECK(g_load_succeeded);
-}
-
-// static
-bool ScopedHString::ResolveCoreWinRTStringDelayload() {
- // TODO(finnur): Add AssertIOAllowed once crbug.com/770193 is fixed.
-
- static const bool load_succeeded = []() {
- bool success = GetWindowsCreateString() && GetWindowsDeleteString() &&
- GetWindowsGetStringRawBuffer();
- g_load_succeeded = success;
- return success;
- }();
- return load_succeeded;
-}
-
-StringPiece16 ScopedHString::Get() const {
- UINT32 length = 0;
- const wchar_t* buffer = base::WindowsGetStringRawBuffer(get(), &length);
- return StringPiece16(buffer, length);
-}
-
-std::string ScopedHString::GetAsUTF8() const {
- std::string result;
- const StringPiece16 wide_string = Get();
- WideToUTF8(wide_string.data(), wide_string.length(), &result);
- return result;
-}
-
-} // namespace win
-} // namespace base
diff --git a/base/win/scoped_hstring.h b/base/win/scoped_hstring.h
deleted file mode 100644
index 7c169b9..0000000
--- a/base/win/scoped_hstring.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2017 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_HSTRING_H_
-#define BASE_WIN_SCOPED_HSTRING_H_
-
-#include <hstring.h>
-
-#include "base/scoped_generic.h"
-#include "base/strings/string_piece_forward.h"
-
-namespace base {
-
-namespace internal {
-
-// Scoped HSTRING class to maintain lifetime of HSTRINGs allocated with
-// WindowsCreateString().
-struct ScopedHStringTraits {
- static HSTRING InvalidValue() { return nullptr; }
- static void Free(HSTRING hstr);
-};
-
-} // namespace internal
-
-namespace win {
-
-// ScopedHString is a wrapper around an HSTRING. Note that it requires certain
-// functions that are only available on Windows 8 and later, and that these
-// functions need to be delayloaded to avoid breaking Chrome on Windows 7.
-//
-// Callers MUST check the return value of ResolveCoreWinRTStringDelayLoad()
-// *before* using ScopedHString.
-//
-// One-time Initialization for ScopedHString:
-//
-// bool success = ScopedHString::ResolveCoreWinRTStringDelayload();
-// if (!success) {
-// // ScopeHString can be used.
-// } else {
-// // Handle error.
-// }
-//
-// Example use:
-//
-// ScopedHString string = ScopedHString::Create(L"abc");
-//
-// Also:
-//
-// HSTRING win_string;
-// HRESULT hr = WindowsCreateString(..., &win_string);
-// ScopedHString string(win_string);
-//
-class ScopedHString
- : public ScopedGeneric<HSTRING, base::internal::ScopedHStringTraits> {
- public:
- // Constructs a ScopedHString from an HSTRING, and takes ownership of |hstr|.
- explicit ScopedHString(HSTRING hstr);
-
- static ScopedHString Create(StringPiece16 str);
- static ScopedHString Create(StringPiece str);
-
- // Loads all required HSTRING functions, available from Win8 and onwards.
- static bool ResolveCoreWinRTStringDelayload();
-
- StringPiece16 Get() const;
- std::string GetAsUTF8() const;
-};
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_SCOPED_HSTRING_H_
diff --git a/base/win/startup_information.cc b/base/win/startup_information.cc
deleted file mode 100644
index fbfb093..0000000
--- a/base/win/startup_information.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (c) 2012 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/startup_information.h"
-
-#include "base/logging.h"
-
-namespace {
-
-typedef BOOL(WINAPI* InitializeProcThreadAttributeListFunction)(
- LPPROC_THREAD_ATTRIBUTE_LIST attribute_list,
- DWORD attribute_count,
- DWORD flags,
- PSIZE_T size);
-static InitializeProcThreadAttributeListFunction
- initialize_proc_thread_attribute_list;
-
-typedef BOOL(WINAPI* UpdateProcThreadAttributeFunction)(
- LPPROC_THREAD_ATTRIBUTE_LIST attribute_list,
- DWORD flags,
- DWORD_PTR attribute,
- PVOID value,
- SIZE_T size,
- PVOID previous_value,
- PSIZE_T return_size);
-static UpdateProcThreadAttributeFunction update_proc_thread_attribute_list;
-
-typedef VOID(WINAPI* DeleteProcThreadAttributeListFunction)(
- LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList);
-static DeleteProcThreadAttributeListFunction delete_proc_thread_attribute_list;
-
-} // namespace
-
-namespace base {
-namespace win {
-
-StartupInformation::StartupInformation() {
- memset(&startup_info_, 0, sizeof(startup_info_));
- startup_info_.StartupInfo.cb = sizeof(startup_info_);
-
- // Load the attribute API functions.
- if (!initialize_proc_thread_attribute_list ||
- !update_proc_thread_attribute_list ||
- !delete_proc_thread_attribute_list) {
- HMODULE module = ::GetModuleHandleW(L"kernel32.dll");
- initialize_proc_thread_attribute_list =
- reinterpret_cast<InitializeProcThreadAttributeListFunction>(
- ::GetProcAddress(module, "InitializeProcThreadAttributeList"));
- update_proc_thread_attribute_list =
- reinterpret_cast<UpdateProcThreadAttributeFunction>(
- ::GetProcAddress(module, "UpdateProcThreadAttribute"));
- delete_proc_thread_attribute_list =
- reinterpret_cast<DeleteProcThreadAttributeListFunction>(
- ::GetProcAddress(module, "DeleteProcThreadAttributeList"));
- }
-}
-
-StartupInformation::~StartupInformation() {
- if (startup_info_.lpAttributeList) {
- delete_proc_thread_attribute_list(startup_info_.lpAttributeList);
- delete[] reinterpret_cast<BYTE*>(startup_info_.lpAttributeList);
- }
-}
-
-bool StartupInformation::InitializeProcThreadAttributeList(
- DWORD attribute_count) {
- if (startup_info_.StartupInfo.cb != sizeof(startup_info_) ||
- startup_info_.lpAttributeList)
- return false;
-
- SIZE_T size = 0;
- initialize_proc_thread_attribute_list(NULL, attribute_count, 0, &size);
- if (size == 0)
- return false;
-
- startup_info_.lpAttributeList =
- reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(new BYTE[size]);
- if (!initialize_proc_thread_attribute_list(startup_info_.lpAttributeList,
- attribute_count, 0, &size)) {
- delete[] reinterpret_cast<BYTE*>(startup_info_.lpAttributeList);
- startup_info_.lpAttributeList = NULL;
- return false;
- }
-
- return true;
-}
-
-bool StartupInformation::UpdateProcThreadAttribute(DWORD_PTR attribute,
- void* value,
- size_t size) {
- if (!startup_info_.lpAttributeList)
- return false;
- return !!update_proc_thread_attribute_list(
- startup_info_.lpAttributeList, 0, attribute, value, size, NULL, NULL);
-}
-
-} // namespace win
-} // namespace base
diff --git a/base/win/startup_information.h b/base/win/startup_information.h
deleted file mode 100644
index d95f39b..0000000
--- a/base/win/startup_information.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2012 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_STARTUP_INFORMATION_H_
-#define BASE_WIN_STARTUP_INFORMATION_H_
-
-#include <stddef.h>
-#include <windows.h>
-
-#include "base/macros.h"
-
-namespace base {
-namespace win {
-
-// Manages the lifetime of additional attributes in STARTUPINFOEX.
-class StartupInformation {
- public:
- StartupInformation();
-
- ~StartupInformation();
-
- // Initialize the attribute list for the specified number of entries.
- bool InitializeProcThreadAttributeList(DWORD attribute_count);
-
- // Sets one entry in the initialized attribute list.
- // |value| needs to live at least as long as the StartupInformation object
- // this is called on.
- bool UpdateProcThreadAttribute(DWORD_PTR attribute, void* value, size_t size);
-
- LPSTARTUPINFOW startup_info() { return &startup_info_.StartupInfo; }
- LPSTARTUPINFOW startup_info() const {
- return const_cast<const LPSTARTUPINFOW>(&startup_info_.StartupInfo);
- }
-
- bool has_extended_startup_info() const {
- return !!startup_info_.lpAttributeList;
- }
-
- private:
- STARTUPINFOEXW startup_info_;
- DISALLOW_COPY_AND_ASSIGN(StartupInformation);
-};
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_STARTUP_INFORMATION_H_
diff --git a/base/win/windows_full.h b/base/win/windows_full.h
deleted file mode 100644
index 8b9e43a..0000000
--- a/base/win/windows_full.h
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 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.
-
-// This header is needed so that mojo typemap files can specify their dependence
-// on Windows.h. This can be removed once https://crbug.com/798763 is resolved.
-
-#ifndef BASE_WIN_WINDOWS_FULL_H
-#define BASE_WIN_WINDOWS_FULL_H
-
-#include <windows.h>
-
-#endif // BASE_WIN_WINDOWS_FULL_H
diff --git a/base/win/winrt_storage_util.cc b/base/win/winrt_storage_util.cc
deleted file mode 100644
index 262d817..0000000
--- a/base/win/winrt_storage_util.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2017 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/winrt_storage_util.h"
-
-#include <robuffer.h>
-#include <string.h>
-#include <wrl/client.h>
-
-#include "base/strings/string_util.h"
-#include "base/win/core_winrt_util.h"
-#include "base/win/scoped_hstring.h"
-
-namespace base {
-namespace win {
-
-using IBuffer = ABI::Windows::Storage::Streams::IBuffer;
-
-HRESULT GetPointerToBufferData(IBuffer* buffer, uint8_t** out, UINT32* length) {
- *out = nullptr;
-
- Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess>
- buffer_byte_access;
- HRESULT hr = buffer->QueryInterface(IID_PPV_ARGS(&buffer_byte_access));
- if (FAILED(hr))
- return hr;
-
- hr = buffer->get_Length(length);
- if (FAILED(hr))
- return hr;
-
- // Lifetime of the pointing buffer is controlled by the buffer object.
- return buffer_byte_access->Buffer(out);
-}
-
-HRESULT CreateIBufferFromData(const uint8_t* data,
- UINT32 length,
- Microsoft::WRL::ComPtr<IBuffer>* buffer) {
- *buffer = nullptr;
-
- Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBufferFactory>
- buffer_factory;
- HRESULT hr = base::win::GetActivationFactory<
- ABI::Windows::Storage::Streams::IBufferFactory,
- RuntimeClass_Windows_Storage_Streams_Buffer>(&buffer_factory);
- if (FAILED(hr))
- return hr;
-
- Microsoft::WRL::ComPtr<IBuffer> internal_buffer;
- hr = buffer_factory->Create(length, internal_buffer.GetAddressOf());
- if (FAILED(hr))
- return hr;
-
- hr = internal_buffer->put_Length(length);
- if (FAILED(hr))
- return hr;
-
- uint8_t* p_buffer_data;
- hr = GetPointerToBufferData(internal_buffer.Get(), &p_buffer_data, &length);
- if (FAILED(hr))
- return hr;
-
- memcpy(p_buffer_data, data, length);
-
- *buffer = std::move(internal_buffer);
-
- return S_OK;
-}
-
-} // namespace win
-} // namespace base
diff --git a/base/win/winrt_storage_util.h b/base/win/winrt_storage_util.h
deleted file mode 100644
index 8cf57d4..0000000
--- a/base/win/winrt_storage_util.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2017 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_WINRT_STORAGE_UTIL_H_
-#define BASE_WIN_WINRT_STORAGE_UTIL_H_
-
-#include <stdint.h>
-#include <windows.storage.streams.h>
-#include <wrl/client.h>
-
-namespace base {
-namespace win {
-
-// Gets an array of bytes in the |buffer|, |out| represents a array of
-// bytes used by byte stream read and write.
-HRESULT
-GetPointerToBufferData(ABI::Windows::Storage::Streams::IBuffer* buffer,
- uint8_t** out,
- UINT32* length);
-
-// Creates stream |buffer| from |data| that represents a array of bytes
-// and the |length| of bytes.
-HRESULT CreateIBufferFromData(
- const uint8_t* data,
- UINT32 length,
- Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer>* buffer);
-
-} // namespace win
-} // namespace base
-
-#endif // BASE_WIN_WINRT_STORAGE_UTIL_H_
diff --git a/build/gen.py b/build/gen.py
index 4bf84d9..22e6bc9 100755
--- a/build/gen.py
+++ b/build/gen.py
@@ -528,7 +528,6 @@
'base/win/registry.cc',
'base/win/scoped_handle.cc',
'base/win/scoped_process_information.cc',
- 'base/win/startup_information.cc',
])
libs.extend([