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_operation.h" | 18 #include "webkit/fileapi/file_system_operation.h" |
19 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
20 #include "webkit/fileapi/file_system_util.h" | 20 #include "webkit/fileapi/file_system_util.h" |
21 #include "webkit/fileapi/isolated_context.h" | 21 #include "webkit/fileapi/isolated_context.h" |
22 #include "webkit/fileapi/isolated_file_util.h" | 22 #include "webkit/fileapi/isolated_file_util.h" |
23 #include "webkit/fileapi/media_device_map_service.h" | |
24 #include "webkit/fileapi/media_file_util.h" | |
23 #include "webkit/fileapi/local_file_stream_writer.h" | 25 #include "webkit/fileapi/local_file_stream_writer.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 |
46 bool IsMediaFileSystemURL(const FileSystemURL& url) { | |
47 // TODO(kmadhusu): Query the SystemMonitor for the URL device type. | |
48 #if defined(OS_WIN) | |
49 FilePath temp = GetPathFromURL(url); | |
50 if (temp.empty()) | |
51 return false; | |
52 FilePath::StringType device_name(temp.value()); | |
53 return (!(device_name.substr(0,4)).compare(L"\\\\?\\")); | |
54 #else | |
55 return true; | |
56 #endif | |
kinuko
2012/07/24 19:57:19
We are thinking about a refactoring like following
kmadhusu
2012/07/24 20:56:34
sgtm. Your changes will simplify this CL. I will s
| |
57 } | |
58 | |
44 } // namespace | 59 } // namespace |
45 | 60 |
46 IsolatedMountPointProvider::IsolatedMountPointProvider() | 61 IsolatedMountPointProvider::IsolatedMountPointProvider() |
47 : isolated_file_util_(new IsolatedFileUtil()) { | 62 : isolated_file_util_(new IsolatedFileUtil()), |
63 media_file_util_(new MediaFileUtil()) { | |
48 } | 64 } |
49 | 65 |
50 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 66 IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
51 } | 67 } |
52 | 68 |
53 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 69 void IsolatedMountPointProvider::ValidateFileSystemRoot( |
54 const GURL& origin_url, | 70 const GURL& origin_url, |
55 FileSystemType type, | 71 FileSystemType type, |
56 bool create, | 72 bool create, |
57 const ValidateFileSystemCallback& callback) { | 73 const ValidateFileSystemCallback& callback) { |
(...skipping 27 matching lines...) Expand all Loading... | |
85 FilePath path; | 101 FilePath path; |
86 return isolated_context()->CrackIsolatedPath( | 102 return isolated_context()->CrackIsolatedPath( |
87 virtual_path, &filesystem_id, NULL, &path); | 103 virtual_path, &filesystem_id, NULL, &path); |
88 } | 104 } |
89 | 105 |
90 bool IsolatedMountPointProvider::IsRestrictedFileName( | 106 bool IsolatedMountPointProvider::IsRestrictedFileName( |
91 const FilePath& filename) const { | 107 const FilePath& filename) const { |
92 return false; | 108 return false; |
93 } | 109 } |
94 | 110 |
95 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil() { | 111 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
112 const FileSystemURL& url) { | |
113 if (IsMediaFileSystemURL(url)) | |
114 return media_file_util_.get(); | |
96 return isolated_file_util_.get(); | 115 return isolated_file_util_.get(); |
97 } | 116 } |
98 | 117 |
99 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( | 118 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
100 const FilePath& virtual_path) const { | 119 const FilePath& virtual_path) const { |
101 std::string fsid; | 120 std::string fsid; |
102 FilePath path; | 121 FilePath path; |
103 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path)) | 122 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path)) |
104 return FilePath(); | 123 return FilePath(); |
105 return path; | 124 return path; |
106 } | 125 } |
107 | 126 |
108 FileSystemOperationInterface* | 127 FileSystemOperationInterface* |
109 IsolatedMountPointProvider::CreateFileSystemOperation( | 128 IsolatedMountPointProvider::CreateFileSystemOperation( |
110 const FileSystemURL& url, | 129 const FileSystemURL& url, |
111 FileSystemContext* context) const { | 130 FileSystemContext* context) const { |
131 if (IsMediaFileSystemURL(url)) { | |
132 FilePath actual_path = GetPathFromURL(url); | |
133 if (actual_path.empty()) | |
134 return false; | |
135 FilePath::StringType device_name(actual_path.value()); | |
136 MediaDeviceMapService::GetInstance()->AddMediaDevice(device_name); | |
137 } | |
112 return new FileSystemOperation(context); | 138 return new FileSystemOperation(context); |
113 } | 139 } |
114 | 140 |
115 webkit_blob::FileStreamReader* | 141 webkit_blob::FileStreamReader* |
116 IsolatedMountPointProvider::CreateFileStreamReader( | 142 IsolatedMountPointProvider::CreateFileStreamReader( |
117 const FileSystemURL& url, | 143 const FileSystemURL& url, |
118 int64 offset, | 144 int64 offset, |
119 FileSystemContext* context) const { | 145 FileSystemContext* context) const { |
120 FilePath path = GetPathFromURL(url); | 146 FilePath path = GetPathFromURL(url); |
121 return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader( | 147 return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader( |
122 context->file_task_runner(), path, offset, base::Time()); | 148 context->file_task_runner(), path, offset, base::Time()); |
123 } | 149 } |
124 | 150 |
125 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( | 151 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
126 const FileSystemURL& url, | 152 const FileSystemURL& url, |
127 int64 offset, | 153 int64 offset, |
128 FileSystemContext* context) const { | 154 FileSystemContext* context) const { |
129 FilePath path = GetPathFromURL(url); | 155 FilePath path = GetPathFromURL(url); |
130 return path.empty() ? NULL : new LocalFileStreamWriter(path, offset); | 156 return path.empty() ? NULL : new LocalFileStreamWriter(path, offset); |
131 } | 157 } |
132 | 158 |
133 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 159 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
134 // No quota support. | 160 // No quota support. |
135 return NULL; | 161 return NULL; |
136 } | 162 } |
137 | 163 |
138 } // namespace fileapi | 164 } // namespace fileapi |
OLD | NEW |