Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_manager / fileapi_util.h
blob8adbd0996ba07bc218882eff258919af27cc282c
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.
4 //
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_
10 #include <string>
12 #include "base/callback_forward.h"
13 #include "base/files/file.h"
14 #include "base/files/file_path.h"
15 #include "url/gurl.h"
17 class Profile;
19 namespace content {
20 class RenderViewHost;
23 namespace fileapi {
24 class FileSystemContext;
27 namespace file_manager {
28 namespace util {
30 // Structure information necessary to create a EntryDefinition, and therefore
31 // an Entry object on the JavaScript side.
32 struct FileDefinition {
33 base::FilePath virtual_path;
34 base::FilePath absolute_path;
35 bool is_directory;
38 // Contains all information needed to create an Entry object in custom bindings.
39 struct EntryDefinition {
40 EntryDefinition();
41 ~EntryDefinition();
43 std::string file_system_root_url; // Used to create DOMFileSystem.
44 std::string file_system_name; // Value of DOMFileSystem.name.
45 base::FilePath full_path; // Value of Entry.fullPath.
46 bool is_directory; // Whether to create FileEntry or DirectoryEntry.
47 base::File::Error error;
50 typedef std::vector<FileDefinition> FileDefinitionList;
51 typedef std::vector<EntryDefinition> EntryDefinitionList;
53 // The callback used by ConvertFileDefinitionToEntryDefinition. Returns the
54 // result of the conversion.
55 typedef base::Callback<void(const EntryDefinition& entry_definition)>
56 EntryDefinitionCallback;
58 // The callback used by ConvertFileDefinitionListToEntryDefinitionList. Returns
59 // the result of the conversion as a list.
60 typedef base::Callback<void(scoped_ptr<
61 EntryDefinitionList> entry_definition_list)> EntryDefinitionListCallback;
63 // Returns a file system context associated with the given profile and the
64 // extension ID.
65 fileapi::FileSystemContext* GetFileSystemContextForExtensionId(
66 Profile* profile,
67 const std::string& extension_id);
69 // Returns a file system context associated with the given profile and the
70 // render view host.
71 fileapi::FileSystemContext* GetFileSystemContextForRenderViewHost(
72 Profile* profile,
73 content::RenderViewHost* render_view_host);
75 // Converts DrivePath (e.g., "drive/root", which always starts with the fixed
76 // "drive" directory) to a RelativeFileSystemPathrelative (e.g.,
77 // "drive-xxx/root/foo". which starts from the "mount point" in the FileSystem
78 // API that may be distinguished for each profile by the appended "xxx" part.)
79 base::FilePath ConvertDrivePathToRelativeFileSystemPath(
80 Profile* profile,
81 const std::string& extension_id,
82 const base::FilePath& drive_path);
84 // Converts DrivePath to FileSystem URL.
85 // E.g., "drive/root" to filesystem://id/external/drive-xxx/root.
86 GURL ConvertDrivePathToFileSystemUrl(Profile* profile,
87 const base::FilePath& drive_path,
88 const std::string& extension_id);
90 // Converts AbsolutePath (e.g., "/special/drive-xxx/root" or
91 // "/home/chronos/u-xxx/Downloads") into filesystem URL. Returns false
92 // if |absolute_path| is not managed by the external filesystem provider.
93 bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile,
94 const base::FilePath& absolute_path,
95 const std::string& extension_id,
96 GURL* url);
98 // Converts AbsolutePath into RelativeFileSystemPath (e.g.,
99 // "/special/drive-xxx/root/foo" => "drive-xxx/root/foo".) Returns false if
100 // |absolute_path| is not managed by the external filesystem provider.
101 bool ConvertAbsoluteFilePathToRelativeFileSystemPath(
102 Profile* profile,
103 const std::string& extension_id,
104 const base::FilePath& absolute_path,
105 base::FilePath* relative_path);
107 // Converts a file definition to a entry definition and returns the result
108 // via a callback. |profile| cannot be null. Must be called on UI thread.
109 void ConvertFileDefinitionToEntryDefinition(
110 Profile* profile,
111 const std::string& extension_id,
112 const FileDefinition& file_definition,
113 const EntryDefinitionCallback& callback);
115 // Converts a list of file definitions into a list of entry definitions and
116 // returns it via |callback|. The method is safe, |file_definition_list| is
117 // copied internally. The output list has the same order of items and size as
118 // the input vector. |profile| cannot be null. Must be called on UI thread.
119 void ConvertFileDefinitionListToEntryDefinitionList(
120 Profile* profile,
121 const std::string& extension_id,
122 const FileDefinitionList& file_definition_list,
123 const EntryDefinitionListCallback& callback);
125 } // namespace util
126 } // namespace file_manager
128 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_