| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/filesystem/file_system_impl.h" | 5 #include "components/filesystem/file_system_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_file.h" | 12 #include "base/files/scoped_file.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "components/filesystem/directory_impl.h" | 17 #include "components/filesystem/directory_impl.h" |
| 18 #include "mojo/shell/public/cpp/connection.h" | 18 #include "mojo/shell/public/cpp/connection.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace filesystem { | 21 namespace filesystem { |
| 22 | 22 |
| 23 FileSystemImpl::FileSystemImpl(mojo::Connection* connection, | 23 FileSystemImpl::FileSystemImpl(mojo::Connection* connection, |
| 24 mojo::InterfaceRequest<FileSystem> request, | 24 mojo::InterfaceRequest<FileSystem> request, |
| 25 base::FilePath persistent_dir, | 25 const base::FilePath& persistent_dir, |
| 26 LockTable* lock_table) | 26 LockTable* lock_table) |
| 27 : remote_application_url_(connection->GetRemoteApplicationURL()), | 27 : remote_application_url_(connection->GetRemoteApplicationURL()), |
| 28 binding_(this, std::move(request)), | 28 binding_(this, std::move(request)), |
| 29 lock_table_(lock_table), | 29 lock_table_(lock_table), |
| 30 persistent_dir_(persistent_dir) {} | 30 persistent_dir_(persistent_dir) { |
| 31 } |
| 31 | 32 |
| 32 FileSystemImpl::~FileSystemImpl() { | 33 FileSystemImpl::~FileSystemImpl() {} |
| 33 } | |
| 34 | 34 |
| 35 void FileSystemImpl::OpenTempDirectory( | 35 void FileSystemImpl::OpenTempDirectory( |
| 36 mojo::InterfaceRequest<Directory> directory, | 36 mojo::InterfaceRequest<Directory> directory, |
| 37 const OpenTempDirectoryCallback& callback) { | 37 const OpenTempDirectoryCallback& callback) { |
| 38 // Set only if the |DirectoryImpl| will own a temporary directory. | 38 // Set only if the |DirectoryImpl| will own a temporary directory. |
| 39 scoped_ptr<base::ScopedTempDir> temp_dir(new base::ScopedTempDir); | 39 scoped_ptr<base::ScopedTempDir> temp_dir(new base::ScopedTempDir); |
| 40 CHECK(temp_dir->CreateUniqueTempDir()); | 40 CHECK(temp_dir->CreateUniqueTempDir()); |
| 41 | 41 |
| 42 base::FilePath path = temp_dir->path(); | 42 base::FilePath path = temp_dir->path(); |
| 43 new DirectoryImpl( | 43 new DirectoryImpl( |
| 44 std::move(directory), path, std::move(temp_dir), lock_table_); | 44 std::move(directory), path, std::move(temp_dir), lock_table_); |
| 45 callback.Run(FileError::OK); | 45 callback.Run(FileError::OK); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void FileSystemImpl::OpenPersistentFileSystem( | 48 void FileSystemImpl::OpenPersistentFileSystem( |
| 49 mojo::InterfaceRequest<Directory> directory, | 49 mojo::InterfaceRequest<Directory> directory, |
| 50 const OpenPersistentFileSystemCallback& callback) { | 50 const OpenPersistentFileSystemCallback& callback) { |
| 51 scoped_ptr<base::ScopedTempDir> temp_dir; | 51 scoped_ptr<base::ScopedTempDir> temp_dir; |
| 52 base::FilePath path = persistent_dir_; | 52 base::FilePath path = persistent_dir_; |
| 53 if (!base::PathExists(path)) | 53 if (!base::PathExists(path)) |
| 54 base::CreateDirectory(path); | 54 base::CreateDirectory(path); |
| 55 | 55 |
| 56 new DirectoryImpl( | 56 new DirectoryImpl( |
| 57 std::move(directory), path, std::move(temp_dir), lock_table_); | 57 std::move(directory), path, std::move(temp_dir), lock_table_); |
| 58 callback.Run(FileError::OK); | 58 callback.Run(FileError::OK); |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace filesystem | 61 } // namespace filesystem |
| OLD | NEW |