diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 20:36:28 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 20:36:28 +0000 |
commit | 822e2947f42a96cc29771f15013fe324037a9712 (patch) | |
tree | a83ff359afec5eb297bf58f2c44cd8037e89dd04 | |
parent | 0cb7bec2eb1b954e30de75305c974ecfee3c8efb (diff) | |
download | chromium_src-822e2947f42a96cc29771f15013fe324037a9712.zip chromium_src-822e2947f42a96cc29771f15013fe324037a9712.tar.gz chromium_src-822e2947f42a96cc29771f15013fe324037a9712.tar.bz2 |
Turn on file access checks on Win.
BUG=60211
Review URL: http://codereview.chromium.org/4222005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64960 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gypi | 4 | ||||
-rw-r--r-- | base/file_util_win.cc | 70 | ||||
-rw-r--r-- | base/file_version_info_win.cc | 4 | ||||
-rw-r--r-- | base/platform_file_win.cc | 10 | ||||
-rw-r--r-- | base/win/registry.cc | 24 | ||||
-rw-r--r-- | base/win_util.cc | 6 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 20 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shared_resources_data_source.cc | 6 | ||||
-rw-r--r-- | chrome/browser/download/save_package.cc | 9 | ||||
-rw-r--r-- | chrome/browser/io_thread.cc | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 27 | ||||
-rw-r--r-- | chrome/common/chrome_version_info.cc | 3 | ||||
-rw-r--r-- | net/base/ssl_config_service_win.cc | 8 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_win.cc | 8 | ||||
-rw-r--r-- | net/url_request/url_request_file_job.cc | 8 |
16 files changed, 184 insertions, 27 deletions
diff --git a/base/base.gypi b/base/base.gypi index a96e5e9..f9570aab 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -263,6 +263,8 @@ 'thread_local_storage_posix.cc', 'thread_local_storage_win.cc', 'thread_local_win.cc', + 'thread_restrictions.h', + 'thread_restrictions.cc', 'time.cc', 'time.h', 'time_win.cc', @@ -476,8 +478,6 @@ 'sync_socket.h', 'sync_socket_win.cc', 'sync_socket_posix.cc', - 'thread_restrictions.h', - 'thread_restrictions.cc', 'time_mac.cc', 'time_posix.cc', 'version.cc', diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 30d314f..4645acc 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -19,6 +19,7 @@ #include "base/win/scoped_handle.h" #include "base/string_number_conversions.h" #include "base/string_util.h" +#include "base/thread_restrictions.h" #include "base/time.h" #include "base/utf_string_conversions.h" #include "base/win_util.h" @@ -35,6 +36,8 @@ const DWORD kFileShareAll = // Helper for NormalizeFilePath(), defined below. bool DevicePathToDriveLetterPath(const FilePath& device_path, FilePath* drive_letter_path) { + base::ThreadRestrictions::AssertIOAllowed(); + // Get the mapping of drive letters to device paths. const int kDriveMappingSize = 1024; wchar_t drive_mapping[kDriveMappingSize] = {'\0'}; @@ -75,6 +78,7 @@ bool DevicePathToDriveLetterPath(const FilePath& device_path, } // namespace std::wstring GetDirectoryFromPath(const std::wstring& path) { + base::ThreadRestrictions::AssertIOAllowed(); wchar_t path_buffer[MAX_PATH]; wchar_t* file_ptr = NULL; if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0) @@ -87,6 +91,7 @@ std::wstring GetDirectoryFromPath(const std::wstring& path) { } bool AbsolutePath(FilePath* path) { + base::ThreadRestrictions::AssertIOAllowed(); wchar_t file_path_buf[MAX_PATH]; if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH)) return false; @@ -96,6 +101,8 @@ bool AbsolutePath(FilePath* path) { int CountFilesCreatedAfter(const FilePath& path, const base::Time& comparison_time) { + base::ThreadRestrictions::AssertIOAllowed(); + int file_count = 0; FILETIME comparison_filetime(comparison_time.ToFileTime()); @@ -123,6 +130,8 @@ int CountFilesCreatedAfter(const FilePath& path, } bool Delete(const FilePath& path, bool recursive) { + base::ThreadRestrictions::AssertIOAllowed(); + if (path.value().length() >= MAX_PATH) return false; @@ -161,6 +170,8 @@ bool Delete(const FilePath& path, bool recursive) { } bool DeleteAfterReboot(const FilePath& path) { + base::ThreadRestrictions::AssertIOAllowed(); + if (path.value().length() >= MAX_PATH) return false; @@ -170,6 +181,8 @@ bool DeleteAfterReboot(const FilePath& path) { } bool Move(const FilePath& from_path, const FilePath& to_path) { + base::ThreadRestrictions::AssertIOAllowed(); + // NOTE: I suspect we could support longer paths, but that would involve // analyzing all our usage of files. if (from_path.value().length() >= MAX_PATH || @@ -189,6 +202,8 @@ bool Move(const FilePath& from_path, const FilePath& to_path) { } bool ReplaceFile(const FilePath& from_path, const FilePath& to_path) { + base::ThreadRestrictions::AssertIOAllowed(); + // Make sure that the target file exists. HANDLE target_file = ::CreateFile( to_path.value().c_str(), @@ -208,6 +223,8 @@ bool ReplaceFile(const FilePath& from_path, const FilePath& to_path) { } bool CopyFile(const FilePath& from_path, const FilePath& to_path) { + base::ThreadRestrictions::AssertIOAllowed(); + // NOTE: I suspect we could support longer paths, but that would involve // analyzing all our usage of files. if (from_path.value().length() >= MAX_PATH || @@ -220,6 +237,8 @@ bool CopyFile(const FilePath& from_path, const FilePath& to_path) { bool ShellCopy(const FilePath& from_path, const FilePath& to_path, bool recursive) { + base::ThreadRestrictions::AssertIOAllowed(); + // NOTE: I suspect we could support longer paths, but that would involve // analyzing all our usage of files. if (from_path.value().length() >= MAX_PATH || @@ -251,6 +270,8 @@ bool ShellCopy(const FilePath& from_path, const FilePath& to_path, bool CopyDirectory(const FilePath& from_path, const FilePath& to_path, bool recursive) { + base::ThreadRestrictions::AssertIOAllowed(); + if (recursive) return ShellCopy(from_path, to_path, true); @@ -274,6 +295,7 @@ bool CopyDirectory(const FilePath& from_path, const FilePath& to_path, bool CopyAndDeleteDirectory(const FilePath& from_path, const FilePath& to_path) { + base::ThreadRestrictions::AssertIOAllowed(); if (CopyDirectory(from_path, to_path, true)) { if (Delete(from_path, true)) { return true; @@ -288,10 +310,12 @@ bool CopyAndDeleteDirectory(const FilePath& from_path, bool PathExists(const FilePath& path) { + base::ThreadRestrictions::AssertIOAllowed(); return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES); } bool PathIsWritable(const FilePath& path) { + base::ThreadRestrictions::AssertIOAllowed(); HANDLE dir = CreateFile(path.value().c_str(), FILE_ADD_FILE, kFileShareAll, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); @@ -304,6 +328,7 @@ bool PathIsWritable(const FilePath& path) { } bool DirectoryExists(const FilePath& path) { + base::ThreadRestrictions::AssertIOAllowed(); DWORD fileattr = GetFileAttributes(path.value().c_str()); if (fileattr != INVALID_FILE_ATTRIBUTES) return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; @@ -312,6 +337,7 @@ bool DirectoryExists(const FilePath& path) { bool GetFileCreationLocalTimeFromHandle(HANDLE file_handle, LPSYSTEMTIME creation_time) { + base::ThreadRestrictions::AssertIOAllowed(); if (!file_handle) return false; @@ -328,6 +354,7 @@ bool GetFileCreationLocalTimeFromHandle(HANDLE file_handle, bool GetFileCreationLocalTime(const std::wstring& filename, LPSYSTEMTIME creation_time) { + base::ThreadRestrictions::AssertIOAllowed(); base::win::ScopedHandle file_handle( CreateFile(filename.c_str(), GENERIC_READ, kFileShareAll, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); @@ -335,6 +362,8 @@ bool GetFileCreationLocalTime(const std::wstring& filename, } bool ResolveShortcut(FilePath* path) { + base::ThreadRestrictions::AssertIOAllowed(); + HRESULT result; base::win::ScopedComPtr<IShellLink> i_shell_link; bool is_resolved = false; @@ -370,6 +399,8 @@ bool CreateShortcutLink(const wchar_t *source, const wchar_t *destination, const wchar_t *working_dir, const wchar_t *arguments, const wchar_t *description, const wchar_t *icon, int icon_index, const wchar_t* app_id) { + base::ThreadRestrictions::AssertIOAllowed(); + // Length of arguments and description must be less than MAX_PATH. DCHECK(lstrlen(arguments) < MAX_PATH); DCHECK(lstrlen(description) < MAX_PATH); @@ -421,6 +452,8 @@ bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination, const wchar_t *working_dir, const wchar_t *arguments, const wchar_t *description, const wchar_t *icon, int icon_index, const wchar_t* app_id) { + base::ThreadRestrictions::AssertIOAllowed(); + // Length of arguments and description must be less than MAX_PATH. DCHECK(lstrlen(arguments) < MAX_PATH); DCHECK(lstrlen(description) < MAX_PATH); @@ -467,6 +500,8 @@ bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination, } bool TaskbarPinShortcutLink(const wchar_t* shortcut) { + base::ThreadRestrictions::AssertIOAllowed(); + // "Pin to taskbar" is only supported after Win7. if (base::win::GetVersion() < base::win::VERSION_WIN7) return false; @@ -477,6 +512,8 @@ bool TaskbarPinShortcutLink(const wchar_t* shortcut) { } bool TaskbarUnpinShortcutLink(const wchar_t* shortcut) { + base::ThreadRestrictions::AssertIOAllowed(); + // "Unpin from taskbar" is only supported after Win7. if (base::win::GetVersion() < base::win::VERSION_WIN7) return false; @@ -487,6 +524,8 @@ bool TaskbarUnpinShortcutLink(const wchar_t* shortcut) { } bool GetTempDir(FilePath* path) { + base::ThreadRestrictions::AssertIOAllowed(); + wchar_t temp_path[MAX_PATH + 1]; DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); if (path_len >= MAX_PATH || path_len <= 0) @@ -503,6 +542,8 @@ bool GetShmemTempDir(FilePath* path) { } bool CreateTemporaryFile(FilePath* path) { + base::ThreadRestrictions::AssertIOAllowed(); + FilePath temp_file; if (!GetTempDir(path)) @@ -517,6 +558,7 @@ bool CreateTemporaryFile(FilePath* path) { } FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) { + base::ThreadRestrictions::AssertIOAllowed(); return CreateAndOpenTemporaryFile(path); } @@ -525,6 +567,7 @@ FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) { // TODO(jrg): is there equivalent call to use on Windows instead of // going 2-step? FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { + base::ThreadRestrictions::AssertIOAllowed(); if (!CreateTemporaryFileInDir(dir, path)) { return NULL; } @@ -536,6 +579,8 @@ FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { bool CreateTemporaryFileInDir(const FilePath& dir, FilePath* temp_file) { + base::ThreadRestrictions::AssertIOAllowed(); + wchar_t temp_name[MAX_PATH + 1]; if (!GetTempFileName(dir.value().c_str(), L"", 0, temp_name)) { @@ -558,6 +603,8 @@ bool CreateTemporaryFileInDir(const FilePath& dir, bool CreateTemporaryDirInDir(const FilePath& base_dir, const FilePath::StringType& prefix, FilePath* new_dir) { + base::ThreadRestrictions::AssertIOAllowed(); + FilePath path_to_create; srand(static_cast<uint32>(time(NULL))); @@ -582,6 +629,8 @@ bool CreateTemporaryDirInDir(const FilePath& base_dir, bool CreateNewTempDirectory(const FilePath::StringType& prefix, FilePath* new_temp_path) { + base::ThreadRestrictions::AssertIOAllowed(); + FilePath system_temp_dir; if (!GetTempDir(&system_temp_dir)) return false; @@ -590,6 +639,8 @@ bool CreateNewTempDirectory(const FilePath::StringType& prefix, } bool CreateDirectory(const FilePath& full_path) { + base::ThreadRestrictions::AssertIOAllowed(); + // If the path exists, we've succeeded if it's a directory, failed otherwise. const wchar_t* full_path_str = full_path.value().c_str(); DWORD fileattr = ::GetFileAttributes(full_path_str); @@ -636,6 +687,8 @@ bool CreateDirectory(const FilePath& full_path) { } bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { + base::ThreadRestrictions::AssertIOAllowed(); + WIN32_FILE_ATTRIBUTE_DATA attr; if (!GetFileAttributesEx(file_path.value().c_str(), GetFileExInfoStandard, &attr)) { @@ -657,15 +710,18 @@ bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { } FILE* OpenFile(const FilePath& filename, const char* mode) { + base::ThreadRestrictions::AssertIOAllowed(); std::wstring w_mode = ASCIIToWide(std::string(mode)); return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); } FILE* OpenFile(const std::string& filename, const char* mode) { + base::ThreadRestrictions::AssertIOAllowed(); return _fsopen(filename.c_str(), mode, _SH_DENYNO); } int ReadFile(const FilePath& filename, char* data, int size) { + base::ThreadRestrictions::AssertIOAllowed(); base::win::ScopedHandle file(CreateFile(filename.value().c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -684,6 +740,7 @@ int ReadFile(const FilePath& filename, char* data, int size) { } int WriteFile(const FilePath& filename, const char* data, int size) { + base::ThreadRestrictions::AssertIOAllowed(); base::win::ScopedHandle file(CreateFile(filename.value().c_str(), GENERIC_WRITE, 0, @@ -718,6 +775,8 @@ int WriteFile(const FilePath& filename, const char* data, int size) { bool RenameFileAndResetSecurityDescriptor(const FilePath& source_file_path, const FilePath& target_file_path) { + base::ThreadRestrictions::AssertIOAllowed(); + // The parameters to SHFileOperation must be terminated with 2 NULL chars. std::wstring source = source_file_path.value(); std::wstring target = target_file_path.value(); @@ -740,6 +799,8 @@ bool RenameFileAndResetSecurityDescriptor(const FilePath& source_file_path, // Gets the current working directory for the process. bool GetCurrentDirectory(FilePath* dir) { + base::ThreadRestrictions::AssertIOAllowed(); + wchar_t system_buffer[MAX_PATH]; system_buffer[0] = 0; DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); @@ -755,6 +816,7 @@ bool GetCurrentDirectory(FilePath* dir) { // Sets the current working directory for the process. bool SetCurrentDirectory(const FilePath& directory) { + base::ThreadRestrictions::AssertIOAllowed(); BOOL ret = ::SetCurrentDirectory(directory.value().c_str()); return ret != 0; } @@ -812,6 +874,8 @@ FilePath FileEnumerator::GetFilename(const FindInfo& find_info) { } FilePath FileEnumerator::Next() { + base::ThreadRestrictions::AssertIOAllowed(); + while (has_find_data_ || !pending_paths_.empty()) { if (!has_find_data_) { // The last find FindFirstFile operation is done, prepare a new one. @@ -883,6 +947,8 @@ MemoryMappedFile::MemoryMappedFile() } bool MemoryMappedFile::MapFileToMemoryInternal() { + base::ThreadRestrictions::AssertIOAllowed(); + if (file_ == INVALID_HANDLE_VALUE) return false; @@ -926,12 +992,14 @@ void MemoryMappedFile::CloseHandles() { bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, const base::Time& cutoff_time) { + base::ThreadRestrictions::AssertIOAllowed(); long result = CompareFileTime(&find_info.ftLastWriteTime, &cutoff_time.ToFileTime()); return result == 1 || result == 0; } bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { + base::ThreadRestrictions::AssertIOAllowed(); FilePath mapped_file; if (!NormalizeToNativeFilePath(path, &mapped_file)) return false; @@ -943,6 +1011,7 @@ bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { } bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { + base::ThreadRestrictions::AssertIOAllowed(); // In Vista, GetFinalPathNameByHandle() would give us the real path // from a file handle. If we ever deprecate XP, consider changing the // code below to a call to GetFinalPathNameByHandle(). The method this @@ -998,6 +1067,7 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { bool PreReadImage(const wchar_t* file_path, size_t size_to_read, size_t step_size) { + base::ThreadRestrictions::AssertIOAllowed(); if (base::win::GetVersion() > base::win::VERSION_XP) { // Vista+ branch. On these OSes, the forced reads through the DLL actually // slows warm starts. The solution is to sequentially read file contents diff --git a/base/file_version_info_win.cc b/base/file_version_info_win.cc index d1049b8..6c69708 100644 --- a/base/file_version_info_win.cc +++ b/base/file_version_info_win.cc @@ -10,12 +10,14 @@ #include "base/file_version_info.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/thread_restrictions.h" // This has to be last. #include <strsafe.h> FileVersionInfoWin::FileVersionInfoWin(void* data, int language, int code_page) : language_(language), code_page_(code_page) { + base::ThreadRestrictions::AssertIOAllowed(); data_.reset((char*) data); fixed_file_info_ = NULL; UINT size; @@ -43,6 +45,8 @@ FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { // static FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( const FilePath& file_path) { + base::ThreadRestrictions::AssertIOAllowed(); + DWORD dummy; const wchar_t* path = file_path.value().c_str(); DWORD length = ::GetFileVersionInfoSize(path, &dummy); diff --git a/base/platform_file_win.cc b/base/platform_file_win.cc index 3aa02e8..34d8e45 100644 --- a/base/platform_file_win.cc +++ b/base/platform_file_win.cc @@ -6,6 +6,7 @@ #include "base/file_path.h" #include "base/logging.h" +#include "base/thread_restrictions.h" namespace base { @@ -13,6 +14,8 @@ PlatformFile CreatePlatformFile(const FilePath& name, int flags, bool* created, PlatformFileError* error_code) { + base::ThreadRestrictions::AssertIOAllowed(); + DWORD disposition = 0; if (flags & PLATFORM_FILE_OPEN) @@ -108,10 +111,12 @@ PlatformFile CreatePlatformFile(const std::wstring& name, int flags, } bool ClosePlatformFile(PlatformFile file) { + base::ThreadRestrictions::AssertIOAllowed(); return (CloseHandle(file) != 0); } int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { + base::ThreadRestrictions::AssertIOAllowed(); if (file == kInvalidPlatformFileValue) return -1; @@ -133,6 +138,7 @@ int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { int WritePlatformFile(PlatformFile file, int64 offset, const char* data, int size) { + base::ThreadRestrictions::AssertIOAllowed(); if (file == kInvalidPlatformFileValue) return -1; @@ -151,6 +157,7 @@ int WritePlatformFile(PlatformFile file, int64 offset, } bool TruncatePlatformFile(PlatformFile file, int64 length) { + base::ThreadRestrictions::AssertIOAllowed(); if (file == kInvalidPlatformFileValue) return false; @@ -176,11 +183,13 @@ bool TruncatePlatformFile(PlatformFile file, int64 length) { } bool FlushPlatformFile(PlatformFile file) { + base::ThreadRestrictions::AssertIOAllowed(); return ((file != kInvalidPlatformFileValue) && ::FlushFileBuffers(file)); } bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time, const base::Time& last_modified_time) { + base::ThreadRestrictions::AssertIOAllowed(); if (file == kInvalidPlatformFileValue) return false; @@ -191,6 +200,7 @@ bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time, } bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info) { + base::ThreadRestrictions::AssertIOAllowed(); if (!info) return false; diff --git a/base/win/registry.cc b/base/win/registry.cc index 545c337..977ea00 100644 --- a/base/win/registry.cc +++ b/base/win/registry.cc @@ -7,6 +7,7 @@ #include <shlwapi.h> #include "base/logging.h" +#include "base/thread_restrictions.h" #pragma comment(lib, "shlwapi.lib") // for SHDeleteKey @@ -15,6 +16,8 @@ namespace win { RegistryValueIterator::RegistryValueIterator(HKEY root_key, const wchar_t* folder_key) { + base::ThreadRestrictions::AssertIOAllowed(); + LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); if (result != ERROR_SUCCESS) { key_ = NULL; @@ -35,6 +38,7 @@ RegistryValueIterator::RegistryValueIterator(HKEY root_key, } RegistryValueIterator::~RegistryValueIterator() { + base::ThreadRestrictions::AssertIOAllowed(); if (key_) ::RegCloseKey(key_); } @@ -49,6 +53,7 @@ void RegistryValueIterator::operator++() { } bool RegistryValueIterator::Read() { + base::ThreadRestrictions::AssertIOAllowed(); if (Valid()) { DWORD ncount = arraysize(name_); value_size_ = sizeof(value_); @@ -65,6 +70,7 @@ bool RegistryValueIterator::Read() { } DWORD RegistryValueIterator::ValueCount() const { + base::ThreadRestrictions::AssertIOAllowed(); DWORD count = 0; HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, &count, NULL, NULL, NULL, NULL); @@ -77,6 +83,7 @@ DWORD RegistryValueIterator::ValueCount() const { RegistryKeyIterator::RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key) { + base::ThreadRestrictions::AssertIOAllowed(); LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); if (result != ERROR_SUCCESS) { key_ = NULL; @@ -97,6 +104,7 @@ RegistryKeyIterator::RegistryKeyIterator(HKEY root_key, } RegistryKeyIterator::~RegistryKeyIterator() { + base::ThreadRestrictions::AssertIOAllowed(); if (key_) ::RegCloseKey(key_); } @@ -111,6 +119,7 @@ void RegistryKeyIterator::operator++() { } bool RegistryKeyIterator::Read() { + base::ThreadRestrictions::AssertIOAllowed(); if (Valid()) { DWORD ncount = arraysize(name_); FILETIME written; @@ -125,6 +134,7 @@ bool RegistryKeyIterator::Read() { } DWORD RegistryKeyIterator::SubkeyCount() const { + base::ThreadRestrictions::AssertIOAllowed(); DWORD count = 0; HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -143,6 +153,7 @@ RegKey::RegKey() RegKey::RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access) : key_(NULL), watch_event_(0) { + base::ThreadRestrictions::AssertIOAllowed(); if (rootkey) { if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) Create(rootkey, subkey, access); @@ -158,6 +169,7 @@ RegKey::~RegKey() { } void RegKey::Close() { + base::ThreadRestrictions::AssertIOAllowed(); StopWatching(); if (key_) { ::RegCloseKey(key_); @@ -172,6 +184,7 @@ bool RegKey::Create(HKEY rootkey, const wchar_t* subkey, REGSAM access) { bool RegKey::CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, DWORD* disposition, REGSAM access) { + base::ThreadRestrictions::AssertIOAllowed(); DCHECK(rootkey && subkey && access && disposition); Close(); @@ -193,6 +206,7 @@ bool RegKey::CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, } bool RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) { + base::ThreadRestrictions::AssertIOAllowed(); DCHECK(rootkey && subkey && access); Close(); @@ -205,6 +219,7 @@ bool RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) { } bool RegKey::CreateKey(const wchar_t* name, REGSAM access) { + base::ThreadRestrictions::AssertIOAllowed(); DCHECK(name && access); HKEY subkey = NULL; @@ -217,6 +232,7 @@ bool RegKey::CreateKey(const wchar_t* name, REGSAM access) { } bool RegKey::OpenKey(const wchar_t* name, REGSAM access) { + base::ThreadRestrictions::AssertIOAllowed(); DCHECK(name && access); HKEY subkey = NULL; @@ -229,6 +245,7 @@ bool RegKey::OpenKey(const wchar_t* name, REGSAM access) { } DWORD RegKey::ValueCount() { + base::ThreadRestrictions::AssertIOAllowed(); DWORD count = 0; HRESULT result = RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, &count, NULL, NULL, NULL, NULL); @@ -236,6 +253,7 @@ DWORD RegKey::ValueCount() { } bool RegKey::ReadName(int index, std::wstring* name) { + base::ThreadRestrictions::AssertIOAllowed(); wchar_t buf[256]; DWORD bufsize = arraysize(buf); LRESULT r = ::RegEnumValue(key_, index, buf, &bufsize, NULL, NULL, @@ -248,6 +266,7 @@ bool RegKey::ReadName(int index, std::wstring* name) { } bool RegKey::ValueExists(const wchar_t* name) { + base::ThreadRestrictions::AssertIOAllowed(); if (!key_) return false; HRESULT result = RegQueryValueEx(key_, name, 0, NULL, NULL, NULL); @@ -256,6 +275,7 @@ bool RegKey::ValueExists(const wchar_t* name) { bool RegKey::ReadValue(const wchar_t* name, void* data, DWORD* dsize, DWORD* dtype) { + base::ThreadRestrictions::AssertIOAllowed(); if (!key_) return false; HRESULT result = RegQueryValueEx(key_, name, 0, dtype, @@ -264,6 +284,7 @@ bool RegKey::ReadValue(const wchar_t* name, void* data, } bool RegKey::ReadValue(const wchar_t* name, std::wstring* value) { + base::ThreadRestrictions::AssertIOAllowed(); DCHECK(value); const size_t kMaxStringLength = 1024; // This is after expansion. // Use the one of the other forms of ReadValue if 1024 is too small for you. @@ -308,6 +329,7 @@ bool RegKey::ReadValueDW(const wchar_t* name, DWORD* value) { bool RegKey::WriteValue(const wchar_t* name, const void * data, DWORD dsize, DWORD dtype) { + base::ThreadRestrictions::AssertIOAllowed(); DCHECK(data); if (!key_) @@ -334,10 +356,12 @@ bool RegKey::WriteValue(const wchar_t* name, DWORD value) { } bool RegKey::DeleteKey(const wchar_t* name) { + base::ThreadRestrictions::AssertIOAllowed(); return (!key_) ? false : (ERROR_SUCCESS == SHDeleteKey(key_, name)); } bool RegKey::DeleteValue(const wchar_t* value_name) { + base::ThreadRestrictions::AssertIOAllowed(); DCHECK(value_name); HRESULT result = RegDeleteValue(key_, value_name); return (result == ERROR_SUCCESS); diff --git a/base/win_util.cc b/base/win_util.cc index a576122..3fcfb92 100644 --- a/base/win_util.cc +++ b/base/win_util.cc @@ -17,6 +17,7 @@ #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/stringprintf.h" +#include "base/thread_restrictions.h" #include "base/win/windows_version.h" namespace win_util { @@ -127,6 +128,11 @@ std::wstring GetClassName(HWND window) { } bool UserAccountControlIsEnabled() { + // This can be slow if Windows ends up going to disk. Should watch this key + // for changes and only read it once, preferably on the file thread. + // http://code.google.com/p/chromium/issues/detail?id=61644 + base::ThreadRestrictions::ScopedAllowIO allow_io; + base::win::RegKey key(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", KEY_READ); diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index bf4d385..446bca6 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -376,13 +376,19 @@ void Browser::CreateBrowserWindow() { window_ = BrowserWindow::CreateBrowserWindow(this); #if defined(OS_WIN) - // Set the app user model id for this application to that of the application - // name. See http://crbug.com/7028. - win_util::SetAppIdForWindow( - type_ & TYPE_APP ? - ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : - ShellIntegration::GetChromiumAppId(profile_->GetPath()), - window()->GetNativeHandle()); + { + // TODO: This might hit the disk + // http://code.google.com/p/chromium/issues/detail?id=61638 + base::ThreadRestrictions::ScopedAllowIO allow_io; + + // Set the app user model id for this application to that of the application + // name. See http://crbug.com/7028. + win_util::SetAppIdForWindow( + type_ & TYPE_APP ? + ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : + ShellIntegration::GetChromiumAppId(profile_->GetPath()), + window()->GetNativeHandle()); + } #endif NotificationService::current()->Notify( diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 9e33f68..2452da3 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -483,7 +483,7 @@ void HandleTestParameters(const CommandLine& command_line) { void RunUIMessageLoop(BrowserProcess* browser_process) { TRACE_EVENT_BEGIN("BrowserMain:MESSAGE_LOOP", 0, ""); -#if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) +#if !defined(OS_CHROMEOS) // If the UI thread blocks, the whole UI is unresponsive. // Do not allow disk IO from the UI thread. // TODO(evanm): turn this on for all platforms. diff --git a/chrome/browser/dom_ui/shared_resources_data_source.cc b/chrome/browser/dom_ui/shared_resources_data_source.cc index 43257a2..2c51470 100644 --- a/chrome/browser/dom_ui/shared_resources_data_source.cc +++ b/chrome/browser/dom_ui/shared_resources_data_source.cc @@ -6,6 +6,7 @@ #include "app/resource_bundle.h" #include "base/singleton.h" +#include "base/thread_restrictions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" @@ -79,6 +80,11 @@ void SharedResourcesDataSource::StartDataRequest(const std::string& path, std::string SharedResourcesDataSource::GetMimeType( const std::string& path) const { + // Requests should not block on the disk! On Windows this goes to the + // registry. + // http://code.google.com/p/chromium/issues/detail?id=59849 + base::ThreadRestrictions::ScopedAllowIO allow_io; + std::string mime_type; net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); return mime_type; diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 473a795..d637cda 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -13,6 +13,7 @@ #include "base/stl_util-inl.h" #include "base/string_piece.h" #include "base/string_split.h" +#include "base/thread_restrictions.h" #include "base/utf_string_conversions.h" #include "base/task.h" #include "base/thread.h" @@ -1158,6 +1159,10 @@ FilePath SavePackage::GetSuggestedNameForSaveAs( } FilePath SavePackage::EnsureHtmlExtension(const FilePath& name) { + // The GetMimeTypeFromExtension call will end up going to disk. Do this on + // another thread to avoid slowing the UI thread. http://crbug.com/61775 + base::ThreadRestrictions::ScopedAllowIO allow_io; + // If the file name doesn't have an extension suitable for HTML files, // append one. FilePath::StringType ext = name.Extension(); @@ -1174,6 +1179,10 @@ FilePath SavePackage::EnsureHtmlExtension(const FilePath& name) { FilePath SavePackage::EnsureMimeExtension(const FilePath& name, const FilePath::StringType& contents_mime_type) { + // The GetMimeTypeFromExtension call will end up going to disk. Do this on + // another thread to avoid slowing the UI thread. http://crbug.com/61775 + base::ThreadRestrictions::ScopedAllowIO allow_io; + // Start extension at 1 to skip over period if non-empty. FilePath::StringType ext = name.Extension().length() ? name.Extension().substr(1) : name.Extension(); diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 55713b7..9f40c50 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -257,7 +257,7 @@ net::ProxyScriptFetcher* IOThread::CreateAndRegisterProxyScriptFetcher( } void IOThread::Init() { -#if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) +#if !defined(OS_CHROMEOS) // TODO(evan): test and enable this on all platforms. // Though this thread is called the "IO" thread, it actually just routes // messages around; it shouldn't be allowed to perform any blocking disk I/O. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index e30970c..e49c463 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -110,6 +110,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/password_form.h" +#include "webkit/glue/plugins/plugin_list.h" // Cross-Site Navigations // @@ -2026,25 +2027,19 @@ void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { DCHECK(!plugin_path.value().empty()); std::wstring plugin_name = plugin_path.ToWStringHack(); -#if defined(OS_WIN) || defined(OS_MACOSX) - scoped_ptr<FileVersionInfo> version_info( - FileVersionInfo::CreateFileVersionInfo(plugin_path)); - if (version_info.get()) { - const std::wstring& product_name = version_info->product_name(); - if (!product_name.empty()) { - plugin_name = product_name; + WebPluginInfo plugin_info; + if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath( + plugin_path, &plugin_info) && + !plugin_info.name.empty()) { + plugin_name = UTF16ToWide(plugin_info.name); #if defined(OS_MACOSX) - // Many plugins on the Mac have .plugin in the actual name, which looks - // terrible, so look for that and strip it off if present. - const std::wstring plugin_extension(L".plugin"); - if (EndsWith(plugin_name, plugin_extension, true)) - plugin_name.erase(plugin_name.length() - plugin_extension.length()); + // Many plugins on the Mac have .plugin in the actual name, which looks + // terrible, so look for that and strip it off if present. + const std::wstring plugin_extension(L".plugin"); + if (EndsWith(plugin_name, plugin_extension, true)) + plugin_name.erase(plugin_name.length() - plugin_extension.length()); #endif // OS_MACOSX - } } -#else - NOTIMPLEMENTED() << " convert plugin path to plugin name"; -#endif SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_INFOBAR_PLUGIN_CRASHED); AddInfoBar(new SimpleAlertInfoBarDelegate( diff --git a/chrome/common/chrome_version_info.cc b/chrome/common/chrome_version_info.cc index a26f81f..5157c4a 100644 --- a/chrome/common/chrome_version_info.cc +++ b/chrome/common/chrome_version_info.cc @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "base/file_version_info.h" #include "base/string_util.h" +#include "base/thread_restrictions.h" #include "build/build_config.h" namespace chrome { @@ -16,6 +17,8 @@ namespace chrome { // FileVersionInfo for the current module. VersionInfo::VersionInfo() { + // The current module is already loaded in memory, so this will be cheap. + base::ThreadRestrictions::ScopedAllowIO allow_io; version_info_.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule()); } diff --git a/net/base/ssl_config_service_win.cc b/net/base/ssl_config_service_win.cc index 14c4d24..debea7d 100644 --- a/net/base/ssl_config_service_win.cc +++ b/net/base/ssl_config_service_win.cc @@ -4,6 +4,7 @@ #include "net/base/ssl_config_service_win.h" +#include "base/thread_restrictions.h" #include "base/win/registry.h" using base::TimeDelta; @@ -59,6 +60,9 @@ void SSLConfigServiceWin::GetSSLConfigAt(SSLConfig* config, TimeTicks now) { // static bool SSLConfigServiceWin::GetSSLConfigNow(SSLConfig* config) { + // This registry access goes to disk and will slow down the IO thread. + // http://crbug.com/61455 + base::ThreadRestrictions::ScopedAllowIO allow_io; RegKey internet_settings; if (!internet_settings.Open(HKEY_CURRENT_USER, kInternetSettingsSubKeyName, KEY_READ)) @@ -83,6 +87,8 @@ bool SSLConfigServiceWin::GetSSLConfigNow(SSLConfig* config) { // static void SSLConfigServiceWin::SetRevCheckingEnabled(bool enabled) { + // This registry access goes to disk and will slow down the IO thread. + // http://crbug.com/61455 DWORD value = enabled; RegKey internet_settings(HKEY_CURRENT_USER, kInternetSettingsSubKeyName, KEY_WRITE); @@ -108,6 +114,8 @@ void SSLConfigServiceWin::SetTLS1Enabled(bool enabled) { // static void SSLConfigServiceWin::SetSSLVersionEnabled(int version, bool enabled) { + // This registry access goes to disk and will slow down the IO thread. + // http://crbug.com/61455 RegKey internet_settings(HKEY_CURRENT_USER, kInternetSettingsSubKeyName, KEY_READ | KEY_WRITE); DWORD value; diff --git a/net/proxy/proxy_config_service_win.cc b/net/proxy/proxy_config_service_win.cc index d0a387f..5aca4ae 100644 --- a/net/proxy/proxy_config_service_win.cc +++ b/net/proxy/proxy_config_service_win.cc @@ -12,6 +12,7 @@ #include "base/string_tokenizer.h" #include "base/string_util.h" #include "base/stl_util-inl.h" +#include "base/thread_restrictions.h" #include "base/win/registry.h" #include "net/base/net_errors.h" #include "net/proxy/proxy_config.h" @@ -72,6 +73,9 @@ ProxyConfigServiceWin::ProxyConfigServiceWin() } ProxyConfigServiceWin::~ProxyConfigServiceWin() { + // The registry functions below will end up going to disk. Do this on another + // thread to avoid slowing the IO thread. http://crbug.com/61453 + base::ThreadRestrictions::ScopedAllowIO allow_io; STLDeleteElements(&keys_to_watch_); } @@ -87,6 +91,10 @@ void ProxyConfigServiceWin::StartWatchingRegistryForChanges() { if (!keys_to_watch_.empty()) return; // Already initialized. + // The registry functions below will end up going to disk. Do this on another + // thread to avoid slowing the IO thread. http://crbug.com/61453 + base::ThreadRestrictions::ScopedAllowIO allow_io; + // There are a number of different places where proxy settings can live // in the registry. In some cases it appears in a binary value, in other // cases string values. Furthermore winhttp and wininet appear to have diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc index f9c6559..fff85c3 100644 --- a/net/url_request/url_request_file_job.cc +++ b/net/url_request/url_request_file_job.cc @@ -203,6 +203,10 @@ bool URLRequestFileJob::GetContentEncodings( } bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { + // URL requests should not block on the disk! On Windows this goes to the + // registry. + // http://code.google.com/p/chromium/issues/detail?id=59849 + base::ThreadRestrictions::ScopedAllowIO allow_io; DCHECK(request_); return net::GetMimeTypeFromFile(file_path_, mime_type); } @@ -252,6 +256,10 @@ void URLRequestFileJob::DidResolve( if (!exists) { rv = net::ERR_FILE_NOT_FOUND; } else if (!is_directory_) { + // URL requests should not block on the disk! + // http://code.google.com/p/chromium/issues/detail?id=59849 + base::ThreadRestrictions::ScopedAllowIO allow_io; + int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC; |