Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h

Issue 11297002: [Media Gallery] Added code to support mtp device media file system on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed DCHECK, added lock in PortableDeviceWatcherWin and fixed tests. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // This class supports media transfer protocol (MTP) device file system
6 // operations. This class communicates with the portable device and completes
7 // the requested file system operation. A portable device can have multiple
8 // data partitions. A user can register each partition as a media file system.
9 // This class is instantiated per MTP device partition.
10
11 #ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_
12 #define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_
13
14 #include <portabledeviceapi.h>
15 #include <string>
16
17 #include "base/platform_file.h"
18 #include "base/sequenced_task_runner_helpers.h"
19 #include "base/string16.h"
20 #include "base/synchronization/lock.h"
21 #include "base/win/scoped_comptr.h"
22 #include "chrome/browser/media_gallery/mtp_device_delegate_impl.h"
23 #include "webkit/fileapi/file_system_file_util.h"
24 #include "webkit/fileapi/media/mtp_device_delegate.h"
25
26 class FilePath;
27
28 namespace base {
29 class SequencedTaskRunner;
30 }
31
32 namespace chrome {
33
34 // This class communicates with the MTP device to complete isolated file system
35 // operations. This class contains platform specific code to communicate with
36 // the attached MTP device. Instantiate this class per MTP device storage
37 // partition using CreateMTPDeviceDelegate(). This object lives on a sequenced
38 // task runner thread, except for CancelPendingTasksAndDeleteDelegate() which
39 // happens on the UI thread.
40 class MTPDeviceDelegateImplWin : public fileapi::MTPDeviceDelegate {
41 private:
42 friend void CreateMTPDeviceDelegate(const string16&,
43 base::SequencedTaskRunner*,
44 const CreateMTPDeviceDelegateCallback&);
45 friend class base::DeleteHelper<MTPDeviceDelegateImplWin>;
46
47 // Defer the device initializations until the first file operation request.
48 // Do all the initializations in LazyInit() function.
49 MTPDeviceDelegateImplWin(const string16& pnp_device_id,
50 base::SequencedTaskRunner* media_task_runner);
51
52 // Destructed via CancelPendingTasksAndDeleteDelegate().
53 virtual ~MTPDeviceDelegateImplWin();
54
55 // MTPDeviceDelegate:
56 virtual base::PlatformFileError GetFileInfo(
57 const FilePath& file_path,
58 base::PlatformFileInfo* file_info) OVERRIDE;
59 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator>
60 CreateFileEnumerator(const FilePath& root,
61 bool recursive) OVERRIDE;
62 virtual base::PlatformFileError CreateSnapshotFile(
63 const FilePath& device_file_path,
64 const FilePath& local_path,
65 base::PlatformFileInfo* file_info) OVERRIDE;
66 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE;
67
68 // Returns whether the device is ready for communication.
69 bool LazyInit();
70
71 // Returns the object id of the file object specified by the |file_path|,
72 // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM"
73 // and |registered_device_path_| is "\\MTP:StorageSerial:SID-{1001,,192}:125",
74 // this function returns the identifier of the "DCIM" folder object.
75 //
76 // Returns an empty string if the device is detached while the request is in
77 // progress.
78 string16 GetFileObjectIdFromPath(const string16& file_path);
79
80 // The Pnp Device Id, used to open the device for communication,
81 // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}".
82 string16 pnp_device_id_;
83
84 // The media file system root path, which is obtained during the registration
85 // of MTP device storage partition as a file system,
86 // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483".
87 const string16 registered_device_path_;
88
89 // The MTP device storage partition object identifier, used to enumerate the
90 // storage contents, e.g. "s10001".
91 string16 storage_object_id_;
92
93 // The task runner where most of the class lives and runs (save for
94 // CancelPendingTasksAndDeleteDelegate).
95 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
96
97 // The portable device.
98 base::win::ScopedComPtr<IPortableDevice> device_;
99
100 // The lock to protect |cancel_pending_tasks_|. |cancel_pending_tasks_| is
101 // set on the UI thread when the
102 // (1) Browser application is in shutdown mode (or)
103 // (2) Last extension using this MTP device is destroyed (or)
104 // (3) Attached MTP device is removed (or)
105 // (4) User revoked the MTP device gallery permission.
106 base::Lock cancel_tasks_lock_;
107 bool cancel_pending_tasks_;
108
109 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin);
110 };
111
112 } // namespace chrome
113
114 #endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698