| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_context.h" | 5 #include "webkit/fileapi/file_system_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 11 #include "webkit/fileapi/file_system_file_util.h" | 12 #include "webkit/fileapi/file_system_file_util.h" |
| 12 #include "webkit/fileapi/file_system_operation_interface.h" | 13 #include "webkit/fileapi/file_system_operation_interface.h" |
| 13 #include "webkit/fileapi/file_system_options.h" | 14 #include "webkit/fileapi/file_system_options.h" |
| 14 #include "webkit/fileapi/file_system_quota_client.h" | 15 #include "webkit/fileapi/file_system_quota_client.h" |
| 15 #include "webkit/fileapi/file_system_util.h" | 16 #include "webkit/fileapi/file_system_util.h" |
| 16 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 17 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 17 #include "webkit/quota/quota_manager.h" | 18 #include "webkit/quota/quota_manager.h" |
| 18 #include "webkit/quota/special_storage_policy.h" | 19 #include "webkit/quota/special_storage_policy.h" |
| 19 | 20 |
| 20 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
| 21 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 22 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 using quota::QuotaClient; | 25 using quota::QuotaClient; |
| 25 | 26 |
| 26 namespace fileapi { | 27 namespace fileapi { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 QuotaClient* CreateQuotaClient( | 31 QuotaClient* CreateQuotaClient( |
| 31 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 32 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 32 FileSystemContext* context, | 33 FileSystemContext* context, |
| 33 bool is_incognito) { | 34 bool is_incognito) { |
| 34 return new FileSystemQuotaClient(file_message_loop, context, is_incognito); | 35 return new FileSystemQuotaClient(file_message_loop, context, is_incognito); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void DidOpenFileSystem(FileSystemContext::OpenFileSystemCallback callback, | 38 void DidOpenFileSystem(scoped_ptr<FileSystemCallbackDispatcher> dispatcher, |
| 38 const GURL& filesystem_root, | 39 const GURL& filesystem_root, |
| 39 const std::string& filesystem_name, | 40 const std::string& filesystem_name, |
| 40 base::PlatformFileError error) { | 41 base::PlatformFileError error) { |
| 41 callback.Run(error, filesystem_name, filesystem_root); | 42 if (error == base::PLATFORM_FILE_OK) { |
| 43 dispatcher->DidOpenFileSystem(filesystem_name, filesystem_root); |
| 44 } else { |
| 45 dispatcher->DidFail(error); |
| 46 } |
| 42 } | 47 } |
| 43 | 48 |
| 44 } // anonymous namespace | 49 } // anonymous namespace |
| 45 | 50 |
| 46 FileSystemContext::FileSystemContext( | 51 FileSystemContext::FileSystemContext( |
| 47 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 52 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 48 scoped_refptr<base::MessageLoopProxy> io_message_loop, | 53 scoped_refptr<base::MessageLoopProxy> io_message_loop, |
| 49 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 54 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 50 quota::QuotaManagerProxy* quota_manager_proxy, | 55 quota::QuotaManagerProxy* quota_manager_proxy, |
| 51 const FilePath& profile_path, | 56 const FilePath& profile_path, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 io_message_loop_->DeleteSoon(FROM_HERE, this); | 150 io_message_loop_->DeleteSoon(FROM_HERE, this); |
| 146 return; | 151 return; |
| 147 } | 152 } |
| 148 delete this; | 153 delete this; |
| 149 } | 154 } |
| 150 | 155 |
| 151 void FileSystemContext::OpenFileSystem( | 156 void FileSystemContext::OpenFileSystem( |
| 152 const GURL& origin_url, | 157 const GURL& origin_url, |
| 153 FileSystemType type, | 158 FileSystemType type, |
| 154 bool create, | 159 bool create, |
| 155 OpenFileSystemCallback callback) { | 160 scoped_ptr<FileSystemCallbackDispatcher> dispatcher) { |
| 156 DCHECK(!callback.is_null()); | 161 DCHECK(dispatcher.get()); |
| 157 | 162 |
| 158 FileSystemMountPointProvider* mount_point_provider = | 163 FileSystemMountPointProvider* mount_point_provider = |
| 159 GetMountPointProvider(type); | 164 GetMountPointProvider(type); |
| 160 if (!mount_point_provider) { | 165 if (!mount_point_provider) { |
| 161 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); | 166 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 162 return; | 167 return; |
| 163 } | 168 } |
| 164 | 169 |
| 165 GURL root_url = GetFileSystemRootURI(origin_url, type); | 170 GURL root_url = GetFileSystemRootURI(origin_url, type); |
| 166 std::string name = GetFileSystemName(origin_url, type); | 171 std::string name = GetFileSystemName(origin_url, type); |
| 167 | 172 |
| 168 mount_point_provider->ValidateFileSystemRoot( | 173 mount_point_provider->ValidateFileSystemRoot( |
| 169 origin_url, type, create, | 174 origin_url, type, create, |
| 170 base::Bind(&DidOpenFileSystem, callback, root_url, name)); | 175 base::Bind(&DidOpenFileSystem, |
| 176 base::Passed(&dispatcher), root_url, name)); |
| 171 } | 177 } |
| 172 | 178 |
| 173 FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation( | 179 FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation( |
| 174 const GURL& url, | 180 const GURL& url, |
| 181 scoped_ptr<FileSystemCallbackDispatcher> dispatcher, |
| 175 base::MessageLoopProxy* file_proxy) { | 182 base::MessageLoopProxy* file_proxy) { |
| 176 GURL origin_url; | 183 GURL origin_url; |
| 177 FileSystemType file_system_type = kFileSystemTypeUnknown; | 184 FileSystemType file_system_type = kFileSystemTypeUnknown; |
| 178 FilePath file_path; | 185 FilePath file_path; |
| 179 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path)) | 186 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path)) |
| 180 return NULL; | 187 return NULL; |
| 181 FileSystemMountPointProvider* mount_point_provider = | 188 FileSystemMountPointProvider* mount_point_provider = |
| 182 GetMountPointProvider(file_system_type); | 189 GetMountPointProvider(file_system_type); |
| 183 if (!mount_point_provider) | 190 if (!mount_point_provider) |
| 184 return NULL; | 191 return NULL; |
| 185 return mount_point_provider->CreateFileSystemOperation( | 192 return mount_point_provider->CreateFileSystemOperation( |
| 186 origin_url, file_system_type, file_path, file_proxy, this); | 193 origin_url, file_system_type, file_path, |
| 194 dispatcher.Pass(), file_proxy, this); |
| 187 } | 195 } |
| 188 | 196 |
| 189 } // namespace fileapi | 197 } // namespace fileapi |
| OLD | NEW |