| Index: webkit/fileapi/mtp_device_interface_win.cc
|
| diff --git a/webkit/fileapi/mtp_device_interface_win.cc b/webkit/fileapi/mtp_device_interface_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7fcdb6ecc3201c9240f4f65f992752e1e0efdf8c
|
| --- /dev/null
|
| +++ b/webkit/fileapi/mtp_device_interface_win.cc
|
| @@ -0,0 +1,130 @@
|
| +// 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 "webkit/fileapi/mtp_device_interface_win.h"
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +#define CLIENT_NAME L"WPD Chromium"
|
| +#define CLIENT_MAJOR_VER 1
|
| +#define CLIENT_MINOR_VER 0
|
| +#define CLIENT_REVISION 2
|
| +
|
| +namespace fileapi {
|
| +
|
| +MtpDeviceInterfaceWin::MtpDeviceInterfaceWin(
|
| + const FilePath::StringType& device_id)
|
| + : device_id_(device_id) {
|
| + CoInitialize(NULL);
|
| + bool res = Init();
|
| + DCHECK(res);
|
| +}
|
| +
|
| +MtpDeviceInterfaceWin::~MtpDeviceInterfaceWin() {
|
| + pdevice_.Release();
|
| + CoUninitialize();
|
| +}
|
| +
|
| +bool MtpDeviceInterfaceWin::Init() {
|
| + HRESULT hr = pdevice_.CreateInstance(__uuidof(PortableDevice),
|
| + NULL,
|
| + CLSCTX_INPROC_SERVER);
|
| + if (FAILED(hr))
|
| + return false;
|
| +
|
| + base::win::ScopedComPtr<IPortableDeviceValues> client_info;
|
| + // Fill out information about your application, so the device knows
|
| + // who they are speaking to. Client information is optional. The client
|
| + // can choose to identify itself, or to remain unknown to the driver. It is
|
| + // beneficial to identify yourself because drivers may be able to optimize
|
| + // their behavior for known clients.
|
| +
|
| + // CoCreate an IPortableDeviceValues interface to hold the client
|
| + // information.
|
| + hr = client_info.CreateInstance(__uuidof(PortableDeviceValues),
|
| + NULL,
|
| + CLSCTX_INPROC_SERVER);
|
| + if (FAILED(hr))
|
| + return false;
|
| +
|
| + // Attempt to set all bits of client information
|
| + hr = client_info->SetStringValue(WPD_CLIENT_NAME, CLIENT_NAME);
|
| + if (FAILED(hr))
|
| + LOG(INFO) << "Failed to set WPD_CLIENT_NAME ";
|
| +
|
| + hr = client_info->SetUnsignedIntegerValue(WPD_CLIENT_MAJOR_VERSION,
|
| + CLIENT_MAJOR_VER);
|
| + if (FAILED(hr))
|
| + LOG(INFO) << "Failed to set WPD_CLIENT_MAJOR_VERSION";
|
| +
|
| + hr = client_info->SetUnsignedIntegerValue(WPD_CLIENT_REVISION,
|
| + CLIENT_REVISION);
|
| + if (FAILED(hr))
|
| + LOG(INFO) << "Failed to set WPD_CLIENT_REVISION";
|
| +
|
| + // Some device drivers need to impersonate the caller in order to function
|
| + // correctly. Since our application does not need to restrict its identity,
|
| + // specify SECURITY_IMPERSONATION so that we work with all devices.
|
| + hr = client_info->SetUnsignedIntegerValue(
|
| + WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, SECURITY_IMPERSONATION);
|
| + if (FAILED(hr))
|
| + LOG(INFO) << "Failed to set WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE";
|
| +
|
| + hr = pdevice_->Open(const_cast<wchar_t*>(device_id_.c_str()), client_info);
|
| + if (FAILED(hr)) {
|
| + if (hr == E_ACCESSDENIED) {
|
| + // Failed to Open the device for Read Write access, will open it for
|
| + // Read-only access instead.
|
| + client_info->SetUnsignedIntegerValue(WPD_CLIENT_DESIRED_ACCESS,
|
| + GENERIC_READ);
|
| + hr = pdevice_->Open(const_cast<wchar_t*>(device_id_.c_str()),
|
| + client_info);
|
| + if (FAILED(hr))
|
| + return false;
|
| + } else {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +PlatformFileError MtpDeviceInterfaceWin::GetFileInfo(
|
| + const FilePath& file_path,
|
| + PlatformFileInfo* file_info) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_SECURITY;
|
| +}
|
| +
|
| +FileSystemFileUtil::AbstractFileEnumerator*
|
| + MtpDeviceInterfaceWin::CreateFileEnumerator(
|
| + const FilePath& root,
|
| + bool recursive) {
|
| + NOTIMPLEMENTED();
|
| + return new FileSystemFileUtil::EmptyFileEnumerator();
|
| +}
|
| +
|
| +PlatformFileError MtpDeviceInterfaceWin::Touch(
|
| + const FilePath& file_path,
|
| + const base::Time& last_access_time,
|
| + const base::Time& last_modified_time) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_SECURITY;
|
| +}
|
| +
|
| +bool MtpDeviceInterfaceWin::PathExists(const FilePath& file_path) {
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +bool MtpDeviceInterfaceWin::DirectoryExists(const FilePath& file_path) {
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +bool MtpDeviceInterfaceWin::IsDirectoryEmpty(const FilePath& file_path) {
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +} // namespace fileapi
|
|
|