| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/file/file_system.h" | 5 #include "services/file/file_system.h" |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/filesystem/directory_impl.h" | 12 #include "components/filesystem/directory_impl.h" |
| 13 #include "components/filesystem/lock_table.h" | 13 #include "components/filesystem/lock_table.h" |
| 14 #include "components/filesystem/public/interfaces/types.mojom.h" | 14 #include "components/filesystem/public/interfaces/types.mojom.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 #include "services/shell/public/cpp/connection.h" | 16 #include "services/shell/public/cpp/connection.h" |
| 16 | 17 |
| 17 namespace file { | 18 namespace file { |
| 18 | 19 |
| 19 FileSystem::FileSystem(const base::FilePath& base_user_dir, | 20 FileSystem::FileSystem(const base::FilePath& base_user_dir, |
| 20 const scoped_refptr<filesystem::LockTable>& lock_table) | 21 const scoped_refptr<filesystem::LockTable>& lock_table) |
| 21 : lock_table_(lock_table), path_(base_user_dir) { | 22 : lock_table_(lock_table), path_(base_user_dir) { |
| 22 base::CreateDirectory(path_); | 23 base::CreateDirectory(path_); |
| 23 } | 24 } |
| 24 | 25 |
| 25 FileSystem::~FileSystem() {} | 26 FileSystem::~FileSystem() {} |
| 26 | 27 |
| 27 void FileSystem::GetDirectory(filesystem::mojom::DirectoryRequest request, | 28 void FileSystem::GetDirectory(filesystem::mojom::DirectoryRequest request, |
| 28 const GetDirectoryCallback& callback) { | 29 const GetDirectoryCallback& callback) { |
| 29 new filesystem::DirectoryImpl(std::move(request), path_, | 30 mojo::MakeStrongBinding( |
| 30 scoped_refptr<filesystem::SharedTempDir>(), | 31 base::MakeUnique<filesystem::DirectoryImpl>( |
| 31 lock_table_); | 32 path_, scoped_refptr<filesystem::SharedTempDir>(), lock_table_), |
| 33 std::move(request)); |
| 32 callback.Run(); | 34 callback.Run(); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void FileSystem::GetSubDirectory(const std::string& sub_directory_path, | 37 void FileSystem::GetSubDirectory(const std::string& sub_directory_path, |
| 36 filesystem::mojom::DirectoryRequest request, | 38 filesystem::mojom::DirectoryRequest request, |
| 37 const GetSubDirectoryCallback& callback) { | 39 const GetSubDirectoryCallback& callback) { |
| 38 // Ensure that we've made |subdirectory| recursively under our user dir. | 40 // Ensure that we've made |subdirectory| recursively under our user dir. |
| 39 base::FilePath subdir = path_.Append( | 41 base::FilePath subdir = path_.Append( |
| 40 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 41 base::UTF8ToWide(sub_directory_path)); | 43 base::UTF8ToWide(sub_directory_path)); |
| 42 #else | 44 #else |
| 43 sub_directory_path); | 45 sub_directory_path); |
| 44 #endif | 46 #endif |
| 45 base::File::Error error; | 47 base::File::Error error; |
| 46 if (!base::CreateDirectoryAndGetError(subdir, &error)) { | 48 if (!base::CreateDirectoryAndGetError(subdir, &error)) { |
| 47 callback.Run(static_cast<filesystem::mojom::FileError>(error)); | 49 callback.Run(static_cast<filesystem::mojom::FileError>(error)); |
| 48 return; | 50 return; |
| 49 } | 51 } |
| 50 | 52 |
| 51 new filesystem::DirectoryImpl(std::move(request), subdir, | 53 mojo::MakeStrongBinding( |
| 52 scoped_refptr<filesystem::SharedTempDir>(), | 54 base::MakeUnique<filesystem::DirectoryImpl>( |
| 53 lock_table_); | 55 subdir, scoped_refptr<filesystem::SharedTempDir>(), lock_table_), |
| 56 std::move(request)); |
| 54 callback.Run(filesystem::mojom::FileError::OK); | 57 callback.Run(filesystem::mojom::FileError::OK); |
| 55 } | 58 } |
| 56 | 59 |
| 57 } // namespace file | 60 } // namespace file |
| OLD | NEW |