OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_system_path_manager.h" | 5 #include "webkit/fileapi/file_system_path_manager.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 DispatchCallbackOnCallerThread(FilePath()); | 117 DispatchCallbackOnCallerThread(FilePath()); |
118 return; | 118 return; |
119 } | 119 } |
120 | 120 |
121 // Creates the root directory. | 121 // Creates the root directory. |
122 root = base_path.Append(CreateUniqueDirectoryName(origin_url)); | 122 root = base_path.Append(CreateUniqueDirectoryName(origin_url)); |
123 if (!file_util::CreateDirectory(root)) { | 123 if (!file_util::CreateDirectory(root)) { |
124 DispatchCallbackOnCallerThread(FilePath()); | 124 DispatchCallbackOnCallerThread(FilePath()); |
125 return; | 125 return; |
126 } | 126 } |
127 | |
128 DispatchCallbackOnCallerThread(root); | 127 DispatchCallbackOnCallerThread(root); |
129 } | 128 } |
130 | 129 |
131 bool ReadOriginDirectory(const FilePath& base_path, | 130 bool ReadOriginDirectory(const FilePath& base_path, |
132 const GURL& origin_url, | 131 const GURL& origin_url, |
133 FilePath* unique) { | 132 FilePath* unique) { |
134 file_util::FileEnumerator file_enum( | 133 file_util::FileEnumerator file_enum( |
135 base_path, false /* recursive */, | 134 base_path, false /* recursive */, |
136 file_util::FileEnumerator::DIRECTORIES, | 135 file_util::FileEnumerator::DIRECTORIES, |
137 FilePath::StringType(kFileSystemUniqueNamePrefix) + | 136 FilePath::StringType(kFileSystemUniqueNamePrefix) + |
(...skipping 26 matching lines...) Expand all Loading... |
164 callback_->Run(!root_path.empty(), root_path, name_); | 163 callback_->Run(!root_path.empty(), root_path, name_); |
165 callback_.reset(); | 164 callback_.reset(); |
166 } | 165 } |
167 | 166 |
168 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | 167 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
169 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 168 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
170 std::string name_; | 169 std::string name_; |
171 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback_; | 170 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback_; |
172 }; | 171 }; |
173 | 172 |
174 FilePath FileSystemPathManager::GetFileSystemCommonRootDirectory( | |
175 const FilePath& root_path) { | |
176 #if defined(OS_WIN) | |
177 // To specify an extended-length path, "\\?\" prefix is used. Else path names | |
178 // are limited to 260 characters. | |
179 FilePath::StringType extended_length_str(L"\\\\?\\"); | |
180 extended_length_str.append(root_path.value()); | |
181 return FilePath(extended_length_str).Append(kFileSystemDirectory); | |
182 #endif | |
183 return root_path.Append(kFileSystemDirectory); | |
184 } | |
185 | |
186 FileSystemPathManager::FileSystemPathManager( | 173 FileSystemPathManager::FileSystemPathManager( |
187 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 174 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
188 const FilePath& profile_path, | 175 const FilePath& profile_path, |
189 bool is_incognito, | 176 bool is_incognito, |
190 bool allow_file_access_from_files) | 177 bool allow_file_access_from_files) |
191 : file_message_loop_(file_message_loop), | 178 : file_message_loop_(file_message_loop), |
192 base_path_(GetFileSystemCommonRootDirectory(profile_path)), | 179 base_path_(profile_path.Append(kFileSystemDirectory)), |
193 is_incognito_(is_incognito), | 180 is_incognito_(is_incognito), |
194 allow_file_access_from_files_(allow_file_access_from_files) { | 181 allow_file_access_from_files_(allow_file_access_from_files) { |
195 } | 182 } |
196 | 183 |
197 FileSystemPathManager::~FileSystemPathManager() {} | 184 FileSystemPathManager::~FileSystemPathManager() {} |
198 | 185 |
199 void FileSystemPathManager::GetFileSystemRootPath( | 186 void FileSystemPathManager::GetFileSystemRootPath( |
200 const GURL& origin_url, fileapi::FileSystemType type, | 187 const GURL& origin_url, fileapi::FileSystemType type, |
201 bool create, GetRootPathCallback* callback_ptr) { | 188 bool create, GetRootPathCallback* callback_ptr) { |
202 scoped_ptr<GetRootPathCallback> callback(callback_ptr); | 189 scoped_ptr<GetRootPathCallback> callback(callback_ptr); |
(...skipping 18 matching lines...) Expand all Loading... |
221 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); | 208 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); |
222 | 209 |
223 std::string type_string; | 210 std::string type_string; |
224 if (type == fileapi::kFileSystemTypeTemporary) | 211 if (type == fileapi::kFileSystemTypeTemporary) |
225 type_string = kTemporaryName; | 212 type_string = kTemporaryName; |
226 else if (type == fileapi::kFileSystemTypePersistent) | 213 else if (type == fileapi::kFileSystemTypePersistent) |
227 type_string = kPersistentName; | 214 type_string = kPersistentName; |
228 DCHECK(!type_string.empty()); | 215 DCHECK(!type_string.empty()); |
229 | 216 |
230 FilePath origin_base_path = base_path_.AppendASCII(storage_identifier) | 217 FilePath origin_base_path = base_path_.AppendASCII(storage_identifier) |
231 .AppendASCII(type_string); | 218 .AppendASCII(type_string); |
232 | |
233 std::string name = storage_identifier + ":" + type_string; | 219 std::string name = storage_identifier + ":" + type_string; |
234 | 220 |
235 scoped_refptr<GetFileSystemRootPathTask> task( | 221 scoped_refptr<GetFileSystemRootPathTask> task( |
236 new GetFileSystemRootPathTask(file_message_loop_, | 222 new GetFileSystemRootPathTask(file_message_loop_, |
237 name, callback.release())); | 223 name, callback.release())); |
238 task->Start(origin_url, origin_base_path, create); | 224 task->Start(origin_url, origin_base_path, create); |
239 } | 225 } |
240 | 226 |
241 bool FileSystemPathManager::CrackFileSystemPath( | 227 bool FileSystemPathManager::CrackFileSystemPath( |
242 const FilePath& path, GURL* origin_url, FileSystemType* type, | 228 const FilePath& path, GURL* origin_url, FileSystemType* type, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); | 332 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); |
347 return web_security_origin.databaseIdentifier().utf8(); | 333 return web_security_origin.databaseIdentifier().utf8(); |
348 } | 334 } |
349 | 335 |
350 } // namespace fileapi | 336 } // namespace fileapi |
351 | 337 |
352 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ | 338 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ |
353 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); | 339 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); |
354 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ | 340 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ |
355 int(fileapi::kFileSystemTypePersistent), mismatching_enums); | 341 int(fileapi::kFileSystemTypePersistent), mismatching_enums); |
OLD | NEW |