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

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

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
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/media/device_media_file_util.h" 5 #include "webkit/fileapi/media/device_media_file_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "webkit/fileapi/file_system_operation_context.h" 9 #include "webkit/fileapi/file_system_operation_context.h"
10 #include "webkit/fileapi/file_system_url.h" 10 #include "webkit/fileapi/file_system_url.h"
11 #include "webkit/fileapi/isolated_context.h" 11 #include "webkit/fileapi/isolated_context.h"
12 #include "webkit/fileapi/media/filtering_file_enumerator.h" 12 #include "webkit/fileapi/media/filtering_file_enumerator.h"
13 #include "webkit/fileapi/media/media_path_filter.h" 13 #include "webkit/fileapi/media/media_path_filter.h"
14 #include "webkit/fileapi/media/mtp_device_delegate.h" 14 #include "webkit/fileapi/media/mtp_device_delegate.h"
15 #include "webkit/fileapi/media/mtp_device_map_service.h" 15 #include "webkit/fileapi/media/mtp_device_map_service.h"
16 16
17 using base::PlatformFile; 17 using base::PlatformFile;
18 using base::PlatformFileError; 18 using base::PlatformFileError;
19 using base::PlatformFileInfo; 19 using base::PlatformFileInfo;
20 20
21 namespace fileapi { 21 namespace fileapi {
22 22
23 namespace { 23 namespace {
24 24
25 const FilePath::CharType kDeviceMediaFileUtilTempDir[] = 25 const base::FilePath::CharType kDeviceMediaFileUtilTempDir[] =
26 FILE_PATH_LITERAL("DeviceMediaFileSystem"); 26 FILE_PATH_LITERAL("DeviceMediaFileSystem");
27 27
28 MTPDeviceDelegate* GetMTPDeviceDelegate(FileSystemOperationContext* context) { 28 MTPDeviceDelegate* GetMTPDeviceDelegate(FileSystemOperationContext* context) {
29 DCHECK(context->task_runner()->RunsTasksOnCurrentThread()); 29 DCHECK(context->task_runner()->RunsTasksOnCurrentThread());
30 return MTPDeviceMapService::GetInstance()->GetMTPDeviceDelegate( 30 return MTPDeviceMapService::GetInstance()->GetMTPDeviceDelegate(
31 context->mtp_device_delegate_url()); 31 context->mtp_device_delegate_url());
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 DeviceMediaFileUtil::DeviceMediaFileUtil(const FilePath& profile_path) 36 DeviceMediaFileUtil::DeviceMediaFileUtil(const base::FilePath& profile_path)
37 : profile_path_(profile_path) { 37 : profile_path_(profile_path) {
38 } 38 }
39 39
40 PlatformFileError DeviceMediaFileUtil::CreateOrOpen( 40 PlatformFileError DeviceMediaFileUtil::CreateOrOpen(
41 FileSystemOperationContext* context, 41 FileSystemOperationContext* context,
42 const FileSystemURL& url, int file_flags, 42 const FileSystemURL& url, int file_flags,
43 PlatformFile* file_handle, bool* created) { 43 PlatformFile* file_handle, bool* created) {
44 return base::PLATFORM_FILE_ERROR_SECURITY; 44 return base::PLATFORM_FILE_ERROR_SECURITY;
45 } 45 }
46 46
(...skipping 16 matching lines...) Expand all
63 const FileSystemURL& url, 63 const FileSystemURL& url,
64 bool exclusive, 64 bool exclusive,
65 bool recursive) { 65 bool recursive) {
66 return base::PLATFORM_FILE_ERROR_SECURITY; 66 return base::PLATFORM_FILE_ERROR_SECURITY;
67 } 67 }
68 68
69 PlatformFileError DeviceMediaFileUtil::GetFileInfo( 69 PlatformFileError DeviceMediaFileUtil::GetFileInfo(
70 FileSystemOperationContext* context, 70 FileSystemOperationContext* context,
71 const FileSystemURL& url, 71 const FileSystemURL& url,
72 PlatformFileInfo* file_info, 72 PlatformFileInfo* file_info,
73 FilePath* platform_path) { 73 base::FilePath* platform_path) {
74 MTPDeviceDelegate* delegate = GetMTPDeviceDelegate(context); 74 MTPDeviceDelegate* delegate = GetMTPDeviceDelegate(context);
75 if (!delegate) 75 if (!delegate)
76 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 76 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
77 77
78 PlatformFileError error = delegate->GetFileInfo(url.path(), file_info); 78 PlatformFileError error = delegate->GetFileInfo(url.path(), file_info);
79 if (error != base::PLATFORM_FILE_OK) 79 if (error != base::PLATFORM_FILE_OK)
80 return error; 80 return error;
81 81
82 if (file_info->is_directory || 82 if (file_info->is_directory ||
83 context->media_path_filter()->Match(url.path())) 83 context->media_path_filter()->Match(url.path()))
(...skipping 13 matching lines...) Expand all
97 } 97 }
98 return scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>( 98 return scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>(
99 new FilteringFileEnumerator( 99 new FilteringFileEnumerator(
100 delegate->CreateFileEnumerator(url.path(), recursive), 100 delegate->CreateFileEnumerator(url.path(), recursive),
101 context->media_path_filter())); 101 context->media_path_filter()));
102 } 102 }
103 103
104 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( 104 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath(
105 FileSystemOperationContext* context, 105 FileSystemOperationContext* context,
106 const FileSystemURL& file_system_url, 106 const FileSystemURL& file_system_url,
107 FilePath* local_file_path) { 107 base::FilePath* local_file_path) {
108 return base::PLATFORM_FILE_ERROR_SECURITY; 108 return base::PLATFORM_FILE_ERROR_SECURITY;
109 } 109 }
110 110
111 PlatformFileError DeviceMediaFileUtil::Touch( 111 PlatformFileError DeviceMediaFileUtil::Touch(
112 FileSystemOperationContext* context, 112 FileSystemOperationContext* context,
113 const FileSystemURL& url, 113 const FileSystemURL& url,
114 const base::Time& last_access_time, 114 const base::Time& last_access_time,
115 const base::Time& last_modified_time) { 115 const base::Time& last_modified_time) {
116 return base::PLATFORM_FILE_ERROR_FAILED; 116 return base::PLATFORM_FILE_ERROR_FAILED;
117 } 117 }
118 118
119 PlatformFileError DeviceMediaFileUtil::Truncate( 119 PlatformFileError DeviceMediaFileUtil::Truncate(
120 FileSystemOperationContext* context, 120 FileSystemOperationContext* context,
121 const FileSystemURL& url, 121 const FileSystemURL& url,
122 int64 length) { 122 int64 length) {
123 return base::PLATFORM_FILE_ERROR_FAILED; 123 return base::PLATFORM_FILE_ERROR_FAILED;
124 } 124 }
125 125
126 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( 126 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile(
127 FileSystemOperationContext* context, 127 FileSystemOperationContext* context,
128 const FileSystemURL& src_url, 128 const FileSystemURL& src_url,
129 const FileSystemURL& dest_url, 129 const FileSystemURL& dest_url,
130 bool copy) { 130 bool copy) {
131 return base::PLATFORM_FILE_ERROR_SECURITY; 131 return base::PLATFORM_FILE_ERROR_SECURITY;
132 } 132 }
133 133
134 PlatformFileError DeviceMediaFileUtil::CopyInForeignFile( 134 PlatformFileError DeviceMediaFileUtil::CopyInForeignFile(
135 FileSystemOperationContext* context, 135 FileSystemOperationContext* context,
136 const FilePath& src_file_path, 136 const base::FilePath& src_file_path,
137 const FileSystemURL& dest_url) { 137 const FileSystemURL& dest_url) {
138 return base::PLATFORM_FILE_ERROR_SECURITY; 138 return base::PLATFORM_FILE_ERROR_SECURITY;
139 } 139 }
140 140
141 PlatformFileError DeviceMediaFileUtil::DeleteFile( 141 PlatformFileError DeviceMediaFileUtil::DeleteFile(
142 FileSystemOperationContext* context, 142 FileSystemOperationContext* context,
143 const FileSystemURL& url) { 143 const FileSystemURL& url) {
144 return base::PLATFORM_FILE_ERROR_SECURITY; 144 return base::PLATFORM_FILE_ERROR_SECURITY;
145 } 145 }
146 146
147 PlatformFileError DeviceMediaFileUtil::DeleteDirectory( 147 PlatformFileError DeviceMediaFileUtil::DeleteDirectory(
148 FileSystemOperationContext* context, 148 FileSystemOperationContext* context,
149 const FileSystemURL& url) { 149 const FileSystemURL& url) {
150 return base::PLATFORM_FILE_ERROR_SECURITY; 150 return base::PLATFORM_FILE_ERROR_SECURITY;
151 } 151 }
152 152
153 base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile( 153 base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile(
154 FileSystemOperationContext* context, 154 FileSystemOperationContext* context,
155 const FileSystemURL& url, 155 const FileSystemURL& url,
156 base::PlatformFileInfo* file_info, 156 base::PlatformFileInfo* file_info,
157 FilePath* local_path, 157 base::FilePath* local_path,
158 SnapshotFilePolicy* snapshot_policy) { 158 SnapshotFilePolicy* snapshot_policy) {
159 DCHECK(file_info); 159 DCHECK(file_info);
160 DCHECK(local_path); 160 DCHECK(local_path);
161 DCHECK(snapshot_policy); 161 DCHECK(snapshot_policy);
162 // We return a temporary file as a snapshot. 162 // We return a temporary file as a snapshot.
163 *snapshot_policy = kSnapshotFileTemporary; 163 *snapshot_policy = kSnapshotFileTemporary;
164 164
165 MTPDeviceDelegate* delegate = GetMTPDeviceDelegate(context); 165 MTPDeviceDelegate* delegate = GetMTPDeviceDelegate(context);
166 if (!delegate) 166 if (!delegate)
167 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 167 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
168 168
169 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". 169 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir".
170 FilePath isolated_media_file_system_dir_path = 170 base::FilePath isolated_media_file_system_dir_path =
171 profile_path_.Append(kDeviceMediaFileUtilTempDir); 171 profile_path_.Append(kDeviceMediaFileUtilTempDir);
172 bool dir_exists = file_util::DirectoryExists( 172 bool dir_exists = file_util::DirectoryExists(
173 isolated_media_file_system_dir_path); 173 isolated_media_file_system_dir_path);
174 if (!dir_exists && 174 if (!dir_exists &&
175 !file_util::CreateDirectory(isolated_media_file_system_dir_path)) { 175 !file_util::CreateDirectory(isolated_media_file_system_dir_path)) {
176 LOG(WARNING) << "Could not create a directory for media snapshot file " 176 LOG(WARNING) << "Could not create a directory for media snapshot file "
177 << isolated_media_file_system_dir_path.value(); 177 << isolated_media_file_system_dir_path.value();
178 return base::PLATFORM_FILE_ERROR_FAILED; 178 return base::PLATFORM_FILE_ERROR_FAILED;
179 } 179 }
180 180
181 bool file_created = file_util::CreateTemporaryFileInDir( 181 bool file_created = file_util::CreateTemporaryFileInDir(
182 isolated_media_file_system_dir_path, local_path); 182 isolated_media_file_system_dir_path, local_path);
183 if (!file_created) { 183 if (!file_created) {
184 LOG(WARNING) << "Could not create a temporary file for media snapshot in " 184 LOG(WARNING) << "Could not create a temporary file for media snapshot in "
185 << isolated_media_file_system_dir_path.value(); 185 << isolated_media_file_system_dir_path.value();
186 return base::PLATFORM_FILE_ERROR_FAILED; 186 return base::PLATFORM_FILE_ERROR_FAILED;
187 } 187 }
188 return delegate->CreateSnapshotFile(url.path(), *local_path, file_info); 188 return delegate->CreateSnapshotFile(url.path(), *local_path, file_info);
189 } 189 }
190 190
191 } // namespace fileapi 191 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/media/device_media_file_util.h ('k') | webkit/fileapi/media/filtering_file_enumerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698