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
3 // found in the LICENSE file.
5 // This file provides File API related utilities.
7 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_
8 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_
12 #include "base/callback_forward.h"
13 #include "base/files/file.h"
14 #include "base/files/file_path.h"
15 #include "storage/browser/fileapi/file_system_operation_runner.h"
25 class FileSystemContext;
28 namespace file_manager {
31 // Structure information necessary to create a EntryDefinition, and therefore
32 // an Entry object on the JavaScript side.
33 struct FileDefinition {
34 base::FilePath virtual_path;
35 base::FilePath absolute_path;
39 // Contains all information needed to create an Entry object in custom bindings.
40 struct EntryDefinition {
44 std::string file_system_root_url; // Used to create DOMFileSystem.
45 std::string file_system_name; // Value of DOMFileSystem.name.
46 base::FilePath full_path; // Value of Entry.fullPath.
47 // Whether to create FileEntry or DirectoryEntry when the corresponding entry
50 base::File::Error error;
53 typedef std::vector<FileDefinition> FileDefinitionList;
54 typedef std::vector<EntryDefinition> EntryDefinitionList;
56 // The callback used by ConvertFileDefinitionToEntryDefinition. Returns the
57 // result of the conversion.
58 typedef base::Callback<void(const EntryDefinition& entry_definition)>
59 EntryDefinitionCallback;
61 // The callback used by ConvertFileDefinitionListToEntryDefinitionList. Returns
62 // the result of the conversion as a list.
63 typedef base::Callback<void(scoped_ptr<
64 EntryDefinitionList> entry_definition_list)> EntryDefinitionListCallback;
66 // Returns a file system context associated with the given profile and the
68 storage::FileSystemContext* GetFileSystemContextForExtensionId(
70 const std::string& extension_id);
72 // Returns a file system context associated with the given profile and the
74 storage::FileSystemContext* GetFileSystemContextForRenderViewHost(
76 content::RenderViewHost* render_view_host);
78 // Converts DrivePath (e.g., "drive/root", which always starts with the fixed
79 // "drive" directory) to a RelativeFileSystemPathrelative (e.g.,
80 // "drive-xxx/root/foo". which starts from the "mount point" in the FileSystem
81 // API that may be distinguished for each profile by the appended "xxx" part.)
82 base::FilePath ConvertDrivePathToRelativeFileSystemPath(
84 const std::string& extension_id,
85 const base::FilePath& drive_path);
87 // Converts DrivePath to FileSystem URL.
88 // E.g., "drive/root" to filesystem://id/external/drive-xxx/root.
89 GURL ConvertDrivePathToFileSystemUrl(Profile* profile,
90 const base::FilePath& drive_path,
91 const std::string& extension_id);
93 // Converts AbsolutePath (e.g., "/special/drive-xxx/root" or
94 // "/home/chronos/u-xxx/Downloads") into filesystem URL. Returns false
95 // if |absolute_path| is not managed by the external filesystem provider.
96 bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile,
97 const base::FilePath& absolute_path,
98 const std::string& extension_id,
101 // Converts AbsolutePath into RelativeFileSystemPath (e.g.,
102 // "/special/drive-xxx/root/foo" => "drive-xxx/root/foo".) Returns false if
103 // |absolute_path| is not managed by the external filesystem provider.
104 bool ConvertAbsoluteFilePathToRelativeFileSystemPath(
106 const std::string& extension_id,
107 const base::FilePath& absolute_path,
108 base::FilePath* relative_path);
110 // Converts a file definition to a entry definition and returns the result
111 // via a callback. |profile| cannot be null. Must be called on UI thread.
112 void ConvertFileDefinitionToEntryDefinition(
114 const std::string& extension_id,
115 const FileDefinition& file_definition,
116 const EntryDefinitionCallback& callback);
118 // Converts a list of file definitions into a list of entry definitions and
119 // returns it via |callback|. The method is safe, |file_definition_list| is
120 // copied internally. The output list has the same order of items and size as
121 // the input vector. |profile| cannot be null. Must be called on UI thread.
122 void ConvertFileDefinitionListToEntryDefinitionList(
124 const std::string& extension_id,
125 const FileDefinitionList& file_definition_list,
126 const EntryDefinitionListCallback& callback);
128 // Checks if a directory exists at |url|.
129 void CheckIfDirectoryExists(
130 scoped_refptr<storage::FileSystemContext> file_system_context,
132 const storage::FileSystemOperationRunner::StatusCallback& callback);
135 } // namespace file_manager
137 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_