| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste
      m.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste
      m.h" | 
| 6 | 6 | 
| 7 #include <sys/statvfs.h> | 7 #include <sys/statvfs.h> | 
| 8 #include <set> | 8 #include <set> | 
| 9 | 9 | 
| 10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" | 
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 233     const storage::FileSystemOperation::GetMetadataCallback& callback, | 233     const storage::FileSystemOperation::GetMetadataCallback& callback, | 
| 234     base::File::Error result, | 234     base::File::Error result, | 
| 235     const base::File::Info& file_info) { | 235     const base::File::Info& file_info) { | 
| 236   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 236   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 237   BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 237   BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 
| 238                           base::Bind(callback, result, file_info)); | 238                           base::Bind(callback, result, file_info)); | 
| 239 } | 239 } | 
| 240 | 240 | 
| 241 }  // namespace | 241 }  // namespace | 
| 242 | 242 | 
| 243 void FileManagerPrivateRequestFileSystemFunction::DidFail( |  | 
| 244     base::File::Error error_code) { |  | 
| 245   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  | 
| 246 |  | 
| 247   SetError(base::StringPrintf("File error %d", static_cast<int>(error_code))); |  | 
| 248   SendResponse(false); |  | 
| 249 } |  | 
| 250 |  | 
| 251 bool FileManagerPrivateRequestFileSystemFunction:: |  | 
| 252     SetupFileSystemAccessPermissions( |  | 
| 253         scoped_refptr<storage::FileSystemContext> file_system_context, |  | 
| 254         int child_id, |  | 
| 255         Profile* profile, |  | 
| 256         scoped_refptr<const extensions::Extension> extension, |  | 
| 257         const base::FilePath& mount_path, |  | 
| 258         const base::FilePath& virtual_path) { |  | 
| 259   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  | 
| 260 |  | 
| 261   if (!extension.get()) |  | 
| 262     return false; |  | 
| 263 |  | 
| 264   storage::ExternalFileSystemBackend* const backend = |  | 
| 265       file_system_context->external_backend(); |  | 
| 266   if (!backend) |  | 
| 267     return false; |  | 
| 268 |  | 
| 269   backend->GrantFileAccessToExtension(extension_->id(), virtual_path); |  | 
| 270 |  | 
| 271   // Grant R/W file permissions to the renderer hosting component |  | 
| 272   // extension to the mount path of the volume. |  | 
| 273   ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile( |  | 
| 274       child_id, mount_path); |  | 
| 275 |  | 
| 276   return true; |  | 
| 277 } |  | 
| 278 |  | 
| 279 bool FileManagerPrivateRequestFileSystemFunction::RunAsync() { |  | 
| 280   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  | 
| 281   using extensions::api::file_manager_private::RequestFileSystem::Params; |  | 
| 282   const scoped_ptr<Params> params(Params::Create(*args_)); |  | 
| 283   EXTENSION_FUNCTION_VALIDATE(params); |  | 
| 284 |  | 
| 285   if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess()) |  | 
| 286     return false; |  | 
| 287 |  | 
| 288   set_log_on_completion(true); |  | 
| 289 |  | 
| 290   using file_manager::VolumeManager; |  | 
| 291   using file_manager::VolumeInfo; |  | 
| 292   VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); |  | 
| 293   if (!volume_manager) |  | 
| 294     return false; |  | 
| 295 |  | 
| 296   VolumeInfo volume_info; |  | 
| 297   if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info)) { |  | 
| 298     DidFail(base::File::FILE_ERROR_NOT_FOUND); |  | 
| 299     return false; |  | 
| 300   } |  | 
| 301 |  | 
| 302   scoped_refptr<storage::FileSystemContext> file_system_context = |  | 
| 303       file_manager::util::GetFileSystemContextForRenderViewHost( |  | 
| 304           GetProfile(), render_view_host()); |  | 
| 305 |  | 
| 306   FileDefinition file_definition; |  | 
| 307   if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( |  | 
| 308            GetProfile(), |  | 
| 309            extension_id(), |  | 
| 310            volume_info.mount_path, |  | 
| 311            &file_definition.virtual_path)) { |  | 
| 312     DidFail(base::File::FILE_ERROR_INVALID_OPERATION); |  | 
| 313     return false; |  | 
| 314   } |  | 
| 315   file_definition.is_directory = true; |  | 
| 316 |  | 
| 317   // Set up file permission access. |  | 
| 318   const int child_id = render_view_host()->GetProcess()->GetID(); |  | 
| 319   if (!SetupFileSystemAccessPermissions( |  | 
| 320           file_system_context, child_id, GetProfile(), extension(), |  | 
| 321           volume_info.mount_path, file_definition.virtual_path)) { |  | 
| 322     DidFail(base::File::FILE_ERROR_SECURITY); |  | 
| 323     return false; |  | 
| 324   } |  | 
| 325 |  | 
| 326   file_manager::util::ConvertFileDefinitionToEntryDefinition( |  | 
| 327       GetProfile(), |  | 
| 328       extension_id(), |  | 
| 329       file_definition, |  | 
| 330       base::Bind( |  | 
| 331           &FileManagerPrivateRequestFileSystemFunction::OnEntryDefinition, |  | 
| 332           this)); |  | 
| 333   return true; |  | 
| 334 } |  | 
| 335 |  | 
| 336 void FileManagerPrivateRequestFileSystemFunction::OnEntryDefinition( |  | 
| 337     const EntryDefinition& entry_definition) { |  | 
| 338   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  | 
| 339 |  | 
| 340   if (entry_definition.error != base::File::FILE_OK) { |  | 
| 341     DidFail(entry_definition.error); |  | 
| 342     return; |  | 
| 343   } |  | 
| 344 |  | 
| 345   if (!entry_definition.is_directory) { |  | 
| 346     DidFail(base::File::FILE_ERROR_NOT_A_DIRECTORY); |  | 
| 347     return; |  | 
| 348   } |  | 
| 349 |  | 
| 350   base::DictionaryValue* dict = new base::DictionaryValue(); |  | 
| 351   SetResult(dict); |  | 
| 352   dict->SetString("name", entry_definition.file_system_name); |  | 
| 353   dict->SetString("root_url", entry_definition.file_system_root_url); |  | 
| 354   dict->SetInteger("error", drive::FILE_ERROR_OK); |  | 
| 355   SendResponse(true); |  | 
| 356 } |  | 
| 357 |  | 
| 358 ExtensionFunction::ResponseAction | 243 ExtensionFunction::ResponseAction | 
| 359 FileManagerPrivateEnableExternalFileSchemeFunction::Run() { | 244 FileManagerPrivateEnableExternalFileSchemeFunction::Run() { | 
| 360   ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 245   ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 
| 361       render_view_host()->GetProcess()->GetID(), content::kExternalFileScheme); | 246       render_view_host()->GetProcess()->GetID(), content::kExternalFileScheme); | 
| 362   return RespondNow(NoArguments()); | 247   return RespondNow(NoArguments()); | 
| 363 } | 248 } | 
| 364 | 249 | 
| 365 FileManagerPrivateGrantAccessFunction::FileManagerPrivateGrantAccessFunction() | 250 FileManagerPrivateGrantAccessFunction::FileManagerPrivateGrantAccessFunction() | 
| 366     : chrome_details_(this) { | 251     : chrome_details_(this) { | 
| 367 } | 252 } | 
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 791       file_manager::util::GetFileSystemContextForRenderViewHost( | 676       file_manager::util::GetFileSystemContextForRenderViewHost( | 
| 792           GetProfile(), render_view_host()); | 677           GetProfile(), render_view_host()); | 
| 793   DCHECK(file_system_context.get()); | 678   DCHECK(file_system_context.get()); | 
| 794 | 679 | 
| 795   const storage::ExternalFileSystemBackend* external_backend = | 680   const storage::ExternalFileSystemBackend* external_backend = | 
| 796       file_system_context->external_backend(); | 681       file_system_context->external_backend(); | 
| 797   DCHECK(external_backend); | 682   DCHECK(external_backend); | 
| 798 | 683 | 
| 799   file_manager::util::FileDefinitionList file_definition_list; | 684   file_manager::util::FileDefinitionList file_definition_list; | 
| 800   for (size_t i = 0; i < params->urls.size(); ++i) { | 685   for (size_t i = 0; i < params->urls.size(); ++i) { | 
| 801     FileSystemURL fileSystemUrl = | 686     const FileSystemURL file_system_url = | 
| 802         file_system_context->CrackURL(GURL(params->urls[i])); | 687         file_system_context->CrackURL(GURL(params->urls[i])); | 
| 803     DCHECK(external_backend->CanHandleType(fileSystemUrl.type())); | 688     DCHECK(external_backend->CanHandleType(file_system_url.type())); | 
| 804 |  | 
| 805     FileDefinition file_definition; | 689     FileDefinition file_definition; | 
| 806     const bool result = | 690     const bool result = | 
| 807         file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | 691         file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | 
| 808             GetProfile(), | 692             GetProfile(), extension_->id(), file_system_url.path(), | 
| 809             extension_->id(), |  | 
| 810             fileSystemUrl.path(), |  | 
| 811             &file_definition.virtual_path); | 693             &file_definition.virtual_path); | 
| 812     if (!result) | 694     if (!result) | 
| 813       continue; | 695       continue; | 
| 814     // The API only supports isolated files. | 696     // The API only supports isolated files. It still works for directories, | 
|  | 697     // as the value is ignored for existing entries. | 
| 815     file_definition.is_directory = false; | 698     file_definition.is_directory = false; | 
| 816     file_definition_list.push_back(file_definition); | 699     file_definition_list.push_back(file_definition); | 
| 817   } | 700   } | 
| 818 | 701 | 
| 819   file_manager::util::ConvertFileDefinitionListToEntryDefinitionList( | 702   file_manager::util::ConvertFileDefinitionListToEntryDefinitionList( | 
| 820       GetProfile(), | 703       GetProfile(), | 
| 821       extension_->id(), | 704       extension_->id(), | 
| 822       file_definition_list,  // Safe, since copied internally. | 705       file_definition_list,  // Safe, since copied internally. | 
| 823       base::Bind( | 706       base::Bind( | 
| 824           &FileManagerPrivateInternalResolveIsolatedEntriesFunction:: | 707           &FileManagerPrivateInternalResolveIsolatedEntriesFunction:: | 
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1014   return RespondLater(); | 897   return RespondLater(); | 
| 1015 } | 898 } | 
| 1016 | 899 | 
| 1017 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted( | 900 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted( | 
| 1018     drive::FileError result) { | 901     drive::FileError result) { | 
| 1019   Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 902   Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 
| 1020                                          : Error("Failed to set a tag.")); | 903                                          : Error("Failed to set a tag.")); | 
| 1021 } | 904 } | 
| 1022 | 905 | 
| 1023 }  // namespace extensions | 906 }  // namespace extensions | 
| OLD | NEW | 
|---|