Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/fileapi/mtp_device_interface_win.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 #define CLIENT_NAME L"WPD Chromium" | |
| 10 #define CLIENT_MAJOR_VER 1 | |
| 11 #define CLIENT_MINOR_VER 0 | |
| 12 #define CLIENT_REVISION 2 | |
| 13 | |
| 14 namespace fileapi { | |
| 15 | |
| 16 MtpDeviceInterfaceWin::MtpDeviceInterfaceWin( | |
| 17 const FilePath::StringType& device_id) | |
| 18 : device_id_(device_id) { | |
| 19 CoInitialize(NULL); | |
| 20 bool res = Init(); | |
| 21 DCHECK(res); | |
| 22 } | |
| 23 | |
| 24 MtpDeviceInterfaceWin::~MtpDeviceInterfaceWin() { | |
| 25 pdevice_.Release(); | |
| 26 CoUninitialize(); | |
|
kinuko
2012/07/26 00:38:06
Is it really ok to call these on another thread fr
kmadhusu
2012/07/27 02:13:41
That should be okay. I removed the win specific co
| |
| 27 } | |
| 28 | |
| 29 bool MtpDeviceInterfaceWin::Init() { | |
| 30 HRESULT hr = pdevice_.CreateInstance(__uuidof(PortableDevice), | |
| 31 NULL, | |
| 32 CLSCTX_INPROC_SERVER); | |
| 33 if (FAILED(hr)) | |
| 34 return false; | |
| 35 | |
| 36 base::win::ScopedComPtr<IPortableDeviceValues> client_info; | |
| 37 // Fill out information about your application, so the device knows | |
| 38 // who they are speaking to. Client information is optional. The client | |
| 39 // can choose to identify itself, or to remain unknown to the driver. It is | |
| 40 // beneficial to identify yourself because drivers may be able to optimize | |
| 41 // their behavior for known clients. | |
| 42 | |
| 43 // CoCreate an IPortableDeviceValues interface to hold the client | |
| 44 // information. | |
| 45 hr = client_info.CreateInstance(__uuidof(PortableDeviceValues), | |
| 46 NULL, | |
| 47 CLSCTX_INPROC_SERVER); | |
| 48 if (FAILED(hr)) | |
| 49 return false; | |
| 50 | |
| 51 // Attempt to set all bits of client information | |
| 52 hr = client_info->SetStringValue(WPD_CLIENT_NAME, CLIENT_NAME); | |
| 53 if (FAILED(hr)) | |
| 54 LOG(INFO) << "Failed to set WPD_CLIENT_NAME "; | |
| 55 | |
| 56 hr = client_info->SetUnsignedIntegerValue(WPD_CLIENT_MAJOR_VERSION, | |
| 57 CLIENT_MAJOR_VER); | |
| 58 if (FAILED(hr)) | |
| 59 LOG(INFO) << "Failed to set WPD_CLIENT_MAJOR_VERSION"; | |
| 60 | |
| 61 hr = client_info->SetUnsignedIntegerValue(WPD_CLIENT_REVISION, | |
| 62 CLIENT_REVISION); | |
| 63 if (FAILED(hr)) | |
| 64 LOG(INFO) << "Failed to set WPD_CLIENT_REVISION"; | |
| 65 | |
| 66 // Some device drivers need to impersonate the caller in order to function | |
| 67 // correctly. Since our application does not need to restrict its identity, | |
| 68 // specify SECURITY_IMPERSONATION so that we work with all devices. | |
| 69 hr = client_info->SetUnsignedIntegerValue( | |
| 70 WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, SECURITY_IMPERSONATION); | |
| 71 if (FAILED(hr)) | |
| 72 LOG(INFO) << "Failed to set WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE"; | |
| 73 | |
| 74 hr = pdevice_->Open(const_cast<wchar_t*>(device_id_.c_str()), client_info); | |
| 75 if (FAILED(hr)) { | |
| 76 if (hr == E_ACCESSDENIED) { | |
| 77 // Failed to Open the device for Read Write access, will open it for | |
| 78 // Read-only access instead. | |
| 79 client_info->SetUnsignedIntegerValue(WPD_CLIENT_DESIRED_ACCESS, | |
| 80 GENERIC_READ); | |
| 81 hr = pdevice_->Open(const_cast<wchar_t*>(device_id_.c_str()), | |
| 82 client_info); | |
| 83 if (FAILED(hr)) | |
| 84 return false; | |
| 85 } else { | |
| 86 return false; | |
| 87 } | |
| 88 } | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 PlatformFileError MtpDeviceInterfaceWin::GetFileInfo( | |
| 93 const FilePath& file_path, | |
| 94 PlatformFileInfo* file_info) { | |
| 95 NOTIMPLEMENTED(); | |
| 96 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 97 } | |
| 98 | |
| 99 FileSystemFileUtil::AbstractFileEnumerator* | |
| 100 MtpDeviceInterfaceWin::CreateFileEnumerator( | |
| 101 const FilePath& root, | |
| 102 bool recursive) { | |
| 103 NOTIMPLEMENTED(); | |
| 104 return new FileSystemFileUtil::EmptyFileEnumerator(); | |
| 105 } | |
| 106 | |
| 107 PlatformFileError MtpDeviceInterfaceWin::Touch( | |
| 108 const FilePath& file_path, | |
| 109 const base::Time& last_access_time, | |
| 110 const base::Time& last_modified_time) { | |
| 111 NOTIMPLEMENTED(); | |
| 112 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 113 } | |
| 114 | |
| 115 bool MtpDeviceInterfaceWin::PathExists(const FilePath& file_path) { | |
| 116 NOTIMPLEMENTED(); | |
| 117 return false; | |
| 118 } | |
| 119 | |
| 120 bool MtpDeviceInterfaceWin::DirectoryExists(const FilePath& file_path) { | |
| 121 NOTIMPLEMENTED(); | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 bool MtpDeviceInterfaceWin::IsDirectoryEmpty(const FilePath& file_path) { | |
| 126 NOTIMPLEMENTED(); | |
| 127 return false; | |
| 128 } | |
| 129 | |
| 130 } // namespace fileapi | |
| OLD | NEW |