diff options
author | erg <erg@chromium.org> | 2015-05-29 10:05:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-29 17:06:03 +0000 |
commit | 6c6729f63ec4fc5063009adb703c2563f08d0464 (patch) | |
tree | 085dbac85774aa7f64efb2a5b8875679bf4940bb /components/filesystem/file_system_impl.cc | |
parent | 3c65322f76409863f94490557b66bd10cbd25369 (diff) | |
download | chromium_src-6c6729f63ec4fc5063009adb703c2563f08d0464.zip chromium_src-6c6729f63ec4fc5063009adb703c2563f08d0464.tar.gz chromium_src-6c6729f63ec4fc5063009adb703c2563f08d0464.tar.bz2 |
mandoline filesystem: Rewrite using base::File.
The previous incomplete implementation of the file system targeted posix
semantics. While I'd still like to see a service that offered posix
semantics added to the filesystem application, for short term
cross-platform bring up, rewrite the implementation to targeting
base::File so Windows works.
BUG=490237
Review URL: https://codereview.chromium.org/1158253002
Cr-Commit-Position: refs/heads/master@{#331994}
Diffstat (limited to 'components/filesystem/file_system_impl.cc')
-rw-r--r-- | components/filesystem/file_system_impl.cc | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/components/filesystem/file_system_impl.cc b/components/filesystem/file_system_impl.cc index 1ce5d25..f33aea8 100644 --- a/components/filesystem/file_system_impl.cc +++ b/components/filesystem/file_system_impl.cc @@ -15,45 +15,15 @@ #include "base/files/scoped_temp_dir.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" -#include "base/posix/eintr_wrapper.h" #include "components/filesystem/directory_impl.h" +#include "mojo/application/public/cpp/application_connection.h" namespace filesystem { -namespace { - -base::ScopedFD CreateAndOpenTemporaryDirectory( - scoped_ptr<base::ScopedTempDir>* temp_dir) { - (*temp_dir).reset(new base::ScopedTempDir()); - CHECK((*temp_dir)->CreateUniqueTempDir()); - - base::ScopedFD temp_dir_fd(HANDLE_EINTR( - open((*temp_dir)->path().value().c_str(), O_RDONLY | O_DIRECTORY, 0))); - PCHECK(temp_dir_fd.is_valid()); - DVLOG(1) << "Made a temporary directory: " << (*temp_dir)->path().value(); - return temp_dir_fd.Pass(); -} - -#ifndef NDEBUG -base::ScopedFD OpenMojoDebugDirectory() { - const char* home_dir_name = getenv("HOME"); - if (!home_dir_name || !home_dir_name[0]) { - LOG(ERROR) << "HOME not set"; - return base::ScopedFD(); - } - base::FilePath mojo_debug_dir_name = - base::FilePath(home_dir_name).Append("MojoDebug"); - return base::ScopedFD(HANDLE_EINTR( - open(mojo_debug_dir_name.value().c_str(), O_RDONLY | O_DIRECTORY, 0))); -} -#endif - -} // namespace - FileSystemImpl::FileSystemImpl(mojo::ApplicationConnection* connection, mojo::InterfaceRequest<FileSystem> request) - : binding_(this, request.Pass()) { - // TODO(vtl): record other app's URL + : remote_application_url_(connection->GetRemoteApplicationURL()), + binding_(this, request.Pass()) { } FileSystemImpl::~FileSystemImpl() { @@ -62,33 +32,24 @@ FileSystemImpl::~FileSystemImpl() { void FileSystemImpl::OpenFileSystem(const mojo::String& file_system, mojo::InterfaceRequest<Directory> directory, const OpenFileSystemCallback& callback) { - base::ScopedFD dir_fd; // Set only if the |DirectoryImpl| will own a temporary directory. scoped_ptr<base::ScopedTempDir> temp_dir; - if (file_system.is_null()) { - // TODO(vtl): ScopedGeneric (hence ScopedFD) doesn't have an operator=! - dir_fd.reset(CreateAndOpenTemporaryDirectory(&temp_dir).release()); - DCHECK(temp_dir); - } else if (file_system.get() == std::string("debug")) { -#ifdef NDEBUG - LOG(WARNING) << "~/MojoDebug only available in Debug builds"; -#else - // TODO(vtl): ScopedGeneric (hence ScopedFD) doesn't have an operator=! - dir_fd.reset(OpenMojoDebugDirectory().release()); -#endif - if (!dir_fd.is_valid()) { - LOG(ERROR) << "~/MojoDebug unavailable"; - callback.Run(ERROR_UNAVAILABLE); - return; - } - } else { - LOG(ERROR) << "Unknown file system: " << file_system.get(); - callback.Run(ERROR_UNIMPLEMENTED); - return; + 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")) { + // TODO(erg): We should serve a persistent directory based on the + // subdirectory |remote_application_url_| of a profile directory. } - new DirectoryImpl(directory.Pass(), dir_fd.Pass(), temp_dir.Pass()); - callback.Run(ERROR_OK); + if (!path.empty()) { + new DirectoryImpl(directory.Pass(), path, temp_dir.Pass()); + callback.Run(ERROR_OK); + } else { + callback.Run(ERROR_FAILED); + } } } // namespace filesystem |