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/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/files/scoped_file.h" | 13 #include "base/files/scoped_file.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "components/filesystem/directory_impl.h" | 18 #include "components/filesystem/directory_impl.h" |
19 #include "components/filesystem/file_system_app.h" | |
20 #include "mojo/shell/public/cpp/connection.h" | 19 #include "mojo/shell/public/cpp/connection.h" |
21 #include "url/gurl.h" | 20 #include "url/gurl.h" |
22 | 21 |
23 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
24 #include "base/base_paths_win.h" | 23 #include "base/base_paths_win.h" |
25 #include "base/path_service.h" | 24 #include "base/path_service.h" |
26 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
27 #elif defined(OS_ANDROID) | 26 #elif defined(OS_ANDROID) |
28 #include "base/base_paths_android.h" | 27 #include "base/base_paths_android.h" |
29 #include "base/path_service.h" | 28 #include "base/path_service.h" |
30 #elif defined(OS_LINUX) | 29 #elif defined(OS_LINUX) |
31 #include "base/environment.h" | 30 #include "base/environment.h" |
32 #include "base/nix/xdg_util.h" | 31 #include "base/nix/xdg_util.h" |
33 #elif defined(OS_MACOSX) | 32 #elif defined(OS_MACOSX) |
34 #include "base/base_paths_mac.h" | 33 #include "base/base_paths_mac.h" |
35 #include "base/path_service.h" | 34 #include "base/path_service.h" |
36 #endif | 35 #endif |
37 | 36 |
38 namespace filesystem { | 37 namespace filesystem { |
39 | 38 |
40 namespace { | 39 namespace { |
41 | 40 |
42 const char kEscapeChar = ','; | 41 const char kEscapeChar = ','; |
43 | 42 |
44 const char kUserDataDir[] = "user-data-dir"; | 43 const char kUserDataDir[] = "user-data-dir"; |
45 | 44 |
46 } // namespace filesystem | 45 } // namespace filesystem |
47 | 46 |
48 FileSystemImpl::FileSystemImpl(FileSystemApp* app, | 47 FileSystemImpl::FileSystemImpl(mojo::Connection* connection, |
49 mojo::Connection* connection, | |
50 mojo::InterfaceRequest<FileSystem> request, | 48 mojo::InterfaceRequest<FileSystem> request, |
51 LockTable* lock_table) | 49 LockTable* lock_table) |
52 : app_(app), | 50 : remote_application_url_(connection->GetRemoteApplicationURL()), |
53 remote_application_url_(connection->GetRemoteApplicationURL()), | |
54 binding_(this, std::move(request)), | 51 binding_(this, std::move(request)), |
55 lock_table_(lock_table) {} | 52 lock_table_(lock_table) {} |
56 | 53 |
57 FileSystemImpl::~FileSystemImpl() { | 54 FileSystemImpl::~FileSystemImpl() { |
58 } | 55 } |
59 | 56 |
60 void FileSystemImpl::OpenFileSystem(const mojo::String& file_system, | 57 void FileSystemImpl::OpenFileSystem(const mojo::String& file_system, |
61 mojo::InterfaceRequest<Directory> directory, | 58 mojo::InterfaceRequest<Directory> directory, |
62 FileSystemClientPtr client, | 59 FileSystemClientPtr client, |
63 const OpenFileSystemCallback& callback) { | 60 const OpenFileSystemCallback& callback) { |
(...skipping 18 matching lines...) Expand all Loading... |
82 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
83 path = base_profile_dir.Append(base::UTF8ToWide(sanitized_origin)); | 80 path = base_profile_dir.Append(base::UTF8ToWide(sanitized_origin)); |
84 #else | 81 #else |
85 path = base_profile_dir.Append(sanitized_origin); | 82 path = base_profile_dir.Append(sanitized_origin); |
86 #endif | 83 #endif |
87 if (!base::PathExists(path)) | 84 if (!base::PathExists(path)) |
88 base::CreateDirectory(path); | 85 base::CreateDirectory(path); |
89 } | 86 } |
90 | 87 |
91 if (!path.empty()) { | 88 if (!path.empty()) { |
92 DirectoryImpl* dir_impl = new DirectoryImpl( | 89 new DirectoryImpl( |
93 std::move(directory), path, std::move(temp_dir), lock_table_); | 90 std::move(directory), path, std::move(temp_dir), lock_table_); |
94 app_->RegisterDirectoryToClient(dir_impl, std::move(client)); | |
95 callback.Run(FileError::OK); | 91 callback.Run(FileError::OK); |
96 } else { | 92 } else { |
97 callback.Run(FileError::FAILED); | 93 callback.Run(FileError::FAILED); |
98 } | 94 } |
99 } | 95 } |
100 | 96 |
101 base::FilePath FileSystemImpl::GetSystemProfileDir() const { | 97 base::FilePath FileSystemImpl::GetSystemProfileDir() const { |
102 base::FilePath path; | 98 base::FilePath path; |
103 | 99 |
104 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 100 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 encoded[1] += (encoded[1] >= 10) ? 'A' - 10 : '0'; | 151 encoded[1] += (encoded[1] >= 10) ? 'A' - 10 : '0'; |
156 encoded[2] = ch % 16; | 152 encoded[2] = ch % 16; |
157 encoded[2] += (encoded[2] >= 10) ? 'A' - 10 : '0'; | 153 encoded[2] += (encoded[2] >= 10) ? 'A' - 10 : '0'; |
158 encoded_len = 3; | 154 encoded_len = 3; |
159 } | 155 } |
160 sanitized_origin->append(encoded, encoded_len); | 156 sanitized_origin->append(encoded, encoded_len); |
161 } | 157 } |
162 } | 158 } |
163 | 159 |
164 } // namespace filesystem | 160 } // namespace filesystem |
OLD | NEW |