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/media_device_map_service.h" |
| 23 #include "webkit/fileapi/media_file_util.h" |
22 #include "webkit/fileapi/local_file_stream_writer.h" | 24 #include "webkit/fileapi/local_file_stream_writer.h" |
23 #include "webkit/fileapi/local_file_system_operation.h" | 25 #include "webkit/fileapi/local_file_system_operation.h" |
24 #include "webkit/fileapi/native_file_util.h" | 26 #include "webkit/fileapi/native_file_util.h" |
25 | 27 |
26 namespace fileapi { | 28 namespace fileapi { |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 IsolatedContext* isolated_context() { | 32 IsolatedContext* isolated_context() { |
31 return IsolatedContext::GetInstance(); | 33 return IsolatedContext::GetInstance(); |
32 } | 34 } |
33 | 35 |
34 FilePath GetPathFromURL(const FileSystemURL& url) { | 36 FilePath GetPathFromURL(const FileSystemURL& url) { |
35 if (!url.is_valid() || url.type() != kFileSystemTypeIsolated) | 37 if (!url.is_valid() || url.type() != kFileSystemTypeIsolated) |
36 return FilePath(); | 38 return FilePath(); |
37 std::string fsid; | 39 std::string fsid; |
38 FilePath path; | 40 FilePath path; |
39 if (!isolated_context()->CrackIsolatedPath(url.path(), &fsid, NULL, &path)) | 41 if (!isolated_context()->CrackIsolatedPath(url.path(), &fsid, NULL, &path)) |
40 return FilePath(); | 42 return FilePath(); |
41 return path; | 43 return path; |
42 } | 44 } |
43 | 45 |
44 } // namespace | 46 } // namespace |
45 | 47 |
46 IsolatedMountPointProvider::IsolatedMountPointProvider() | 48 IsolatedMountPointProvider::IsolatedMountPointProvider() |
47 : isolated_file_util_(new IsolatedFileUtil()) { | 49 : isolated_file_util_(new IsolatedFileUtil()), |
| 50 media_file_util_(new MediaFileUtil()) { |
48 } | 51 } |
49 | 52 |
50 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 53 IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
51 } | 54 } |
52 | 55 |
53 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 56 void IsolatedMountPointProvider::ValidateFileSystemRoot( |
54 const GURL& origin_url, | 57 const GURL& origin_url, |
55 FileSystemType type, | 58 FileSystemType type, |
56 bool create, | 59 bool create, |
57 const ValidateFileSystemCallback& callback) { | 60 const ValidateFileSystemCallback& callback) { |
(...skipping 28 matching lines...) Expand all Loading... |
86 return isolated_context()->CrackIsolatedPath( | 89 return isolated_context()->CrackIsolatedPath( |
87 virtual_path, &filesystem_id, NULL, &path); | 90 virtual_path, &filesystem_id, NULL, &path); |
88 } | 91 } |
89 | 92 |
90 bool IsolatedMountPointProvider::IsRestrictedFileName( | 93 bool IsolatedMountPointProvider::IsRestrictedFileName( |
91 const FilePath& filename) const { | 94 const FilePath& filename) const { |
92 return false; | 95 return false; |
93 } | 96 } |
94 | 97 |
95 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil() { | 98 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil() { |
| 99 if (true /* FIX THIS */) |
| 100 return media_file_util_.get(); |
96 return isolated_file_util_.get(); | 101 return isolated_file_util_.get(); |
97 } | 102 } |
98 | 103 |
99 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( | 104 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
100 const FilePath& virtual_path) const { | 105 const FilePath& virtual_path) const { |
101 std::string fsid; | 106 std::string fsid; |
102 FilePath path; | 107 FilePath path; |
103 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path)) | 108 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path)) |
104 return FilePath(); | 109 return FilePath(); |
105 return path; | 110 return path; |
106 } | 111 } |
107 | 112 |
108 FileSystemOperationInterface* | 113 FileSystemOperationInterface* |
109 IsolatedMountPointProvider::CreateFileSystemOperation( | 114 IsolatedMountPointProvider::CreateFileSystemOperation( |
110 const FileSystemURL& url, | 115 const FileSystemURL& url, |
111 FileSystemContext* context) const { | 116 FileSystemContext* context) const { |
| 117 if (url.type() /* == kFileSystemMedia*/) { |
| 118 std::string fsid; |
| 119 FilePath path; |
| 120 IsolatedContext::FileInfo root; |
| 121 if (!isolated_context()->CrackIsolatedPath(url.path(), &fsid, &root, &path)) |
| 122 return NULL; |
| 123 FilePath::StringType device_name(root.path.value()); |
| 124 MediaDeviceMapService::GetInstance()->AddMediaDevice(device_name); |
| 125 } |
112 return new LocalFileSystemOperation(context); | 126 return new LocalFileSystemOperation(context); |
113 } | 127 } |
114 | 128 |
115 webkit_blob::FileStreamReader* | 129 webkit_blob::FileStreamReader* |
116 IsolatedMountPointProvider::CreateFileStreamReader( | 130 IsolatedMountPointProvider::CreateFileStreamReader( |
117 const FileSystemURL& url, | 131 const FileSystemURL& url, |
118 int64 offset, | 132 int64 offset, |
119 FileSystemContext* context) const { | 133 FileSystemContext* context) const { |
120 FilePath path = GetPathFromURL(url); | 134 FilePath path = GetPathFromURL(url); |
121 return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader( | 135 return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader( |
122 context->file_task_runner(), path, offset, base::Time()); | 136 context->file_task_runner(), path, offset, base::Time()); |
123 } | 137 } |
124 | 138 |
125 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( | 139 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
126 const FileSystemURL& url, | 140 const FileSystemURL& url, |
127 int64 offset, | 141 int64 offset, |
128 FileSystemContext* context) const { | 142 FileSystemContext* context) const { |
129 FilePath path = GetPathFromURL(url); | 143 FilePath path = GetPathFromURL(url); |
130 return path.empty() ? NULL : new LocalFileStreamWriter(path, offset); | 144 return path.empty() ? NULL : new LocalFileStreamWriter(path, offset); |
131 } | 145 } |
132 | 146 |
133 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 147 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
134 // No quota support. | 148 // No quota support. |
135 return NULL; | 149 return NULL; |
136 } | 150 } |
137 | 151 |
138 } // namespace fileapi | 152 } // namespace fileapi |
OLD | NEW |