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

Side by Side Diff: webkit/fileapi/local_file_system_file_util.cc

Issue 7174002: Change {Obfuscated|Local}FileSystemFileUtil non-Singleton to take an underlying *FileUtil. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebased. Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/local_file_system_file_util.h" 5 #include "webkit/fileapi/local_file_system_file_util.h"
6 6
7 #include "base/file_util_proxy.h" 7 #include "base/file_util_proxy.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "webkit/fileapi/file_system_context.h" 9 #include "webkit/fileapi/file_system_context.h"
10 #include "webkit/fileapi/file_system_operation_context.h" 10 #include "webkit/fileapi/file_system_operation_context.h"
11 #include "webkit/fileapi/file_system_path_manager.h" 11 #include "webkit/fileapi/file_system_path_manager.h"
12 #include "webkit/fileapi/file_system_types.h" 12 #include "webkit/fileapi/file_system_types.h"
13 #include "webkit/fileapi/file_system_util.h" 13 #include "webkit/fileapi/file_system_util.h"
14 #include "webkit/fileapi/quota_file_util.h"
15 14
16 namespace fileapi { 15 namespace fileapi {
17 16
18 LocalFileSystemFileUtil* LocalFileSystemFileUtil::GetInstance() { 17 LocalFileSystemFileUtil::LocalFileSystemFileUtil(
19 return Singleton<LocalFileSystemFileUtil>::get(); 18 FileSystemFileUtil* underlying_file_util)
19 : underlying_file_util_(underlying_file_util) {
20 } 20 }
21 21
22 PlatformFileError LocalFileSystemFileUtil::CreateOrOpen( 22 PlatformFileError LocalFileSystemFileUtil::CreateOrOpen(
23 FileSystemOperationContext* context, 23 FileSystemOperationContext* context,
24 const FilePath& file_path, int file_flags, 24 const FilePath& file_path, int file_flags,
25 PlatformFile* file_handle, bool* created) { 25 PlatformFile* file_handle, bool* created) {
26 FilePath local_path = 26 FilePath local_path =
27 GetLocalPath(context, context->src_origin_url(), context->src_type(), 27 GetLocalPath(context, context->src_origin_url(), context->src_type(),
28 file_path); 28 file_path);
29 if (local_path.empty()) 29 if (local_path.empty())
30 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 30 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
31 return QuotaFileUtil::GetInstance()->CreateOrOpen( 31 return underlying_file_util_->CreateOrOpen(
32 context, local_path, file_flags, file_handle, created); 32 context, local_path, file_flags, file_handle, created);
33 } 33 }
34 34
35 PlatformFileError LocalFileSystemFileUtil::EnsureFileExists( 35 PlatformFileError LocalFileSystemFileUtil::EnsureFileExists(
36 FileSystemOperationContext* context, 36 FileSystemOperationContext* context,
37 const FilePath& file_path, 37 const FilePath& file_path,
38 bool* created) { 38 bool* created) {
39 FilePath local_path = 39 FilePath local_path =
40 GetLocalPath(context, context->src_origin_url(), context->src_type(), 40 GetLocalPath(context, context->src_origin_url(), context->src_type(),
41 file_path); 41 file_path);
42 if (local_path.empty()) 42 if (local_path.empty())
43 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 43 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
44 return QuotaFileUtil::GetInstance()->EnsureFileExists( 44 return underlying_file_util_->EnsureFileExists(
45 context, local_path, created); 45 context, local_path, created);
46 } 46 }
47 47
48 PlatformFileError LocalFileSystemFileUtil::GetLocalFilePath( 48 PlatformFileError LocalFileSystemFileUtil::GetLocalFilePath(
49 FileSystemOperationContext* context, 49 FileSystemOperationContext* context,
50 const FilePath& virtual_path, 50 const FilePath& virtual_path,
51 FilePath* local_path) { 51 FilePath* local_path) {
52 FilePath path = 52 FilePath path =
53 GetLocalPath(context, context->src_origin_url(), context->src_type(), 53 GetLocalPath(context, context->src_origin_url(), context->src_type(),
54 virtual_path); 54 virtual_path);
55 if (path.empty()) 55 if (path.empty())
56 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 56 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
57 57
58 *local_path = path; 58 *local_path = path;
59 return base::PLATFORM_FILE_OK; 59 return base::PLATFORM_FILE_OK;
60 } 60 }
61 61
62 PlatformFileError LocalFileSystemFileUtil::GetFileInfo( 62 PlatformFileError LocalFileSystemFileUtil::GetFileInfo(
63 FileSystemOperationContext* context, 63 FileSystemOperationContext* context,
64 const FilePath& file_path, 64 const FilePath& file_path,
65 base::PlatformFileInfo* file_info, 65 base::PlatformFileInfo* file_info,
66 FilePath* platform_file_path) { 66 FilePath* platform_file_path) {
67 FilePath local_path = 67 FilePath local_path =
68 GetLocalPath(context, context->src_origin_url(), context->src_type(), 68 GetLocalPath(context, context->src_origin_url(), context->src_type(),
69 file_path); 69 file_path);
70 if (local_path.empty()) 70 if (local_path.empty())
71 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 71 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
72 return QuotaFileUtil::GetInstance()->GetFileInfo( 72 return underlying_file_util_->GetFileInfo(
73 context, local_path, file_info, platform_file_path); 73 context, local_path, file_info, platform_file_path);
74 } 74 }
75 75
76 PlatformFileError LocalFileSystemFileUtil::ReadDirectory( 76 PlatformFileError LocalFileSystemFileUtil::ReadDirectory(
77 FileSystemOperationContext* context, 77 FileSystemOperationContext* context,
78 const FilePath& file_path, 78 const FilePath& file_path,
79 std::vector<base::FileUtilProxy::Entry>* entries) { 79 std::vector<base::FileUtilProxy::Entry>* entries) {
80 // TODO(kkanetkar): Implement directory read in multiple chunks. 80 // TODO(kkanetkar): Implement directory read in multiple chunks.
81 FilePath local_path = 81 FilePath local_path =
82 GetLocalPath(context, context->src_origin_url(), context->src_type(), 82 GetLocalPath(context, context->src_origin_url(), context->src_type(),
83 file_path); 83 file_path);
84 if (local_path.empty()) 84 if (local_path.empty())
85 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 85 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
86 return QuotaFileUtil::GetInstance()->ReadDirectory( 86 return underlying_file_util_->ReadDirectory(
87 context, local_path, entries); 87 context, local_path, entries);
88 } 88 }
89 89
90 PlatformFileError LocalFileSystemFileUtil::CreateDirectory( 90 PlatformFileError LocalFileSystemFileUtil::CreateDirectory(
91 FileSystemOperationContext* context, 91 FileSystemOperationContext* context,
92 const FilePath& file_path, 92 const FilePath& file_path,
93 bool exclusive, 93 bool exclusive,
94 bool recursive) { 94 bool recursive) {
95 FilePath local_path = 95 FilePath local_path =
96 GetLocalPath(context, context->src_origin_url(), context->src_type(), 96 GetLocalPath(context, context->src_origin_url(), context->src_type(),
97 file_path); 97 file_path);
98 if (local_path.empty()) 98 if (local_path.empty())
99 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 99 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
100 return QuotaFileUtil::GetInstance()->CreateDirectory( 100 return underlying_file_util_->CreateDirectory(
101 context, local_path, exclusive, recursive); 101 context, local_path, exclusive, recursive);
102 } 102 }
103 103
104 PlatformFileError LocalFileSystemFileUtil::CopyOrMoveFile( 104 PlatformFileError LocalFileSystemFileUtil::CopyOrMoveFile(
105 FileSystemOperationContext* context, 105 FileSystemOperationContext* context,
106 const FilePath& src_file_path, 106 const FilePath& src_file_path,
107 const FilePath& dest_file_path, 107 const FilePath& dest_file_path,
108 bool copy) { 108 bool copy) {
109 // TODO(ericu): If they share a root URL, this could be optimized. 109 // TODO(ericu): If they share a root URL, this could be optimized.
110 FilePath local_src_path = 110 FilePath local_src_path =
111 GetLocalPath(context, context->src_origin_url(), context->src_type(), 111 GetLocalPath(context, context->src_origin_url(), context->src_type(),
112 src_file_path); 112 src_file_path);
113 if (local_src_path.empty()) 113 if (local_src_path.empty())
114 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 114 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
115 FilePath local_dest_path = 115 FilePath local_dest_path =
116 GetLocalPath(context, context->dest_origin_url(), context->dest_type(), 116 GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
117 dest_file_path); 117 dest_file_path);
118 if (local_dest_path.empty()) 118 if (local_dest_path.empty())
119 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 119 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
120 return QuotaFileUtil::GetInstance()->CopyOrMoveFile( 120 return underlying_file_util_->CopyOrMoveFile(
121 context, local_src_path, local_dest_path, copy); 121 context, local_src_path, local_dest_path, copy);
122 } 122 }
123 123
124 PlatformFileError LocalFileSystemFileUtil::CopyInForeignFile( 124 PlatformFileError LocalFileSystemFileUtil::CopyInForeignFile(
125 FileSystemOperationContext* context, 125 FileSystemOperationContext* context,
126 const FilePath& src_file_path, 126 const FilePath& src_file_path,
127 const FilePath& dest_file_path) { 127 const FilePath& dest_file_path) {
128 if (src_file_path.empty()) 128 if (src_file_path.empty())
129 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 129 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
130 FilePath local_dest_path = 130 FilePath local_dest_path =
131 GetLocalPath(context, context->dest_origin_url(), context->dest_type(), 131 GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
132 dest_file_path); 132 dest_file_path);
133 if (local_dest_path.empty()) 133 if (local_dest_path.empty())
134 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 134 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
135 return QuotaFileUtil::GetInstance()->CopyOrMoveFile( 135 return underlying_file_util_->CopyOrMoveFile(
136 context, src_file_path, local_dest_path, true); 136 context, src_file_path, local_dest_path, true);
137 } 137 }
138 138
139 PlatformFileError LocalFileSystemFileUtil::DeleteFile( 139 PlatformFileError LocalFileSystemFileUtil::DeleteFile(
140 FileSystemOperationContext* context, 140 FileSystemOperationContext* context,
141 const FilePath& file_path) { 141 const FilePath& file_path) {
142 FilePath local_path = 142 FilePath local_path =
143 GetLocalPath(context, context->src_origin_url(), context->src_type(), 143 GetLocalPath(context, context->src_origin_url(), context->src_type(),
144 file_path); 144 file_path);
145 if (local_path.empty()) 145 if (local_path.empty())
146 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 146 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
147 return QuotaFileUtil::GetInstance()->DeleteFile( 147 return underlying_file_util_->DeleteFile(
148 context, local_path); 148 context, local_path);
149 } 149 }
150 150
151 PlatformFileError LocalFileSystemFileUtil::DeleteSingleDirectory( 151 PlatformFileError LocalFileSystemFileUtil::DeleteSingleDirectory(
152 FileSystemOperationContext* context, 152 FileSystemOperationContext* context,
153 const FilePath& file_path) { 153 const FilePath& file_path) {
154 FilePath local_path = 154 FilePath local_path =
155 GetLocalPath(context, context->src_origin_url(), context->src_type(), 155 GetLocalPath(context, context->src_origin_url(), context->src_type(),
156 file_path); 156 file_path);
157 if (local_path.empty()) 157 if (local_path.empty())
158 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 158 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
159 return QuotaFileUtil::GetInstance()->DeleteSingleDirectory( 159 return underlying_file_util_->DeleteSingleDirectory(
160 context, local_path); 160 context, local_path);
161 } 161 }
162 162
163 PlatformFileError LocalFileSystemFileUtil::Touch( 163 PlatformFileError LocalFileSystemFileUtil::Touch(
164 FileSystemOperationContext* context, 164 FileSystemOperationContext* context,
165 const FilePath& file_path, 165 const FilePath& file_path,
166 const base::Time& last_access_time, 166 const base::Time& last_access_time,
167 const base::Time& last_modified_time) { 167 const base::Time& last_modified_time) {
168 FilePath local_path = 168 FilePath local_path =
169 GetLocalPath(context, context->src_origin_url(), context->src_type(), 169 GetLocalPath(context, context->src_origin_url(), context->src_type(),
170 file_path); 170 file_path);
171 if (local_path.empty()) 171 if (local_path.empty())
172 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 172 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
173 return QuotaFileUtil::GetInstance()->Touch( 173 return underlying_file_util_->Touch(
174 context, local_path, last_access_time, last_modified_time); 174 context, local_path, last_access_time, last_modified_time);
175 } 175 }
176 176
177 PlatformFileError LocalFileSystemFileUtil::Truncate( 177 PlatformFileError LocalFileSystemFileUtil::Truncate(
178 FileSystemOperationContext* context, 178 FileSystemOperationContext* context,
179 const FilePath& file_path, 179 const FilePath& file_path,
180 int64 length) { 180 int64 length) {
181 FilePath local_path = 181 FilePath local_path =
182 GetLocalPath(context, context->src_origin_url(), context->src_type(), 182 GetLocalPath(context, context->src_origin_url(), context->src_type(),
183 file_path); 183 file_path);
184 if (local_path.empty()) 184 if (local_path.empty())
185 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 185 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
186 return QuotaFileUtil::GetInstance()->Truncate( 186 return underlying_file_util_->Truncate(
187 context, local_path, length); 187 context, local_path, length);
188 } 188 }
189 189
190 bool LocalFileSystemFileUtil::PathExists( 190 bool LocalFileSystemFileUtil::PathExists(
191 FileSystemOperationContext* context, 191 FileSystemOperationContext* context,
192 const FilePath& file_path) { 192 const FilePath& file_path) {
193 FilePath local_path = 193 FilePath local_path =
194 GetLocalPath(context, context->src_origin_url(), context->src_type(), 194 GetLocalPath(context, context->src_origin_url(), context->src_type(),
195 file_path); 195 file_path);
196 if (local_path.empty()) 196 if (local_path.empty())
197 return false; 197 return false;
198 return QuotaFileUtil::GetInstance()->PathExists( 198 return underlying_file_util_->PathExists(
199 context, local_path); 199 context, local_path);
200 } 200 }
201 201
202 bool LocalFileSystemFileUtil::DirectoryExists( 202 bool LocalFileSystemFileUtil::DirectoryExists(
203 FileSystemOperationContext* context, 203 FileSystemOperationContext* context,
204 const FilePath& file_path) { 204 const FilePath& file_path) {
205 FilePath local_path = 205 FilePath local_path =
206 GetLocalPath(context, context->src_origin_url(), context->src_type(), 206 GetLocalPath(context, context->src_origin_url(), context->src_type(),
207 file_path); 207 file_path);
208 if (local_path.empty()) 208 if (local_path.empty())
209 return false; 209 return false;
210 return QuotaFileUtil::GetInstance()->DirectoryExists( 210 return underlying_file_util_->DirectoryExists(
211 context, local_path); 211 context, local_path);
212 } 212 }
213 213
214 bool LocalFileSystemFileUtil::IsDirectoryEmpty( 214 bool LocalFileSystemFileUtil::IsDirectoryEmpty(
215 FileSystemOperationContext* context, 215 FileSystemOperationContext* context,
216 const FilePath& file_path) { 216 const FilePath& file_path) {
217 FilePath local_path = 217 FilePath local_path =
218 GetLocalPath(context, context->src_origin_url(), context->src_type(), 218 GetLocalPath(context, context->src_origin_url(), context->src_type(),
219 file_path); 219 file_path);
220 if (local_path.empty()) 220 if (local_path.empty())
221 return true; 221 return true;
222 return QuotaFileUtil::GetInstance()->IsDirectoryEmpty( 222 return underlying_file_util_->IsDirectoryEmpty(
223 context, local_path); 223 context, local_path);
224 } 224 }
225 225
226 class LocalFileSystemFileEnumerator 226 class LocalFileSystemFileEnumerator
227 : public FileSystemFileUtil::AbstractFileEnumerator { 227 : public FileSystemFileUtil::AbstractFileEnumerator {
228 public: 228 public:
229 LocalFileSystemFileEnumerator(const FilePath& platform_root_path, 229 LocalFileSystemFileEnumerator(const FilePath& platform_root_path,
230 const FilePath& virtual_root_path, 230 const FilePath& virtual_root_path,
231 bool recursive, 231 bool recursive,
232 file_util::FileEnumerator::FILE_TYPE file_type) 232 file_util::FileEnumerator::FILE_TYPE file_type)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 const FilePath& virtual_path) { 285 const FilePath& virtual_path) {
286 FilePath root = context->file_system_context()->path_manager()-> 286 FilePath root = context->file_system_context()->path_manager()->
287 ValidateFileSystemRootAndGetPathOnFileThread(origin_url, type, 287 ValidateFileSystemRootAndGetPathOnFileThread(origin_url, type,
288 virtual_path, false); 288 virtual_path, false);
289 if (root.empty()) 289 if (root.empty())
290 return FilePath(); 290 return FilePath();
291 return root.Append(virtual_path); 291 return root.Append(virtual_path);
292 } 292 }
293 293
294 } // namespace fileapi 294 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/local_file_system_file_util.h ('k') | webkit/fileapi/local_file_system_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698