Chromium Code Reviews| 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 "components/profile_service/profile_service_impl.h" | 5 #include "components/profile_service/profile_service_impl.h" |
| 6 | 6 |
| 7 #include "base/files/file.h" | |
| 7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "components/filesystem/directory_impl.h" | 12 #include "components/filesystem/directory_impl.h" |
| 11 #include "components/filesystem/lock_table.h" | 13 #include "components/filesystem/lock_table.h" |
| 14 #include "components/filesystem/public/interfaces/types.mojom.h" | |
| 12 #include "mojo/shell/public/cpp/connection.h" | 15 #include "mojo/shell/public/cpp/connection.h" |
| 16 #include "mojo/shell/public/cpp/message_loop_ref.h" | |
| 13 | 17 |
| 14 namespace profile { | 18 namespace profile { |
| 15 | 19 |
| 16 ProfileServiceImpl::ProfileServiceImpl( | 20 ProfileServiceImpl::ProfileServiceImpl( |
| 17 mojo::Connection* connection, | 21 mojo::Connection* connection, |
| 18 mojo::InterfaceRequest<ProfileService> request, | 22 ProfileServiceRequest request, |
| 19 base::FilePath base_profile_dir, | 23 scoped_ptr<mojo::MessageLoopRef> ref, |
| 24 const base::FilePath& base_profile_dir, | |
| 20 filesystem::LockTable* lock_table) | 25 filesystem::LockTable* lock_table) |
| 21 : binding_(this, std::move(request)), | 26 : message_loop_ref_(std::move(ref)), |
| 27 binding_(this, std::move(request)), | |
| 22 lock_table_(lock_table), | 28 lock_table_(lock_table), |
| 23 path_(base_profile_dir) { | 29 path_(base_profile_dir) { |
| 24 if (!base::PathExists(path_)) | 30 base::CreateDirectory(path_); |
| 25 base::CreateDirectory(path_); | |
| 26 } | 31 } |
| 27 | 32 |
| 28 ProfileServiceImpl::~ProfileServiceImpl() { | 33 ProfileServiceImpl::~ProfileServiceImpl() {} |
| 29 } | |
| 30 | 34 |
| 31 void ProfileServiceImpl::GetDirectory( | 35 void ProfileServiceImpl::GetDirectory( |
| 32 mojo::InterfaceRequest<filesystem::Directory> request) { | 36 filesystem::DirectoryRequest request, |
| 37 const GetDirectoryCallback& callback) { | |
| 33 new filesystem::DirectoryImpl(std::move(request), | 38 new filesystem::DirectoryImpl(std::move(request), |
| 34 path_, | 39 path_, |
| 35 scoped_ptr<base::ScopedTempDir>(), | 40 scoped_ptr<base::ScopedTempDir>(), |
| 36 lock_table_); | 41 lock_table_); |
| 42 callback.Run(); | |
| 43 } | |
| 44 | |
| 45 void ProfileServiceImpl::GetSubDirectory( | |
| 46 const mojo::String& dir_name, | |
|
michaeln
2016/03/16 03:11:13
since this can actually be a nested directory path
| |
| 47 filesystem::DirectoryRequest request, | |
| 48 const GetSubDirectoryCallback& callback) { | |
| 49 // Ensure that we've made |subdirectory| recursively under our profile. | |
| 50 base::FilePath subdir = | |
| 51 path_.Append( | |
| 52 #if defined(OS_WIN) | |
| 53 base::UTF8ToWide(dir_name.To<std::string>())); | |
| 54 #else | |
| 55 dir_name.To<std::string>()); | |
| 56 #endif | |
| 57 base::File::Error error; | |
| 58 if (!base::CreateDirectoryAndGetError(subdir, &error)) { | |
| 59 callback.Run(static_cast<filesystem::FileError>(error)); | |
| 60 return; | |
| 61 } | |
| 62 | |
| 63 new filesystem::DirectoryImpl(std::move(request), | |
| 64 subdir, | |
| 65 scoped_ptr<base::ScopedTempDir>(), | |
| 66 lock_table_); | |
| 67 callback.Run(filesystem::FileError::OK); | |
| 37 } | 68 } |
| 38 | 69 |
| 39 } // namespace profile | 70 } // namespace profile |
| OLD | NEW |