blob: fd0a24fd264fb436c7916cffcb1f1d6a222567dc [file] [log] [blame]
[email protected]b2582862013-05-14 08:50:181// 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
pilgrim4af8c212014-09-05 17:30:155#include "storage/browser/fileapi/transient_file_util.h"
[email protected]b2582862013-05-14 08:50:186
7#include <string>
8
9#include "base/bind.h"
10#include "base/files/file_path.h"
pilgrim4af8c212014-09-05 17:30:1511#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]b2582862013-05-14 08:50:1814
[email protected]cd501a72014-08-22 19:58:3115using storage::ScopedFile;
[email protected]b2582862013-05-14 08:50:1816
[email protected]cd501a72014-08-22 19:58:3117namespace storage {
[email protected]b2582862013-05-14 08:50:1818
19namespace {
20
21void RevokeFileSystem(const std::string& filesystem_id,
22 const base::FilePath& /*path*/) {
23 IsolatedContext::GetInstance()->RevokeFileSystem(filesystem_id);
24}
25
26} // namespace
27
28ScopedFile TransientFileUtil::CreateSnapshotFile(
29 FileSystemOperationContext* context,
30 const FileSystemURL& url,
[email protected]141bcc52014-01-27 21:36:0031 base::File::Error* error,
32 base::File::Info* file_info,
[email protected]b2582862013-05-14 08:50:1833 base::FilePath* platform_path) {
34 DCHECK(file_info);
35 *error = GetFileInfo(context, url, file_info, platform_path);
[email protected]141bcc52014-01-27 21:36:0036 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]b2582862013-05-14 08:50:1839 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(
tzika152062b2018-08-09 09:00:1450 base::BindOnce(&RevokeFileSystem, url.filesystem_id()), nullptr);
[email protected]b2582862013-05-14 08:50:1851
dchengdae49252015-12-27 23:23:1652 return scoped_file;
[email protected]b2582862013-05-14 08:50:1853}
54
[email protected]cd501a72014-08-22 19:58:3155} // namespace storage