diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 17:52:29 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 17:52:29 +0000 |
commit | 04c7bf4344c5b69e89c8dceae1ead9b9835fbd06 (patch) | |
tree | 5aff4336bbad088f8b275ebec2aef0245ae97818 /webkit/fileapi/file_system_operation_context.h | |
parent | 3967355e7d0ef9aded77e056accb36cfd6af38c4 (diff) | |
download | chromium_src-04c7bf4344c5b69e89c8dceae1ead9b9835fbd06.zip chromium_src-04c7bf4344c5b69e89c8dceae1ead9b9835fbd06.tar.gz chromium_src-04c7bf4344c5b69e89c8dceae1ead9b9835fbd06.tar.bz2 |
Redesigned and refactored MTPDeviceMapService and MTPDeviceDelegate.
Previously, MTPDeviceDelegate classes were ref-counted. Since the MTPDeviceDelegate was ref-counted, the design was complicated and the ownership of the MTPDeviceDelegateImpl object was not clearly defined.
In this CL,
(1) MTPDeviceDelegate supports weak pointers and is not ref-counted.
(2) MediaFileSystemRegistry manages ScopedMTPDeviceMapEntry object.
(3) ScopedMTPDeviceMapEntry manages the lifetime of MTPDeviceDelegateImpl object via MTPDeviceMapService class.
(4) ScopedMTPDeviceMapEntry adds an entry in MTPDeviceMapService when the MTP device is registered as a media gallery file system by an extension.
(5) ScopedMTPDeviceMapEntry removes an entry from MTPDeviceMapService, when the browser is in shutdown mode or when the last extension using the device delegate is destroyed or when the device is detached from the system or when the user revoke the device gallery permissions.
(7) FileSystemOperationContext stores a weak pointer of MTPDeviceDelegate object.
(8) DeviceMediaFileUtil validates the weak pointer before forwarding any file operation request to the MTPDeviceDelegateImpl.
(9) When an entry is removed from MTPDeviceMapService, the ownership of the |MTPDeviceDelegateImpl| is handed off to the |MTPDeviceDelegateImpl| object which takes care of deleting itself on the right thread.
BUG=144527
TEST=none
Review URL: https://chromiumcodereview.appspot.com/11358243
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_operation_context.h')
-rw-r--r-- | webkit/fileapi/file_system_operation_context.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/webkit/fileapi/file_system_operation_context.h b/webkit/fileapi/file_system_operation_context.h index 067e0d8..9c9c59a 100644 --- a/webkit/fileapi/file_system_operation_context.h +++ b/webkit/fileapi/file_system_operation_context.h @@ -6,6 +6,7 @@ #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ #include "base/memory/ref_counted.h" +#include "base/memory/weak_ptr.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/media/mtp_device_file_system_config.h" #include "webkit/fileapi/task_runner_bound_observer_list.h" @@ -38,12 +39,16 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext { int64 allowed_bytes_growth() const { return allowed_bytes_growth_; } #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) - void set_mtp_device_delegate(MTPDeviceDelegate* delegate) { + // Called on IO thread. + void set_mtp_device_delegate( + const base::WeakPtr<MTPDeviceDelegate>& delegate) { mtp_device_delegate_ = delegate; } - MTPDeviceDelegate* mtp_device_delegate() const { - return mtp_device_delegate_.get(); + // Caller of this function should dereference the delegate only on media + // sequenced task runner thread. + base::WeakPtr<MTPDeviceDelegate> mtp_device_delegate() const { + return mtp_device_delegate_; } #endif @@ -91,8 +96,9 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext { UpdateObserverList update_observers_; #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) - // Store the current mtp device delegate. - scoped_refptr<MTPDeviceDelegate> mtp_device_delegate_; + // The media transfer protocol (MTP) device delegate. + // Set on IO thread and dereferenced on media sequenced task runner thread. + base::WeakPtr<MTPDeviceDelegate> mtp_device_delegate_; #endif }; |