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