OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ |
6 #define CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | |
10 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_registrar.h" | |
14 #include "webkit/fileapi/file_system_file_util.h" | 13 #include "webkit/fileapi/file_system_file_util.h" |
15 #include "webkit/fileapi/media/mtp_device_delegate.h" | 14 #include "webkit/fileapi/media/mtp_device_delegate.h" |
16 | 15 |
17 class FilePath; | 16 class FilePath; |
18 | 17 |
19 namespace base { | 18 namespace base { |
20 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
21 } | 20 } |
22 | 21 |
23 namespace chrome { | 22 namespace chrome { |
24 | 23 |
25 // Helper class to communicate with MTP storage to complete isolated file system | 24 // This class communicates with the MTP storage to complete the isolated file |
26 // operations. This class contains platform specific code to communicate with | 25 // system operations. This class contains platform specific code to communicate |
27 // the attached MTP storage. Instantiate this class per MTP storage. | 26 // with the attached MTP storage. Instantiate this class per MTP storage. This |
28 // This class is ref-counted, because MTPDeviceDelegate is ref-counted. | 27 // object is constructed on the UI thread. This object is operated and |
29 class MTPDeviceDelegateImplLinux : public fileapi::MTPDeviceDelegate, | 28 // destructed on the sequenced task runner thread. ScopedMTPDeviceMapEntry class |
30 public content::NotificationObserver { | 29 // manages the lifetime of this object via MTPDeviceMapService class. This class |
30 // supports weak pointers because fileapi::MTPDeviceDelegate supports weak | |
kinuko
2012/11/20 06:25:33
nit: fileapi::MTPDeviceDelegate -> 'the base class
kmadhusu
2012/11/21 04:09:53
Done.
| |
31 // pointers. | |
32 class MTPDeviceDelegateImplLinux : public fileapi::MTPDeviceDelegate { | |
31 public: | 33 public: |
32 // Constructed on UI thread. Defer the device initializations until the first | 34 // Should only be called by ScopedMTPDeviceMapEntry. Use |
33 // file operation request. Do all the initializations in LazyInit() function. | 35 // GetAsWeakPtrOnIOThread() to get a weak pointer instance of this class. |
36 // Defer the device initializations until the first file operation request. | |
37 // Do all the initializations in LazyInit() function. | |
34 explicit MTPDeviceDelegateImplLinux(const std::string& device_location); | 38 explicit MTPDeviceDelegateImplLinux(const std::string& device_location); |
35 | 39 |
36 // Overridden from MTPDeviceDelegate. All the functions are called on | 40 // MTPDeviceDelegate: |
kinuko
2012/11/20 06:25:33
nit: MTPDeviceDelegate overrides ?
kmadhusu
2012/11/21 04:09:53
During MTPDeviceDelegateWin CL review, pkasting@ m
| |
37 // |media_task_runner_|. | |
38 virtual base::PlatformFileError GetFileInfo( | 41 virtual base::PlatformFileError GetFileInfo( |
39 const FilePath& file_path, | 42 const FilePath& file_path, |
40 base::PlatformFileInfo* file_info) OVERRIDE; | 43 base::PlatformFileInfo* file_info) OVERRIDE; |
41 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | 44 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> |
42 CreateFileEnumerator(const FilePath& root, | 45 CreateFileEnumerator(const FilePath& root, |
43 bool recursive) OVERRIDE; | 46 bool recursive) OVERRIDE; |
44 virtual base::PlatformFileError CreateSnapshotFile( | 47 virtual base::PlatformFileError CreateSnapshotFile( |
45 const FilePath& device_file_path, | 48 const FilePath& device_file_path, |
46 const FilePath& local_path, | 49 const FilePath& local_path, |
47 base::PlatformFileInfo* file_info) OVERRIDE; | 50 base::PlatformFileInfo* file_info) OVERRIDE; |
48 virtual base::SequencedTaskRunner* GetMediaTaskRunner() OVERRIDE; | 51 virtual base::SequencedTaskRunner* GetMediaTaskRunner() OVERRIDE; |
49 virtual void DeleteOnCorrectThread() const OVERRIDE; | 52 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; |
53 virtual base::WeakPtr<fileapi::MTPDeviceDelegate> GetAsWeakPtrOnIOThread() | |
54 OVERRIDE; | |
50 | 55 |
51 private: | 56 private: |
52 friend struct fileapi::MTPDeviceDelegateDeleter; | 57 // Destructed via DeleteDelegateOnTaskRunner(). Do all the clean up in |
53 friend class base::DeleteHelper<MTPDeviceDelegateImplLinux>; | 58 // DeleteDelegateOnTaskRunner(). |
54 | |
55 // Private because this class is ref-counted. | |
56 virtual ~MTPDeviceDelegateImplLinux(); | 59 virtual ~MTPDeviceDelegateImplLinux(); |
57 | 60 |
58 // content::NotificationObserver implementation. | |
59 virtual void Observe(int type, | |
60 const content::NotificationSource& source, | |
61 const content::NotificationDetails& details) OVERRIDE; | |
62 | |
63 // Opens the device for communication. This function is called on | 61 // Opens the device for communication. This function is called on |
64 // |media_task_runner_|. Returns true if the device is ready for | 62 // |media_task_runner_|. Returns true if the device is ready for |
65 // communication, else false. | 63 // communication, else false. |
66 bool LazyInit(); | 64 bool LazyInit(); |
67 | 65 |
66 // Deletes the delegate on the task runner thread. This is called when the | |
Lei Zhang
2012/11/21 01:33:30
The part that starts with "This is called" is a re
kmadhusu
2012/11/21 04:09:53
Done.
| |
67 // browser application is in shutdown mode or when the last extension using | |
68 // this MTP device delegate is destroyed or when the MTP device is removed | |
69 // from the system or when an extension revokes the MTP device media gallery | |
70 // permissions. | |
71 void DeleteDelegateOnTaskRunner(); | |
72 | |
68 // Stores the registered file system device path value. This path does not | 73 // Stores the registered file system device path value. This path does not |
69 // correspond to a real device path (E.g.: "/usb:2,2:81282"). | 74 // correspond to a real device path (E.g.: "/usb:2,2:81282"). |
70 const std::string device_path_; | 75 const std::string device_path_; |
71 | 76 |
72 // Stores the device handle returned by | 77 // Stores the device handle returned by |
73 // MediaTransferProtocolManager::OpenStorage(). | 78 // MediaTransferProtocolManager::OpenStorage(). |
74 std::string device_handle_; | 79 std::string device_handle_; |
75 | 80 |
76 // Stores a reference to worker pool thread. All requests and response of file | 81 // Stores a reference to worker pool thread. All requests and response of file |
77 // operations are posted on |media_task_runner_|. | 82 // operations are posted on |media_task_runner_|. |
78 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | 83 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
79 | 84 |
80 // |media_task_runner_| can wait on this event until the requested task is | 85 // |media_task_runner_| can wait on this event until the requested task is |
81 // complete. | 86 // complete. Signaled on a different thread. |
Lei Zhang
2012/11/21 01:33:30
I think the comment is a given. If a thread is wai
kmadhusu
2012/11/21 04:09:53
Removed the comment.
| |
82 base::WaitableEvent on_task_completed_event_; | 87 base::WaitableEvent on_task_completed_event_; |
83 | 88 |
84 // Used to notify |media_task_runner_| pending tasks about the shutdown | 89 // Used to notify |media_task_runner_| pending tasks about the shutdown |
85 // sequence. | 90 // sequence. Signaled on the IO thread. |
86 base::WaitableEvent on_shutdown_event_; | 91 base::WaitableEvent on_shutdown_event_; |
87 | 92 |
88 // Handles registering notifications with the NotificationService. | |
89 // Used to listen for application termination message. | |
90 content::NotificationRegistrar registrar_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); | 93 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); |
93 }; | 94 }; |
94 | 95 |
95 } // namespace chrome | 96 } // namespace chrome |
96 | 97 |
97 #endif // CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ | 98 #endif // CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ |
OLD | NEW |