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

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: Modified LazyInit() to handle GetDeviceStorageInfo failure Created 7 years, 11 months 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.
Ryan Sleevi 2013/01/05 03:00:58 STYLE: You should be describing these comments as
kmadhusu 2013/01/08 03:19:40 rsleevi@: Moved some class detail comments from th
Ryan Sleevi 2013/01/09 00:20:36 My main concern was comments like "This class" rea
kmadhusu 2013/01/09 18:11:14 As we discussed, moved these class details to the
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/synchronization/waitable_event.h"
22 #include "base/win/scoped_comptr.h"
23 #include "chrome/browser/media_gallery/mtp_device_delegate_impl.h"
24 #include "webkit/fileapi/file_system_file_util.h"
25 #include "webkit/fileapi/media/mtp_device_delegate.h"
26
27 class FilePath;
28
29 namespace base {
30 class SequencedTaskRunner;
31 }
32
33 namespace chrome {
34
35 // This class communicates with the MTP device to complete isolated file system
36 // operations. This class contains platform specific code to communicate with
37 // the attached MTP device. Instantiate this class per MTP device storage
38 // partition using CreateMTPDeviceDelegate(). This object lives on a sequenced
39 // task runner thread, except for CancelPendingTasksAndDeleteDelegate() which
40 // happens on the UI thread.
41 class MTPDeviceDelegateImplWin : public fileapi::MTPDeviceDelegate {
42 public:
43 // Returns true to cancel the pending tasks if |this| object is scheduled to
44 // be deleted.
45 bool IsCancelTasksFlagSet();
46
47 private:
48 friend void CreateMTPDeviceDelegate(const string16&,
49 base::SequencedTaskRunner*,
50 const CreateMTPDeviceDelegateCallback&);
51 friend class base::DeleteHelper<MTPDeviceDelegateImplWin>;
52
53 // Defer the device initializations until the first file operation request.
54 // Do all the initializations in LazyInit() function.
55 MTPDeviceDelegateImplWin(const string16& pnp_device_id,
56 base::SequencedTaskRunner* media_task_runner);
57
58 // Destructed via CancelPendingTasksAndDeleteDelegate().
59 virtual ~MTPDeviceDelegateImplWin();
60
61 // MTPDeviceDelegate:
62 virtual base::PlatformFileError GetFileInfo(
63 const FilePath& file_path,
64 base::PlatformFileInfo* file_info) OVERRIDE;
65 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator>
66 CreateFileEnumerator(const FilePath& root,
67 bool recursive) OVERRIDE;
68 virtual base::PlatformFileError CreateSnapshotFile(
69 const FilePath& device_file_path,
70 const FilePath& local_path,
71 base::PlatformFileInfo* file_info) OVERRIDE;
72 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE;
73
74 // Returns whether the device is ready for communication.
75 bool LazyInit();
76
77 // Returns the object id of the file object specified by the |file_path|,
78 // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM"
79 // and |registered_device_path_| is "\\MTP:StorageSerial:SID-{1001,,192}:125",
80 // this function returns the identifier of the "DCIM" folder object.
81 //
82 // Returns an empty string if the device is detached while the request is in
83 // progress.
84 string16 GetFileObjectIdFromPath(const string16& file_path);
85
86 // The Pnp Device Id, used to open the device for communication,
87 // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}".
88 string16 pnp_device_id_;
89
90 // The media file system root path, which is obtained during the registration
91 // of MTP device storage partition as a file system,
92 // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483".
93 const string16 registered_device_path_;
94
95 // The MTP device storage partition object identifier, used to enumerate the
96 // storage contents, e.g. "s10001".
97 string16 storage_object_id_;
98
99 // The task runner where most of the class lives and runs (save for
100 // CancelPendingTasksAndDeleteDelegate).
101 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
102
103 // The portable device.
104 base::win::ScopedComPtr<IPortableDevice> device_;
105
106 // The lock to protect |cancel_pending_tasks_|. |cancel_pending_tasks_| is
107 // set on the UI thread when the
108 // (1) Browser application is in shutdown mode (or)
109 // (2) Last extension using this MTP device is destroyed (or)
110 // (3) Attached MTP device is removed (or)
111 // (4) User revoked the MTP device gallery permission.
112 base::Lock cancel_tasks_lock_;
113 bool cancel_pending_tasks_;
114
115 // The task runner can wait on this event until the device storage details
116 // are fetched.
117 base::WaitableEvent task_completed_event_;
118
119 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin);
120 };
121
122 } // namespace chrome
123
124 #endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698