1 // Copyright 2015 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 #include "components/filesystem/file_system_impl.h"
7 #include "base/files/file_path.h"
8 #include "base/files/scoped_file.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/filesystem/directory_impl.h"
13 #include "mojo/application/public/cpp/application_connection.h"
15 namespace filesystem
{
17 FileSystemImpl::FileSystemImpl(mojo::ApplicationConnection
* connection
,
18 mojo::InterfaceRequest
<FileSystem
> request
)
19 : remote_application_url_(connection
->GetRemoteApplicationURL()),
20 binding_(this, request
.Pass()) {
23 FileSystemImpl::~FileSystemImpl() {
26 void FileSystemImpl::OpenFileSystem(const mojo::String
& file_system
,
27 mojo::InterfaceRequest
<Directory
> directory
,
28 const OpenFileSystemCallback
& callback
) {
29 // Set only if the |DirectoryImpl| will own a temporary directory.
30 scoped_ptr
<base::ScopedTempDir
> temp_dir
;
32 if (file_system
.get() == std::string("temp")) {
33 temp_dir
.reset(new base::ScopedTempDir
);
34 CHECK(temp_dir
->CreateUniqueTempDir());
35 path
= temp_dir
->path();
36 } else if (file_system
.get() == std::string("origin")) {
37 // TODO(erg): We should serve a persistent directory based on the
38 // subdirectory |remote_application_url_| of a profile directory.
42 new DirectoryImpl(directory
.Pass(), path
, temp_dir
.Pass());
43 callback
.Run(FILE_ERROR_OK
);
45 callback
.Run(FILE_ERROR_FAILED
);
49 } // namespace filesystem