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/file_manager/fileapi_util.h" | 5 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 9 #include "chrome/browser/chromeos/drive/file_system_util.h" |
10 #include "chrome/browser/chromeos/file_manager/app_id.h" | 10 #include "chrome/browser/chromeos/file_manager/app_id.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 scoped_refptr<storage::FileSystemContext> file_system_context, | 222 scoped_refptr<storage::FileSystemContext> file_system_context, |
223 const GURL& url, | 223 const GURL& url, |
224 const storage::FileSystemOperationRunner::StatusCallback& callback) { | 224 const storage::FileSystemOperationRunner::StatusCallback& callback) { |
225 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 225 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
226 | 226 |
227 storage::FileSystemURL file_system_url = file_system_context->CrackURL(url); | 227 storage::FileSystemURL file_system_url = file_system_context->CrackURL(url); |
228 file_system_context->operation_runner()->DirectoryExists( | 228 file_system_context->operation_runner()->DirectoryExists( |
229 file_system_url, callback); | 229 file_system_url, callback); |
230 } | 230 } |
231 | 231 |
| 232 // Used by GetMetadataForPath |
| 233 void GetMetadataOnIOThread( |
| 234 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 235 const GURL& url, |
| 236 const storage::FileSystemOperationRunner::GetMetadataCallback& callback) { |
| 237 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 238 storage::FileSystemURL file_system_url = file_system_context->CrackURL(url); |
| 239 file_system_context->operation_runner()->GetMetadata(file_system_url, |
| 240 callback); |
| 241 } |
| 242 |
232 // Checks if the |file_path| points non-native location or not. | 243 // Checks if the |file_path| points non-native location or not. |
233 bool IsUnderNonNativeLocalPath(const storage::FileSystemContext& context, | 244 bool IsUnderNonNativeLocalPath(const storage::FileSystemContext& context, |
234 const base::FilePath& file_path) { | 245 const base::FilePath& file_path) { |
235 base::FilePath virtual_path; | 246 base::FilePath virtual_path; |
236 if (!context.external_backend()->GetVirtualPath(file_path, &virtual_path)) | 247 if (!context.external_backend()->GetVirtualPath(file_path, &virtual_path)) |
237 return false; | 248 return false; |
238 | 249 |
239 const storage::FileSystemURL url = context.CreateCrackedFileSystemURL( | 250 const storage::FileSystemURL url = context.CreateCrackedFileSystemURL( |
240 GURL(), storage::kFileSystemTypeExternal, virtual_path); | 251 GURL(), storage::kFileSystemTypeExternal, virtual_path); |
241 if (!url.is_valid()) | 252 if (!url.is_valid()) |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 561 |
551 // Check the existence of directory using file system API implementation on | 562 // Check the existence of directory using file system API implementation on |
552 // behalf of the file manager app. We need to grant access beforehand. | 563 // behalf of the file manager app. We need to grant access beforehand. |
553 storage::ExternalFileSystemBackend* backend = | 564 storage::ExternalFileSystemBackend* backend = |
554 file_system_context->external_backend(); | 565 file_system_context->external_backend(); |
555 DCHECK(backend); | 566 DCHECK(backend); |
556 backend->GrantFullAccessToExtension(kFileManagerAppId); | 567 backend->GrantFullAccessToExtension(kFileManagerAppId); |
557 | 568 |
558 BrowserThread::PostTask( | 569 BrowserThread::PostTask( |
559 BrowserThread::IO, FROM_HERE, | 570 BrowserThread::IO, FROM_HERE, |
560 base::Bind(&CheckIfDirectoryExistsOnIOThread, | 571 base::Bind(&CheckIfDirectoryExistsOnIOThread, file_system_context, url, |
561 file_system_context, | |
562 url, | |
563 google_apis::CreateRelayCallback(callback))); | 572 google_apis::CreateRelayCallback(callback))); |
564 } | 573 } |
565 | 574 |
| 575 void GetMetadataForPath( |
| 576 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 577 const GURL& url, |
| 578 const storage::FileSystemOperationRunner::GetMetadataCallback& callback) { |
| 579 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 580 |
| 581 // Check the existence of directory using file system API implementation on |
| 582 // behalf of the file manager app. We need to grant access beforehand. |
| 583 storage::ExternalFileSystemBackend* backend = |
| 584 file_system_context->external_backend(); |
| 585 DCHECK(backend); |
| 586 backend->GrantFullAccessToExtension(kFileManagerAppId); |
| 587 |
| 588 BrowserThread::PostTask( |
| 589 BrowserThread::IO, FROM_HERE, |
| 590 base::Bind(&GetMetadataOnIOThread, file_system_context, url, |
| 591 google_apis::CreateRelayCallback(callback))); |
| 592 } |
| 593 |
566 storage::FileSystemURL CreateIsolatedURLFromVirtualPath( | 594 storage::FileSystemURL CreateIsolatedURLFromVirtualPath( |
567 const storage::FileSystemContext& context, | 595 const storage::FileSystemContext& context, |
568 const GURL& origin, | 596 const GURL& origin, |
569 const base::FilePath& virtual_path) { | 597 const base::FilePath& virtual_path) { |
570 const storage::FileSystemURL original_url = | 598 const storage::FileSystemURL original_url = |
571 context.CreateCrackedFileSystemURL( | 599 context.CreateCrackedFileSystemURL( |
572 origin, storage::kFileSystemTypeExternal, virtual_path); | 600 origin, storage::kFileSystemTypeExternal, virtual_path); |
573 | 601 |
574 std::string register_name; | 602 std::string register_name; |
575 const std::string isolated_file_system_id = | 603 const std::string isolated_file_system_id = |
576 storage::IsolatedContext::GetInstance()->RegisterFileSystemForPath( | 604 storage::IsolatedContext::GetInstance()->RegisterFileSystemForPath( |
577 original_url.type(), | 605 original_url.type(), |
578 original_url.filesystem_id(), | 606 original_url.filesystem_id(), |
579 original_url.path(), | 607 original_url.path(), |
580 ®ister_name); | 608 ®ister_name); |
581 const storage::FileSystemURL isolated_url = | 609 const storage::FileSystemURL isolated_url = |
582 context.CreateCrackedFileSystemURL( | 610 context.CreateCrackedFileSystemURL( |
583 origin, | 611 origin, |
584 storage::kFileSystemTypeIsolated, | 612 storage::kFileSystemTypeIsolated, |
585 base::FilePath(isolated_file_system_id).Append(register_name)); | 613 base::FilePath(isolated_file_system_id).Append(register_name)); |
586 return isolated_url; | 614 return isolated_url; |
587 } | 615 } |
588 | 616 |
589 } // namespace util | 617 } // namespace util |
590 } // namespace file_manager | 618 } // namespace file_manager |
OLD | NEW |