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

Side by Side Diff: webkit/fileapi/media/device_media_file_util.cc

Issue 10781014: Isolated FS for media devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix shared_build compile error. Created 8 years, 4 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/fileapi/media/device_media_file_util.h"
6
7 #include "base/message_loop_proxy.h"
8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "webkit/blob/shareable_file_reference.h"
11 #include "webkit/fileapi/file_system_operation_context.h"
12 #include "webkit/fileapi/file_system_url.h"
13 #include "webkit/fileapi/isolated_context.h"
14 #include "webkit/fileapi/media/media_device_map_service.h"
15 #include "webkit/fileapi/media/media_device_interface_impl.h"
16
17 using base::PlatformFileError;
18 using base::PlatformFileInfo;
19 using webkit_blob::ShareableFileReference;
20
21 namespace fileapi {
22
23 namespace {
24
25 const FilePath::CharType kIsolatedMediaFileSystemDir[] =
26 FILE_PATH_LITERAL("IsolatedMediaFileSystem");
kinuko 2012/07/30 23:19:03 DeviceMediaFileSystem might reflect where the path
kmadhusu 2012/07/31 01:17:48 Done.
27
28 } // namespace
29
30 DeviceMediaFileUtil::DeviceMediaFileUtil(const FilePath& profile_path)
31 : profile_path_(profile_path) {
32 }
33
34 PlatformFileError DeviceMediaFileUtil::CreateOrOpen(
35 FileSystemOperationContext* context,
36 const FileSystemURL& url, int file_flags,
37 PlatformFile* file_handle, bool* created) {
38 return base::PLATFORM_FILE_ERROR_SECURITY;
39 }
40
41 PlatformFileError DeviceMediaFileUtil::Close(
42 FileSystemOperationContext* context,
43 PlatformFile file_handle) {
44 // We don't allow open thus Close won't be called.
45 return base::PLATFORM_FILE_ERROR_SECURITY;
46 }
47
48 PlatformFileError DeviceMediaFileUtil::EnsureFileExists(
49 FileSystemOperationContext* context,
50 const FileSystemURL& url,
51 bool* created) {
52 return base::PLATFORM_FILE_ERROR_SECURITY;
53 }
54
55 PlatformFileError DeviceMediaFileUtil::CreateDirectory(
56 FileSystemOperationContext* context,
57 const FileSystemURL& url,
58 bool exclusive,
59 bool recursive) {
60 return base::PLATFORM_FILE_ERROR_SECURITY;
61 }
62
63 PlatformFileError DeviceMediaFileUtil::GetFileInfo(
64 FileSystemOperationContext* context,
65 const FileSystemURL& url,
66 PlatformFileInfo* file_info,
67 FilePath* platform_path) {
68 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device());
69 if (!device.get())
70 return base::PLATFORM_FILE_ERROR_INVALID_URL;
71 *platform_path = url.path();
kinuko 2012/07/30 23:19:03 Returning this url.path() won't be usable outside
kmadhusu 2012/07/31 01:17:48 Done.
72 return device->GetFileInfo(*platform_path, file_info);
kinuko 2012/07/30 23:19:03 nit: *platform_path -> url.path() (though they ha
kmadhusu 2012/07/31 01:17:48 Done.
73 }
74
75 FileSystemFileUtil::AbstractFileEnumerator*
76 DeviceMediaFileUtil::CreateFileEnumerator(
77 FileSystemOperationContext* context,
78 const FileSystemURL& url,
79 bool recursive) {
80 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device());
81 if (!device.get())
82 return new FileSystemFileUtil::EmptyFileEnumerator();
83 return device->CreateFileEnumerator(url.path(), recursive);
84 }
85
86 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath(
87 FileSystemOperationContext* context,
88 const FileSystemURL& file_system_url,
89 FilePath* local_file_path) {
90 return base::PLATFORM_FILE_ERROR_SECURITY;
91 }
92
93 PlatformFileError DeviceMediaFileUtil::Touch(
94 FileSystemOperationContext* context,
95 const FileSystemURL& url,
96 const base::Time& last_access_time,
97 const base::Time& last_modified_time) {
98 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device());
99 if (!device.get())
100 return base::PLATFORM_FILE_ERROR_INVALID_URL;
101 return device->Touch(url.path(), last_access_time, last_modified_time);
102 }
103
104 PlatformFileError DeviceMediaFileUtil::Truncate(
105 FileSystemOperationContext* context,
106 const FileSystemURL& url,
107 int64 length) {
108 return base::PLATFORM_FILE_ERROR_SECURITY;
109 }
110
111 bool DeviceMediaFileUtil::PathExists(
112 FileSystemOperationContext* context,
113 const FileSystemURL& url) {
114 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device());
115 if (!device.get())
116 return false;
117 return device->PathExists(url.path());
118 }
119
120 bool DeviceMediaFileUtil::DirectoryExists(
121 FileSystemOperationContext* context,
122 const FileSystemURL& url) {
123 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device());
124 if (!device.get())
125 return false;
126 return device->DirectoryExists(url.path());
127 }
128
129 bool DeviceMediaFileUtil::IsDirectoryEmpty(
130 FileSystemOperationContext* context,
131 const FileSystemURL& url) {
132 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device());
133 if (!device.get())
134 return false;
135 return device->IsDirectoryEmpty(url.path());
136 }
137
138 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile(
139 FileSystemOperationContext* context,
140 const FileSystemURL& src_url,
141 const FileSystemURL& dest_url,
142 bool copy) {
143 return base::PLATFORM_FILE_ERROR_SECURITY;
144 }
145
146 PlatformFileError DeviceMediaFileUtil::CopyInForeignFile(
147 FileSystemOperationContext* context,
148 const FilePath& src_file_path,
149 const FileSystemURL& dest_url) {
150 return base::PLATFORM_FILE_ERROR_SECURITY;
151 }
152
153 PlatformFileError DeviceMediaFileUtil::DeleteFile(
154 FileSystemOperationContext* context,
155 const FileSystemURL& url) {
156 return base::PLATFORM_FILE_ERROR_SECURITY;
157 }
158
159 PlatformFileError DeviceMediaFileUtil::DeleteSingleDirectory(
160 FileSystemOperationContext* context,
161 const FileSystemURL& url) {
162 return base::PLATFORM_FILE_ERROR_SECURITY;
163 }
164
165 scoped_refptr<ShareableFileReference> DeviceMediaFileUtil::CreateSnapshotFile(
166 FileSystemOperationContext* context,
167 const FileSystemURL& url,
168 base::PlatformFileError* result,
169 base::PlatformFileInfo* file_info,
170 FilePath* local_path) {
kinuko 2012/07/30 23:19:03 Can we DCHECK out ptrs before we dereference them?
kmadhusu 2012/07/31 01:17:48 Done.
171 scoped_refptr<ShareableFileReference> file_ref;
172 *result = base::PLATFORM_FILE_ERROR_INVALID_URL;
173
174 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device());
175 if (!device.get())
kinuko 2012/07/30 23:19:03 Maybe we should set a better error code to *result
kmadhusu 2012/07/31 01:17:48 This is very unlikely to happen. As we discussed,
176 return file_ref;
177
178 // Create a temp file in "profile_path_/kIsolatedMediaFileSystemDir".
179 FilePath isolated_media_file_system_dir_path =
180 profile_path_.Append(kIsolatedMediaFileSystemDir);
181 bool dir_exists = file_util::DirectoryExists(
182 isolated_media_file_system_dir_path);
183 if (!dir_exists) {
184 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path))
kinuko 2012/07/30 23:19:03 ditto.
kmadhusu 2012/07/31 01:17:48 Done.
185 return file_ref;
186 }
187
188 bool file_created = file_util::CreateTemporaryFileInDir(
Lei Zhang 2012/07/30 23:03:25 kinuko: What do you think of this potential issue?
kinuko 2012/07/30 23:19:03 I see what you mean. I think we should rather fix
189 isolated_media_file_system_dir_path, local_path);
190 if (!file_created)
kinuko 2012/07/30 23:19:03 ditto.
kmadhusu 2012/07/31 01:17:48 Done.
191 return file_ref;
192
193 if (device->CreateSnapshotFile(url.path(), *local_path, file_info))
194 *result = base::PLATFORM_FILE_OK;
195
196 if (*result != base::PLATFORM_FILE_ERROR_INVALID_URL) {
kinuko 2012/07/30 23:19:03 if (*result == base::PLATFORM_FILE_OK)
kmadhusu 2012/07/31 01:17:48 Done.
197 file_ref = ShareableFileReference::GetOrCreate(
198 *local_path,
199 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
200 context->file_task_runner());
201 }
202 return file_ref;
203 }
204
205 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698