Index: components/filesystem/main.cc |
diff --git a/components/filesystem/main.cc b/components/filesystem/main.cc |
index 69be93f59c3367b88662191d8a369916b5aec5c1..27adae9e9c5028a0535f56e8e8b7c81d42b75d85 100644 |
--- a/components/filesystem/main.cc |
+++ b/components/filesystem/main.cc |
@@ -2,12 +2,71 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/command_line.h" |
+#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
#include "base/macros.h" |
#include "components/filesystem/file_system_app.h" |
#include "mojo/public/c/system/main.h" |
#include "mojo/shell/public/cpp/application_runner.h" |
+#if defined(OS_WIN) |
+#include "base/base_paths_win.h" |
+#include "base/path_service.h" |
+#include "base/strings/utf_string_conversions.h" |
+#elif defined(OS_ANDROID) |
+#include "base/base_paths_android.h" |
+#include "base/path_service.h" |
+#elif defined(OS_LINUX) |
+#include "base/environment.h" |
+#include "base/nix/xdg_util.h" |
+#elif defined(OS_MACOSX) |
+#include "base/base_paths_mac.h" |
+#include "base/path_service.h" |
+#endif |
+ |
+namespace { |
+ |
+const char kUserDataDir[] = "user-data-dir"; |
+ |
+base::FilePath GetUserDataDir() { |
+ base::FilePath path; |
+ |
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
+ if (command_line->HasSwitch(kUserDataDir)) { |
+ path = command_line->GetSwitchValuePath(kUserDataDir); |
+ } else { |
+#if defined(OS_WIN) |
+ CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path)); |
+ path = path.Append(FILE_PATH_LITERAL("mandoline")); |
+#elif defined(OS_LINUX) |
+ scoped_ptr<base::Environment> env(base::Environment::Create()); |
+ base::FilePath config_dir( |
+ base::nix::GetXDGDirectory(env.get(), |
+ base::nix::kXdgConfigHomeEnvVar, |
+ base::nix::kDotConfigDir)); |
+ path = config_dir.Append("mandoline"); |
+#elif defined(OS_MACOSX) |
+ CHECK(PathService::Get(base::DIR_APP_DATA, &path)); |
+ path = path.Append("Mandoline Shell"); |
+#elif defined(OS_ANDROID) |
+ CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path)); |
+ path = path.Append(FILE_PATH_LITERAL("mandoline")); |
+#else |
+ NOTIMPLEMENTED(); |
+#endif |
+ } |
+ |
+ if (!base::PathExists(path)) |
+ base::CreateDirectory(path); |
+ |
+ return path; |
+} |
+ |
+} // namespace |
+ |
MojoResult MojoMain(MojoHandle request) { |
- mojo::ApplicationRunner runner(new filesystem::FileSystemApp()); |
+ mojo::ApplicationRunner runner( |
+ new filesystem::FileSystemApp(GetUserDataDir())); |
return runner.Run(request); |
} |