| Index: components/filesystem/file_system_impl.cc
|
| diff --git a/components/filesystem/file_system_impl.cc b/components/filesystem/file_system_impl.cc
|
| index cf444b38d2ffcc04456efd3bdb372194aaf57ddf..414bab14f85bd4806d87ffa4ad820c535b9de88b 100644
|
| --- a/components/filesystem/file_system_impl.cc
|
| +++ b/components/filesystem/file_system_impl.cc
|
| @@ -7,7 +7,6 @@
|
| #include <stddef.h>
|
| #include <utility>
|
|
|
| -#include "base/command_line.h"
|
| #include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| #include "base/files/scoped_file.h"
|
| @@ -19,142 +18,44 @@
|
| #include "mojo/shell/public/cpp/connection.h"
|
| #include "url/gurl.h"
|
|
|
| -#if defined(OS_WIN)
|
| -#include "base/base_paths_win.h"
|
| -#include "base/path_service.h"
|
| -#include "base/strings/utf_string_conversions.h"
|
| -#elif defined(OS_ANDROID)
|
| -#include "base/base_paths_android.h"
|
| -#include "base/path_service.h"
|
| -#elif defined(OS_LINUX)
|
| -#include "base/environment.h"
|
| -#include "base/nix/xdg_util.h"
|
| -#elif defined(OS_MACOSX)
|
| -#include "base/base_paths_mac.h"
|
| -#include "base/path_service.h"
|
| -#endif
|
| -
|
| namespace filesystem {
|
|
|
| -namespace {
|
| -
|
| -const char kEscapeChar = ',';
|
| -
|
| -const char kUserDataDir[] = "user-data-dir";
|
| -
|
| -} // namespace filesystem
|
| -
|
| FileSystemImpl::FileSystemImpl(mojo::Connection* connection,
|
| mojo::InterfaceRequest<FileSystem> request,
|
| + base::FilePath persistent_dir,
|
| LockTable* lock_table)
|
| : remote_application_url_(connection->GetRemoteApplicationURL()),
|
| binding_(this, std::move(request)),
|
| - lock_table_(lock_table) {}
|
| + lock_table_(lock_table),
|
| + persistent_dir_(persistent_dir) {}
|
|
|
| FileSystemImpl::~FileSystemImpl() {
|
| }
|
|
|
| -void FileSystemImpl::OpenFileSystem(const mojo::String& file_system,
|
| - mojo::InterfaceRequest<Directory> directory,
|
| - FileSystemClientPtr client,
|
| - const OpenFileSystemCallback& callback) {
|
| +void FileSystemImpl::OpenTempDirectory(
|
| + mojo::InterfaceRequest<Directory> directory,
|
| + const OpenTempDirectoryCallback& callback) {
|
| // Set only if the |DirectoryImpl| will own a temporary directory.
|
| - scoped_ptr<base::ScopedTempDir> temp_dir;
|
| - base::FilePath path;
|
| - if (file_system.get() == std::string("temp")) {
|
| - temp_dir.reset(new base::ScopedTempDir);
|
| - CHECK(temp_dir->CreateUniqueTempDir());
|
| - path = temp_dir->path();
|
| - } else if (file_system.get() == std::string("origin")) {
|
| - base::FilePath base_profile_dir = GetSystemProfileDir();
|
| + scoped_ptr<base::ScopedTempDir> temp_dir(new base::ScopedTempDir);
|
| + CHECK(temp_dir->CreateUniqueTempDir());
|
|
|
| - // Sanitize the url for disk access.
|
| - //
|
| - // TODO(erg): While it's currently impossible, we need to deal with http://
|
| - // URLs that have a path. (Or make the decision that these file systems are
|
| - // path bound, not origin bound.)
|
| - std::string sanitized_origin;
|
| - BuildSanitizedOrigin(remote_application_url_, &sanitized_origin);
|
| -
|
| -#if defined(OS_WIN)
|
| - path = base_profile_dir.Append(base::UTF8ToWide(sanitized_origin));
|
| -#else
|
| - path = base_profile_dir.Append(sanitized_origin);
|
| -#endif
|
| - if (!base::PathExists(path))
|
| - base::CreateDirectory(path);
|
| - }
|
| -
|
| - if (!path.empty()) {
|
| - new DirectoryImpl(
|
| - std::move(directory), path, std::move(temp_dir), lock_table_);
|
| - callback.Run(FileError::OK);
|
| - } else {
|
| - callback.Run(FileError::FAILED);
|
| - }
|
| + base::FilePath path = temp_dir->path();
|
| + new DirectoryImpl(
|
| + std::move(directory), path, std::move(temp_dir), lock_table_);
|
| + callback.Run(FileError::OK);
|
| }
|
|
|
| -base::FilePath FileSystemImpl::GetSystemProfileDir() const {
|
| - base::FilePath path;
|
| -
|
| - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
| - if (command_line->HasSwitch(kUserDataDir)) {
|
| - path = command_line->GetSwitchValuePath(kUserDataDir);
|
| - } else {
|
| -#if defined(OS_WIN)
|
| - CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path));
|
| - path = path.Append(FILE_PATH_LITERAL("mandoline"));
|
| -#elif defined(OS_LINUX)
|
| - scoped_ptr<base::Environment> env(base::Environment::Create());
|
| - base::FilePath config_dir(
|
| - base::nix::GetXDGDirectory(env.get(),
|
| - base::nix::kXdgConfigHomeEnvVar,
|
| - base::nix::kDotConfigDir));
|
| - path = config_dir.Append("mandoline");
|
| -#elif defined(OS_MACOSX)
|
| - CHECK(PathService::Get(base::DIR_APP_DATA, &path));
|
| - path = path.Append("Mandoline Shell");
|
| -#elif defined(OS_ANDROID)
|
| - CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path));
|
| - path = path.Append(FILE_PATH_LITERAL("mandoline"));
|
| -#else
|
| - NOTIMPLEMENTED();
|
| -#endif
|
| - }
|
| -
|
| +void FileSystemImpl::OpenPersistentFileSystem(
|
| + mojo::InterfaceRequest<Directory> directory,
|
| + const OpenPersistentFileSystemCallback& callback) {
|
| + scoped_ptr<base::ScopedTempDir> temp_dir;
|
| + base::FilePath path = persistent_dir_;
|
| if (!base::PathExists(path))
|
| base::CreateDirectory(path);
|
|
|
| - return path;
|
| -}
|
| -
|
| -void FileSystemImpl::BuildSanitizedOrigin(
|
| - const std::string& origin,
|
| - std::string* sanitized_origin) {
|
| - // We take the origin string, and encode it in a way safe for filesystem
|
| - // access. This is vaguely based on //net/tools/dump_cache/
|
| - // url_to_filename_encoder.h; that file strips out schemes, and does weird
|
| - // things with subdirectories. We do follow the basic algorithm used there,
|
| - // including using ',' as our escape character.
|
| - for (size_t i = 0; i < origin.length(); ++i) {
|
| - unsigned char ch = origin[i];
|
| - char encoded[3];
|
| - int encoded_len;
|
| - if ((ch == '_') || (ch == '.') || (ch == '=') || (ch == '+') ||
|
| - (ch == '-') || (('0' <= ch) && (ch <= '9')) ||
|
| - (('A' <= ch) && (ch <= 'Z')) || (('a' <= ch) && (ch <= 'z'))) {
|
| - encoded[0] = ch;
|
| - encoded_len = 1;
|
| - } else {
|
| - encoded[0] = kEscapeChar;
|
| - encoded[1] = ch / 16;
|
| - encoded[1] += (encoded[1] >= 10) ? 'A' - 10 : '0';
|
| - encoded[2] = ch % 16;
|
| - encoded[2] += (encoded[2] >= 10) ? 'A' - 10 : '0';
|
| - encoded_len = 3;
|
| - }
|
| - sanitized_origin->append(encoded, encoded_len);
|
| - }
|
| + new DirectoryImpl(
|
| + std::move(directory), path, std::move(temp_dir), lock_table_);
|
| + callback.Run(FileError::OK);
|
| }
|
|
|
| } // namespace filesystem
|
|
|