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

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

Issue 6603034: Stop returning the true root path of each filesystem from openFileSystem.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/fileapi/local_file_system_file_util.h"
6
7 #include "base/file_util_proxy.h"
8 #include "googleurl/src/gurl.h"
9 #include "webkit/fileapi/file_system_context.h"
10 #include "webkit/fileapi/file_system_operation_context.h"
11 #include "webkit/fileapi/file_system_path_manager.h"
12 #include "webkit/fileapi/file_system_types.h"
13 #include "webkit/fileapi/file_system_util.h"
14
15 namespace fileapi {
16
17 LocalFileSystemFileUtil* LocalFileSystemFileUtil::GetInstance() {
18 return Singleton<LocalFileSystemFileUtil>::get();
19 }
20
21 PlatformFileError LocalFileSystemFileUtil::CreateOrOpen(
22 FileSystemOperationContext* context,
23 const FilePath& file_path, int file_flags,
24 PlatformFile* file_handle, bool* created) {
25 FilePath local_path =
26 GetLocalPath(context, context->src_origin_url(), context->src_type(),
27 file_path);
28 if (local_path.empty())
29 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
30 return FileSystemFileUtil::GetInstance()->CreateOrOpen(
31 context, local_path, file_flags, file_handle, created);
32 }
33
34 PlatformFileError LocalFileSystemFileUtil::EnsureFileExists(
35 FileSystemOperationContext* context,
36 const FilePath& file_path,
37 bool* created) {
38 FilePath local_path =
39 GetLocalPath(context, context->src_origin_url(), context->src_type(),
40 file_path);
41 if (local_path.empty())
42 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
43 return FileSystemFileUtil::GetInstance()->EnsureFileExists(
44 context, local_path, created);
45 }
46
47 PlatformFileError LocalFileSystemFileUtil::GetFileInfo(
48 FileSystemOperationContext* context,
49 const FilePath& file_path,
50 base::PlatformFileInfo* file_info) {
51 FilePath local_path =
52 GetLocalPath(context, context->src_origin_url(), context->src_type(),
53 file_path);
54 if (local_path.empty())
55 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
56 return FileSystemFileUtil::GetInstance()->GetFileInfo(
57 context, local_path, file_info);
58 }
59
60 PlatformFileError LocalFileSystemFileUtil::ReadDirectory(
61 FileSystemOperationContext* context,
62 const FilePath& file_path,
63 std::vector<base::FileUtilProxy::Entry>* entries) {
64 // TODO(kkanetkar): Implement directory read in multiple chunks.
65 FilePath local_path =
66 GetLocalPath(context, context->src_origin_url(), context->src_type(),
67 file_path);
68 if (local_path.empty())
69 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
70 return FileSystemFileUtil::GetInstance()->ReadDirectory(
71 context, local_path, entries);
72 }
73
74 PlatformFileError LocalFileSystemFileUtil::CreateDirectory(
75 FileSystemOperationContext* context,
76 const FilePath& file_path,
77 bool exclusive,
78 bool recursive) {
79 FilePath local_path =
80 GetLocalPath(context, context->src_origin_url(), context->src_type(),
81 file_path);
82 if (local_path.empty())
83 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
84 return FileSystemFileUtil::GetInstance()->CreateDirectory(
85 context, local_path, exclusive, recursive);
86 }
87
88 PlatformFileError LocalFileSystemFileUtil::Copy(
89 FileSystemOperationContext* context,
90 const FilePath& src_file_path,
91 const FilePath& dest_file_path) {
92 // TODO(ericu): If they share a root URL, this could be optimized.
93 FilePath local_src_path =
94 GetLocalPath(context, context->src_origin_url(), context->src_type(),
95 src_file_path);
96 if (local_src_path.empty())
97 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
98 FilePath local_dest_path =
99 GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
100 dest_file_path);
101 if (local_dest_path.empty())
102 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
103 return FileSystemFileUtil::GetInstance()->Copy(
104 context, local_src_path, local_dest_path);
105 }
106
107 PlatformFileError LocalFileSystemFileUtil::Move(
108 FileSystemOperationContext* context,
109 const FilePath& src_file_path,
110 const FilePath& dest_file_path) {
111 // TODO(ericu): If they share a root URL, this could be optimized.
112 FilePath local_src_path =
113 GetLocalPath(context, context->src_origin_url(), context->src_type(),
114 src_file_path);
115 if (local_src_path.empty())
116 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
117 FilePath local_dest_path =
118 GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
119 dest_file_path);
120 if (local_dest_path.empty())
121 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
122 return FileSystemFileUtil::GetInstance()->Move(
123 context, local_src_path, local_dest_path);
124 }
125
126 PlatformFileError LocalFileSystemFileUtil::Delete(
127 FileSystemOperationContext* context,
128 const FilePath& file_path,
129 bool recursive) {
130 FilePath local_path =
131 GetLocalPath(context, context->src_origin_url(), context->src_type(),
132 file_path);
133 if (local_path.empty())
134 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
135 return FileSystemFileUtil::GetInstance()->Delete(
136 context, local_path, recursive);
137 }
138
139 PlatformFileError LocalFileSystemFileUtil::Touch(
140 FileSystemOperationContext* context,
141 const FilePath& file_path,
142 const base::Time& last_access_time,
143 const base::Time& last_modified_time) {
144 FilePath local_path =
145 GetLocalPath(context, context->src_origin_url(), context->src_type(),
146 file_path);
147 if (local_path.empty())
148 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
149 return FileSystemFileUtil::GetInstance()->Touch(
150 context, local_path, last_access_time, last_modified_time);
151 }
152
153 PlatformFileError LocalFileSystemFileUtil::Truncate(
154 FileSystemOperationContext* context,
155 const FilePath& file_path,
156 int64 length) {
157 FilePath local_path =
158 GetLocalPath(context, context->src_origin_url(), context->src_type(),
159 file_path);
160 if (local_path.empty())
161 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
162 return FileSystemFileUtil::GetInstance()->Truncate(
163 context, local_path, length);
164 }
165
166 FilePath LocalFileSystemFileUtil::GetLocalPath(
167 FileSystemOperationContext* context,
168 const GURL& origin_url,
169 FileSystemType type,
170 const FilePath& virtual_path) {
171 FilePath root = context->file_system_context()->path_manager()->
172 GetFileSystemRootPathOnFileThread(origin_url, type, false);
173 if (root.empty())
174 return FilePath();
175 return root.Append(virtual_path);
176 }
177
178 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/local_file_system_file_util.h ('k') | webkit/fileapi/sandbox_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698