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 | |
127 DispatchCallbackOnCallerThread(root); | 128 DispatchCallbackOnCallerThread(root); |
128 } | 129 } |
129 | 130 |
130 bool ReadOriginDirectory(const FilePath& base_path, | 131 bool ReadOriginDirectory(const FilePath& base_path, |
131 const GURL& origin_url, | 132 const GURL& origin_url, |
132 FilePath* unique) { | 133 FilePath* unique) { |
133 file_util::FileEnumerator file_enum( | 134 file_util::FileEnumerator file_enum( |
134 base_path, false /* recursive */, | 135 base_path, false /* recursive */, |
135 file_util::FileEnumerator::DIRECTORIES, | 136 file_util::FileEnumerator::DIRECTORIES, |
136 FilePath::StringType(kFileSystemUniqueNamePrefix) + | 137 FilePath::StringType(kFileSystemUniqueNamePrefix) + |
(...skipping 26 matching lines...) Expand all Loading... | |
163 callback_->Run(!root_path.empty(), root_path, name_); | 164 callback_->Run(!root_path.empty(), root_path, name_); |
164 callback_.reset(); | 165 callback_.reset(); |
165 } | 166 } |
166 | 167 |
167 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | 168 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
168 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 169 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
169 std::string name_; | 170 std::string name_; |
170 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback_; | 171 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback_; |
171 }; | 172 }; |
172 | 173 |
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"\\\\?\\"); | |
kinuko
2010/12/15 00:09:30
Can we use FilePath::kExtendedPathPrefix?
Also mig
Kavita Kanetkar
2010/12/16 00:48:55
Done.
| |
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 | |
173 FileSystemPathManager::FileSystemPathManager( | 186 FileSystemPathManager::FileSystemPathManager( |
174 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 187 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
175 const FilePath& profile_path, | 188 const FilePath& profile_path, |
176 bool is_incognito, | 189 bool is_incognito, |
177 bool allow_file_access_from_files) | 190 bool allow_file_access_from_files) |
178 : file_message_loop_(file_message_loop), | 191 : file_message_loop_(file_message_loop), |
179 base_path_(profile_path.Append(kFileSystemDirectory)), | 192 base_path_(GetFileSystemCommonRootDirectory(profile_path)), |
180 is_incognito_(is_incognito), | 193 is_incognito_(is_incognito), |
181 allow_file_access_from_files_(allow_file_access_from_files) { | 194 allow_file_access_from_files_(allow_file_access_from_files) { |
182 } | 195 } |
183 | 196 |
184 FileSystemPathManager::~FileSystemPathManager() {} | 197 FileSystemPathManager::~FileSystemPathManager() {} |
185 | 198 |
186 void FileSystemPathManager::GetFileSystemRootPath( | 199 void FileSystemPathManager::GetFileSystemRootPath( |
187 const GURL& origin_url, fileapi::FileSystemType type, | 200 const GURL& origin_url, fileapi::FileSystemType type, |
188 bool create, GetRootPathCallback* callback_ptr) { | 201 bool create, GetRootPathCallback* callback_ptr) { |
189 scoped_ptr<GetRootPathCallback> callback(callback_ptr); | 202 scoped_ptr<GetRootPathCallback> callback(callback_ptr); |
(...skipping 18 matching lines...) Expand all Loading... | |
208 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); | 221 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); |
209 | 222 |
210 std::string type_string; | 223 std::string type_string; |
211 if (type == fileapi::kFileSystemTypeTemporary) | 224 if (type == fileapi::kFileSystemTypeTemporary) |
212 type_string = kTemporaryName; | 225 type_string = kTemporaryName; |
213 else if (type == fileapi::kFileSystemTypePersistent) | 226 else if (type == fileapi::kFileSystemTypePersistent) |
214 type_string = kPersistentName; | 227 type_string = kPersistentName; |
215 DCHECK(!type_string.empty()); | 228 DCHECK(!type_string.empty()); |
216 | 229 |
217 FilePath origin_base_path = base_path_.AppendASCII(storage_identifier) | 230 FilePath origin_base_path = base_path_.AppendASCII(storage_identifier) |
218 .AppendASCII(type_string); | 231 .AppendASCII(type_string); |
232 | |
219 std::string name = storage_identifier + ":" + type_string; | 233 std::string name = storage_identifier + ":" + type_string; |
220 | 234 |
221 scoped_refptr<GetFileSystemRootPathTask> task( | 235 scoped_refptr<GetFileSystemRootPathTask> task( |
222 new GetFileSystemRootPathTask(file_message_loop_, | 236 new GetFileSystemRootPathTask(file_message_loop_, |
223 name, callback.release())); | 237 name, callback.release())); |
224 task->Start(origin_url, origin_base_path, create); | 238 task->Start(origin_url, origin_base_path, create); |
225 } | 239 } |
226 | 240 |
227 bool FileSystemPathManager::CrackFileSystemPath( | 241 bool FileSystemPathManager::CrackFileSystemPath( |
228 const FilePath& path, GURL* origin_url, FileSystemType* type, | 242 const FilePath& path, GURL* origin_url, FileSystemType* type, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); | 346 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); |
333 return web_security_origin.databaseIdentifier().utf8(); | 347 return web_security_origin.databaseIdentifier().utf8(); |
334 } | 348 } |
335 | 349 |
336 } // namespace fileapi | 350 } // namespace fileapi |
337 | 351 |
338 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ | 352 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ |
339 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); | 353 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); |
340 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ | 354 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ |
341 int(fileapi::kFileSystemTypePersistent), mismatching_enums); | 355 int(fileapi::kFileSystemTypePersistent), mismatching_enums); |
OLD | NEW |