1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file provides File API related utilities.
#ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_
#define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_
#include <string>
#include "base/callback_forward.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "storage/browser/fileapi/file_system_operation_runner.h"
#include "url/gurl.h"
class Profile;
namespace content {
struct FileChooserFileInfo;
class RenderViewHost;
}
namespace storage {
class FileSystemContext;
}
namespace ui {
struct SelectedFileInfo;
}
namespace file_manager {
namespace util {
// Structure information necessary to create a EntryDefinition, and therefore
// an Entry object on the JavaScript side.
struct FileDefinition {
base::FilePath virtual_path;
base::FilePath absolute_path;
bool is_directory;
};
// Contains all information needed to create an Entry object in custom bindings.
struct EntryDefinition {
EntryDefinition();
~EntryDefinition();
std::string file_system_root_url; // Used to create DOMFileSystem.
std::string file_system_name; // Value of DOMFileSystem.name.
base::FilePath full_path; // Value of Entry.fullPath.
// Whether to create FileEntry or DirectoryEntry when the corresponding entry
// is not found.
bool is_directory;
base::File::Error error;
};
typedef std::vector<FileDefinition> FileDefinitionList;
typedef std::vector<EntryDefinition> EntryDefinitionList;
typedef std::vector<ui::SelectedFileInfo> SelectedFileInfoList;
typedef std::vector<content::FileChooserFileInfo> FileChooserFileInfoList;
// The callback used by ConvertFileDefinitionToEntryDefinition. Returns the
// result of the conversion.
typedef base::Callback<void(const EntryDefinition& entry_definition)>
EntryDefinitionCallback;
// The callback used by ConvertFileDefinitionListToEntryDefinitionList. Returns
// the result of the conversion as a list.
typedef base::Callback<void(scoped_ptr<
EntryDefinitionList> entry_definition_list)> EntryDefinitionListCallback;
// The callback used by
// ConvertFileSelectedInfoListToFileChooserFileInfoList. Returns the result of
// the conversion as a list.
typedef base::Callback<void(const FileChooserFileInfoList&)>
FileChooserFileInfoListCallback;
// Returns a file system context associated with the given profile and the
// extension ID.
storage::FileSystemContext* GetFileSystemContextForExtensionId(
Profile* profile,
const std::string& extension_id);
// Returns a file system context associated with the given profile and the
// render view host.
storage::FileSystemContext* GetFileSystemContextForRenderViewHost(
Profile* profile,
content::RenderViewHost* render_view_host);
// Converts DrivePath (e.g., "drive/root", which always starts with the fixed
// "drive" directory) to a RelativeFileSystemPathrelative (e.g.,
// "drive-xxx/root/foo". which starts from the "mount point" in the FileSystem
// API that may be distinguished for each profile by the appended "xxx" part.)
base::FilePath ConvertDrivePathToRelativeFileSystemPath(
Profile* profile,
const std::string& extension_id,
const base::FilePath& drive_path);
// Converts DrivePath to FileSystem URL.
// E.g., "drive/root" to filesystem://id/external/drive-xxx/root.
GURL ConvertDrivePathToFileSystemUrl(Profile* profile,
const base::FilePath& drive_path,
const std::string& extension_id);
// Converts AbsolutePath (e.g., "/special/drive-xxx/root" or
// "/home/chronos/u-xxx/Downloads") into filesystem URL. Returns false
// if |absolute_path| is not managed by the external filesystem provider.
bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile,
const base::FilePath& absolute_path,
const std::string& extension_id,
GURL* url);
// Converts AbsolutePath into RelativeFileSystemPath (e.g.,
// "/special/drive-xxx/root/foo" => "drive-xxx/root/foo".) Returns false if
// |absolute_path| is not managed by the external filesystem provider.
bool ConvertAbsoluteFilePathToRelativeFileSystemPath(
Profile* profile,
const std::string& extension_id,
const base::FilePath& absolute_path,
base::FilePath* relative_path);
// Converts a file definition to a entry definition and returns the result
// via a callback. |profile| cannot be null. Must be called on UI thread.
void ConvertFileDefinitionToEntryDefinition(
Profile* profile,
const std::string& extension_id,
const FileDefinition& file_definition,
const EntryDefinitionCallback& callback);
// Converts a list of file definitions into a list of entry definitions and
// returns it via |callback|. The method is safe, |file_definition_list| is
// copied internally. The output list has the same order of items and size as
// the input vector. |profile| cannot be null. Must be called on UI thread.
void ConvertFileDefinitionListToEntryDefinitionList(
Profile* profile,
const std::string& extension_id,
const FileDefinitionList& file_definition_list,
const EntryDefinitionListCallback& callback);
// Converts SelectedFileInfoList into FileChooserFileInfoList.
void ConvertSelectedFileInfoListToFileChooserFileInfoList(
storage::FileSystemContext* context,
const GURL& origin,
const SelectedFileInfoList& selected_info_list,
const FileChooserFileInfoListCallback& callback);
// Checks if a directory exists at |url|.
void CheckIfDirectoryExists(
scoped_refptr<storage::FileSystemContext> file_system_context,
const GURL& url,
const storage::FileSystemOperationRunner::StatusCallback& callback);
// Obtains isolated file system URL from |virtual_path| pointing a file in the
// external file system.
storage::FileSystemURL CreateIsolatedURLFromVirtualPath(
const storage::FileSystemContext& context,
const GURL& origin,
const base::FilePath& virtual_path);
} // namespace util
} // namespace file_manager
#endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_
|