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_app.h" | 5 #include "components/filesystem/file_system_app.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" |
7 #include "mojo/shell/public/cpp/connection.h" | 10 #include "mojo/shell/public/cpp/connection.h" |
8 #include "mojo/shell/public/cpp/shell.h" | 11 #include "mojo/shell/public/cpp/shell.h" |
9 | 12 |
| 13 #if defined(OS_WIN) |
| 14 #include "base/base_paths_win.h" |
| 15 #include "base/path_service.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
| 17 #elif defined(OS_ANDROID) |
| 18 #include "base/base_paths_android.h" |
| 19 #include "base/path_service.h" |
| 20 #elif defined(OS_LINUX) |
| 21 #include "base/environment.h" |
| 22 #include "base/nix/xdg_util.h" |
| 23 #elif defined(OS_MACOSX) |
| 24 #include "base/base_paths_mac.h" |
| 25 #include "base/path_service.h" |
| 26 #endif |
| 27 |
10 namespace filesystem { | 28 namespace filesystem { |
11 | 29 |
| 30 namespace { |
| 31 |
| 32 const char kUserDataDir[] = "user-data-dir"; |
| 33 |
| 34 } // namespace filesystem |
| 35 |
12 FileSystemApp::FileSystemApp() | 36 FileSystemApp::FileSystemApp() |
13 : shell_(nullptr), lock_table_(new LockTable) {} | 37 : shell_(nullptr), lock_table_(new LockTable) {} |
14 | 38 |
15 FileSystemApp::~FileSystemApp() {} | 39 FileSystemApp::~FileSystemApp() {} |
16 | 40 |
17 void FileSystemApp::Initialize(mojo::Shell* shell, const std::string& url, | 41 void FileSystemApp::Initialize(mojo::Shell* shell, const std::string& url, |
18 uint32_t id) { | 42 uint32_t id) { |
19 shell_ = shell; | 43 shell_ = shell; |
20 tracing_.Initialize(shell, url); | 44 tracing_.Initialize(shell, url); |
21 } | 45 } |
22 | 46 |
23 bool FileSystemApp::AcceptConnection(mojo::Connection* connection) { | 47 bool FileSystemApp::AcceptConnection(mojo::Connection* connection) { |
24 connection->AddInterface<FileSystem>(this); | 48 connection->AddInterface<FileSystem>(this); |
25 return true; | 49 return true; |
26 } | 50 } |
27 | 51 |
28 // |InterfaceFactory<Files>| implementation: | 52 // |InterfaceFactory<Files>| implementation: |
29 void FileSystemApp::Create(mojo::Connection* connection, | 53 void FileSystemApp::Create(mojo::Connection* connection, |
30 mojo::InterfaceRequest<FileSystem> request) { | 54 mojo::InterfaceRequest<FileSystem> request) { |
31 new FileSystemImpl(connection, std::move(request), lock_table_.get()); | 55 new FileSystemImpl(connection, std::move(request), GetUserDataDir(), |
| 56 lock_table_.get()); |
| 57 } |
| 58 |
| 59 //static |
| 60 base::FilePath FileSystemApp::GetUserDataDir() { |
| 61 base::FilePath path; |
| 62 |
| 63 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 64 if (command_line->HasSwitch(kUserDataDir)) { |
| 65 path = command_line->GetSwitchValuePath(kUserDataDir); |
| 66 } else { |
| 67 #if defined(OS_WIN) |
| 68 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path)); |
| 69 path = path.Append(FILE_PATH_LITERAL("mandoline")); |
| 70 #elif defined(OS_LINUX) |
| 71 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 72 base::FilePath config_dir( |
| 73 base::nix::GetXDGDirectory(env.get(), |
| 74 base::nix::kXdgConfigHomeEnvVar, |
| 75 base::nix::kDotConfigDir)); |
| 76 path = config_dir.Append("mandoline"); |
| 77 #elif defined(OS_MACOSX) |
| 78 CHECK(PathService::Get(base::DIR_APP_DATA, &path)); |
| 79 path = path.Append("Mandoline Shell"); |
| 80 #elif defined(OS_ANDROID) |
| 81 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path)); |
| 82 path = path.Append(FILE_PATH_LITERAL("mandoline")); |
| 83 #else |
| 84 NOTIMPLEMENTED(); |
| 85 #endif |
| 86 } |
| 87 |
| 88 if (!base::PathExists(path)) |
| 89 base::CreateDirectory(path); |
| 90 |
| 91 return path; |
32 } | 92 } |
33 | 93 |
34 } // namespace filesystem | 94 } // namespace filesystem |
OLD | NEW |