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 #include "webkit/fileapi/isolated_mount_point_provider.h" | 5 #include "webkit/fileapi/isolated_mount_point_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "webkit/blob/local_file_stream_reader.h" | 14 #include "webkit/blob/local_file_stream_reader.h" |
15 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 15 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
16 #include "webkit/fileapi/file_system_context.h" | 16 #include "webkit/fileapi/file_system_context.h" |
17 #include "webkit/fileapi/file_system_file_stream_reader.h" | 17 #include "webkit/fileapi/file_system_file_stream_reader.h" |
18 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
19 #include "webkit/fileapi/file_system_util.h" | 19 #include "webkit/fileapi/file_system_util.h" |
20 #include "webkit/fileapi/isolated_context.h" | 20 #include "webkit/fileapi/isolated_context.h" |
21 #include "webkit/fileapi/isolated_file_util.h" | 21 #include "webkit/fileapi/isolated_file_util.h" |
22 #include "webkit/fileapi/local_file_stream_writer.h" | 22 #include "webkit/fileapi/local_file_stream_writer.h" |
23 #include "webkit/fileapi/local_file_system_operation.h" | 23 #include "webkit/fileapi/local_file_system_operation.h" |
24 #include "webkit/fileapi/media/media_file_system_config.h" | |
24 #include "webkit/fileapi/native_file_util.h" | 25 #include "webkit/fileapi/native_file_util.h" |
25 | 26 |
27 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
28 #include "webkit/fileapi/media/device_media_file_util.h" | |
29 #include "webkit/fileapi/media/media_device_map_service.h" | |
30 #endif | |
31 | |
26 namespace fileapi { | 32 namespace fileapi { |
27 | 33 |
28 namespace { | 34 namespace { |
29 | 35 |
30 IsolatedContext* isolated_context() { | 36 IsolatedContext* isolated_context() { |
31 return IsolatedContext::GetInstance(); | 37 return IsolatedContext::GetInstance(); |
32 } | 38 } |
33 | 39 |
40 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
41 MediaDeviceInterfaceImpl* GetDeviceForUrl(const FileSystemURL& url, | |
42 FileSystemContext* context) { | |
43 FilePath root_path; | |
44 if (!isolated_context()->GetRegisteredPath(url.filesystem_id(), &root_path)) | |
45 return NULL; | |
46 | |
47 // Add the media device if required. | |
48 MediaDeviceMapService::GetInstance()->MaybeAddMediaDevice( | |
49 root_path.value(), context->file_task_runner()); | |
50 | |
51 return MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
52 root_path.value()); | |
kinuko
2012/08/01 04:24:27
Actually if we always call these two (Add and Get)
kmadhusu
2012/08/01 23:39:35
As we discussed, I have unified them. New function
| |
53 } | |
54 #endif | |
55 | |
34 } // namespace | 56 } // namespace |
35 | 57 |
36 IsolatedMountPointProvider::IsolatedMountPointProvider() | 58 IsolatedMountPointProvider::IsolatedMountPointProvider( |
37 : isolated_file_util_(new IsolatedFileUtil()), | 59 const FilePath& profile_path) |
60 : profile_path_(profile_path), | |
61 isolated_file_util_(new IsolatedFileUtil()), | |
38 dragged_file_util_(new DraggedFileUtil()) { | 62 dragged_file_util_(new DraggedFileUtil()) { |
63 // TODO(kmadhusu): Initialize device_media_file_util_ in initialization list. | |
64 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
65 device_media_file_util_.reset(new DeviceMediaFileUtil(profile_path_)); | |
66 #endif | |
39 } | 67 } |
40 | 68 |
41 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 69 IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
42 } | 70 } |
43 | 71 |
44 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 72 void IsolatedMountPointProvider::ValidateFileSystemRoot( |
45 const GURL& origin_url, | 73 const GURL& origin_url, |
46 FileSystemType type, | 74 FileSystemType type, |
47 bool create, | 75 bool create, |
48 const ValidateFileSystemCallback& callback) { | 76 const ValidateFileSystemCallback& callback) { |
(...skipping 22 matching lines...) Expand all Loading... | |
71 const FilePath& filename) const { | 99 const FilePath& filename) const { |
72 // TODO(kinuko): We need to check platform-specific restricted file names | 100 // TODO(kinuko): We need to check platform-specific restricted file names |
73 // before we actually start allowing file creation in isolated file systems. | 101 // before we actually start allowing file creation in isolated file systems. |
74 return false; | 102 return false; |
75 } | 103 } |
76 | 104 |
77 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( | 105 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
78 FileSystemType type) { | 106 FileSystemType type) { |
79 if (type == kFileSystemTypeDragged) | 107 if (type == kFileSystemTypeDragged) |
80 return dragged_file_util_.get(); | 108 return dragged_file_util_.get(); |
109 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
110 else if (type == kFileSystemTypeDeviceMedia) | |
111 return device_media_file_util_.get(); | |
112 #endif | |
81 else | 113 else |
82 return isolated_file_util_.get(); | 114 return isolated_file_util_.get(); |
83 } | 115 } |
84 | 116 |
85 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( | 117 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
86 const FilePath& virtual_path) const { | 118 const FilePath& virtual_path) const { |
87 // For isolated filesystems we only check per-filesystem permissions. | 119 // For isolated filesystems we only check per-filesystem permissions. |
88 NOTREACHED(); | 120 NOTREACHED(); |
89 return virtual_path; | 121 return virtual_path; |
90 } | 122 } |
91 | 123 |
92 FileSystemOperationInterface* | 124 FileSystemOperationInterface* |
93 IsolatedMountPointProvider::CreateFileSystemOperation( | 125 IsolatedMountPointProvider::CreateFileSystemOperation( |
94 const FileSystemURL& url, | 126 const FileSystemURL& url, |
95 FileSystemContext* context) const { | 127 FileSystemContext* context) const { |
96 scoped_ptr<FileSystemOperationContext> operation_context( | 128 scoped_ptr<FileSystemOperationContext> operation_context( |
97 new FileSystemOperationContext(context)); | 129 new FileSystemOperationContext(context)); |
130 | |
131 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
132 if (url.type() == kFileSystemTypeDeviceMedia) { | |
133 scoped_refptr<MediaDeviceInterfaceImpl> device(GetDeviceForUrl(url, | |
134 context)); | |
135 if (!device.get()) | |
136 return NULL; | |
kinuko
2012/08/01 04:24:27
It looks returning NULL from this method isn't saf
kmadhusu
2012/08/01 23:39:35
Done.
| |
137 operation_context->set_media_device(device); | |
138 } | |
139 #endif | |
140 | |
98 return new LocalFileSystemOperation(context, operation_context.Pass()); | 141 return new LocalFileSystemOperation(context, operation_context.Pass()); |
99 } | 142 } |
100 | 143 |
101 webkit_blob::FileStreamReader* | 144 webkit_blob::FileStreamReader* |
102 IsolatedMountPointProvider::CreateFileStreamReader( | 145 IsolatedMountPointProvider::CreateFileStreamReader( |
103 const FileSystemURL& url, | 146 const FileSystemURL& url, |
104 int64 offset, | 147 int64 offset, |
105 FileSystemContext* context) const { | 148 FileSystemContext* context) const { |
106 return new webkit_blob::LocalFileStreamReader( | 149 return new webkit_blob::LocalFileStreamReader( |
107 context->file_task_runner(), url.path(), offset, base::Time()); | 150 context->file_task_runner(), url.path(), offset, base::Time()); |
108 } | 151 } |
109 | 152 |
110 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( | 153 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
111 const FileSystemURL& url, | 154 const FileSystemURL& url, |
112 int64 offset, | 155 int64 offset, |
113 FileSystemContext* context) const { | 156 FileSystemContext* context) const { |
114 return new LocalFileStreamWriter(url.path(), offset); | 157 return new LocalFileStreamWriter(url.path(), offset); |
115 } | 158 } |
116 | 159 |
117 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 160 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
118 // No quota support. | 161 // No quota support. |
119 return NULL; | 162 return NULL; |
120 } | 163 } |
121 | 164 |
122 } // namespace fileapi | 165 } // namespace fileapi |
OLD | NEW |