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

Side by Side Diff: webkit/fileapi/media/mtp_device_delegate.h

Issue 11358243: Redesigned and refactored ScopedMTPDeviceMapEntry, MTPDeviceMapService & MTPDeviceDelegate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 8 years, 1 month 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
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 WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_DELEGATE_H_ 5 #ifndef WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_DELEGATE_H_
6 #define WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_DELEGATE_H_ 6 #define WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_DELEGATE_H_
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/sequenced_task_runner_helpers.h" 12 #include "base/sequenced_task_runner_helpers.h"
13 #include "webkit/fileapi/file_system_file_util.h" 13 #include "webkit/fileapi/file_system_file_util.h"
14 14
15 namespace base { 15 namespace base {
16 struct PlatformFileInfo; 16 struct PlatformFileInfo;
17 class SequencedTaskRunner; 17 class SequencedTaskRunner;
18 class Time; 18 class Time;
19 } 19 }
20 20
21 namespace fileapi { 21 namespace fileapi {
22 22
23 struct MTPDeviceDelegateDeleter; 23 // Delegate for media transfer protocol (MTP) device to perform media device
24
25 // Delegate for media transfer protocol (MTP_ device to perform media device
26 // isolated file system operations. Class that implements this delegate does 24 // isolated file system operations. Class that implements this delegate does
27 // the actual communication with the MTP device. 25 // the actual communication with the MTP device. ScopedMTPDeviceMapEntry class
28 class MTPDeviceDelegate 26 // manages the lifetime of the delegate via MTPDeviceMapService class.
29 : public base::RefCountedThreadSafe<MTPDeviceDelegate, 27 class MTPDeviceDelegate : public base::SupportsWeakPtr<MTPDeviceDelegate> {
30 MTPDeviceDelegateDeleter> {
31 public: 28 public:
32 // Returns information about the given file path. 29 // Returns information about the given file path.
33 virtual base::PlatformFileError GetFileInfo( 30 virtual base::PlatformFileError GetFileInfo(
34 const FilePath& file_path, 31 const FilePath& file_path,
35 base::PlatformFileInfo* file_info) = 0; 32 base::PlatformFileInfo* file_info) = 0;
36 33
37 // Returns a pointer to a new instance of AbstractFileEnumerator to enumerate 34 // Returns a pointer to a new instance of AbstractFileEnumerator to enumerate
38 // the file entries of |root| path. The instance needs to be freed by the 35 // the file entries of |root| path. The instance needs to be freed by the
39 // caller, and its lifetime should not extend past when the current call 36 // caller, and its lifetime should not extend past when the current call
40 // returns to the main media task runner thread. 37 // returns to the main media task runner thread.
41 virtual scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> 38 virtual scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>
42 CreateFileEnumerator(const FilePath& root, 39 CreateFileEnumerator(const FilePath& root,
43 bool recursive) = 0; 40 bool recursive) = 0;
44 41
45 // Updates the temporary snapshot file contents given by |local_path| with 42 // Updates the temporary snapshot file contents given by |local_path| with
46 // media file contents given by |device_file_path| and also returns the 43 // media file contents given by |device_file_path| and also returns the
47 // metadata of the temporary file. 44 // metadata of the temporary file.
48 virtual PlatformFileError CreateSnapshotFile( 45 virtual PlatformFileError CreateSnapshotFile(
49 const FilePath& device_file_path, 46 const FilePath& device_file_path,
50 const FilePath& local_path, 47 const FilePath& local_path,
51 base::PlatformFileInfo* file_info) = 0; 48 base::PlatformFileInfo* file_info) = 0;
52 49
53 // Returns TaskRunner on which the operation is performed. 50 // Returns TaskRunner on which the operation is performed.
54 virtual base::SequencedTaskRunner* GetMediaTaskRunner() = 0; 51 virtual base::SequencedTaskRunner* GetMediaTaskRunner() = 0;
55 52
56 // Helper function to destruct the delegate object on UI thread. 53 // Called when the
57 virtual void DeleteOnCorrectThread() const = 0; 54 // (1) Browser application is in shutdown mode (or)
55 // (2) Last extension using this MTP device is destroyed (or)
56 // (3) Attached MTP device is removed (or)
57 // (4) User revoked the MTP device gallery permission.
58 // Ownership of |MTPDeviceDelegate| is handed off to the delegate
59 // implementation class by this call. This function should take care of
60 // deleting itself on the right thread. This function should cancel all the
61 // pending requests before posting any message to delete itself. Called on the
Lei Zhang 2012/11/21 01:33:30 Can you put the "Called..." part on the next line?
kmadhusu 2012/11/21 04:09:53 Done.
62 // IO thread.
63 virtual void CancelPendingTasksAndDeleteDelegate() = 0;
64
65 // Called by FileSystemOperationContext to get MTPDeviceDelegate as a WeakPtr.
Lei Zhang 2012/11/21 01:33:30 Again, you don't get to dictate who calls you.
kmadhusu 2012/11/21 04:09:53 Removed the comment.
66 // Called on the IO thread.
67 virtual base::WeakPtr<MTPDeviceDelegate> GetAsWeakPtrOnIOThread() = 0;
58 68
59 protected: 69 protected:
70 // Always destruct this object via CancelPendingTasksAndDeleteDelegate().
60 virtual ~MTPDeviceDelegate() {} 71 virtual ~MTPDeviceDelegate() {}
61
62 private:
63 friend struct MTPDeviceDelegateDeleter;
64 friend class base::DeleteHelper<MTPDeviceDelegate>;
65 friend class base::RefCountedThreadSafe<MTPDeviceDelegate,
66 MTPDeviceDelegateDeleter>;
67 };
68
69 struct MTPDeviceDelegateDeleter {
70 static void Destruct(const MTPDeviceDelegate* delegate) {
71 delegate->DeleteOnCorrectThread();
72 }
73 }; 72 };
74 73
75 } // namespace fileapi 74 } // namespace fileapi
76 75
77 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_DELEGATE_H_ 76 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698