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 if (!root_path.StartsWithExtendedPathPrefix()) { | |
180 FilePath::StringType extended_length_str(FilePath::kExtendedPathPrefix); | |
181 extended_length_str.append(root_path.value()); | |
182 return FilePath(extended_length_str).Append(kFileSystemDirectory); | |
183 } else { | |
kinuko
2010/12/16 01:48:23
this else block looks not necessary.
| |
184 return root_path.Append(kFileSystemDirectory); | |
185 } | |
186 #endif | |
187 return root_path.Append(kFileSystemDirectory); | |
188 } | |
189 | |
173 FileSystemPathManager::FileSystemPathManager( | 190 FileSystemPathManager::FileSystemPathManager( |
174 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 191 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
175 const FilePath& profile_path, | 192 const FilePath& profile_path, |
176 bool is_incognito, | 193 bool is_incognito, |
177 bool allow_file_access_from_files) | 194 bool allow_file_access_from_files) |
178 : file_message_loop_(file_message_loop), | 195 : file_message_loop_(file_message_loop), |
179 base_path_(profile_path.Append(kFileSystemDirectory)), | 196 base_path_(GetFileSystemCommonRootDirectory(profile_path)), |
180 is_incognito_(is_incognito), | 197 is_incognito_(is_incognito), |
181 allow_file_access_from_files_(allow_file_access_from_files) { | 198 allow_file_access_from_files_(allow_file_access_from_files) { |
182 } | 199 } |
183 | 200 |
184 FileSystemPathManager::~FileSystemPathManager() {} | 201 FileSystemPathManager::~FileSystemPathManager() {} |
185 | 202 |
186 void FileSystemPathManager::GetFileSystemRootPath( | 203 void FileSystemPathManager::GetFileSystemRootPath( |
187 const GURL& origin_url, fileapi::FileSystemType type, | 204 const GURL& origin_url, fileapi::FileSystemType type, |
188 bool create, GetRootPathCallback* callback_ptr) { | 205 bool create, GetRootPathCallback* callback_ptr) { |
189 scoped_ptr<GetRootPathCallback> callback(callback_ptr); | 206 scoped_ptr<GetRootPathCallback> callback(callback_ptr); |
(...skipping 18 matching lines...) Expand all Loading... | |
208 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); | 225 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); |
209 | 226 |
210 std::string type_string; | 227 std::string type_string; |
211 if (type == fileapi::kFileSystemTypeTemporary) | 228 if (type == fileapi::kFileSystemTypeTemporary) |
212 type_string = kTemporaryName; | 229 type_string = kTemporaryName; |
213 else if (type == fileapi::kFileSystemTypePersistent) | 230 else if (type == fileapi::kFileSystemTypePersistent) |
214 type_string = kPersistentName; | 231 type_string = kPersistentName; |
215 DCHECK(!type_string.empty()); | 232 DCHECK(!type_string.empty()); |
216 | 233 |
217 FilePath origin_base_path = base_path_.AppendASCII(storage_identifier) | 234 FilePath origin_base_path = base_path_.AppendASCII(storage_identifier) |
218 .AppendASCII(type_string); | 235 .AppendASCII(type_string); |
236 | |
219 std::string name = storage_identifier + ":" + type_string; | 237 std::string name = storage_identifier + ":" + type_string; |
220 | 238 |
221 scoped_refptr<GetFileSystemRootPathTask> task( | 239 scoped_refptr<GetFileSystemRootPathTask> task( |
222 new GetFileSystemRootPathTask(file_message_loop_, | 240 new GetFileSystemRootPathTask(file_message_loop_, |
223 name, callback.release())); | 241 name, callback.release())); |
224 task->Start(origin_url, origin_base_path, create); | 242 task->Start(origin_url, origin_base_path, create); |
225 } | 243 } |
226 | 244 |
227 bool FileSystemPathManager::CrackFileSystemPath( | 245 bool FileSystemPathManager::CrackFileSystemPath( |
228 const FilePath& path, GURL* origin_url, FileSystemType* type, | 246 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())); | 350 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); |
333 return web_security_origin.databaseIdentifier().utf8(); | 351 return web_security_origin.databaseIdentifier().utf8(); |
334 } | 352 } |
335 | 353 |
336 } // namespace fileapi | 354 } // namespace fileapi |
337 | 355 |
338 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ | 356 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ |
339 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); | 357 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); |
340 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ | 358 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ |
341 int(fileapi::kFileSystemTypePersistent), mismatching_enums); | 359 int(fileapi::kFileSystemTypePersistent), mismatching_enums); |
OLD | NEW |