[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 5 | #include "storage/browser/fileapi/transient_file_util.h" |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include "base/bind.h" |
| 10 | #include "base/files/file_path.h" |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 11 | #include "storage/browser/fileapi/file_system_operation_context.h" |
| 12 | #include "storage/browser/fileapi/file_system_url.h" |
| 13 | #include "storage/browser/fileapi/isolated_context.h" |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 14 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 15 | using storage::ScopedFile; |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 16 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 17 | namespace storage { |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 18 | |
| 19 | namespace { |
| 20 | |
| 21 | void RevokeFileSystem(const std::string& filesystem_id, |
| 22 | const base::FilePath& /*path*/) { |
| 23 | IsolatedContext::GetInstance()->RevokeFileSystem(filesystem_id); |
| 24 | } |
| 25 | |
| 26 | } // namespace |
| 27 | |
| 28 | ScopedFile TransientFileUtil::CreateSnapshotFile( |
| 29 | FileSystemOperationContext* context, |
| 30 | const FileSystemURL& url, |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 31 | base::File::Error* error, |
| 32 | base::File::Info* file_info, |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 33 | base::FilePath* platform_path) { |
| 34 | DCHECK(file_info); |
| 35 | *error = GetFileInfo(context, url, file_info, platform_path); |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 36 | if (*error == base::File::FILE_OK && file_info->is_directory) |
| 37 | *error = base::File::FILE_ERROR_NOT_A_FILE; |
| 38 | if (*error != base::File::FILE_OK) |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 39 | return ScopedFile(); |
| 40 | |
| 41 | // Sets-up a transient filesystem. |
| 42 | DCHECK(!platform_path->empty()); |
| 43 | DCHECK(!url.filesystem_id().empty()); |
| 44 | |
| 45 | ScopedFile scoped_file( |
| 46 | *platform_path, |
| 47 | ScopedFile::DELETE_ON_SCOPE_OUT, |
| 48 | context->task_runner()); |
| 49 | scoped_file.AddScopeOutCallback( |
tzik | a152062b | 2018-08-09 09:00:14 | [diff] [blame] | 50 | base::BindOnce(&RevokeFileSystem, url.filesystem_id()), nullptr); |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 51 | |
dcheng | dae4925 | 2015-12-27 23:23:16 | [diff] [blame] | 52 | return scoped_file; |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 53 | } |
| 54 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 55 | } // namespace storage |