Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / file_manager / path_util.cc
index 97bedd2..91ef187 100644 (file)
@@ -13,9 +13,7 @@
 #include "chrome/browser/chromeos/login/user_manager.h"
 #include "chrome/browser/download/download_prefs.h"
 #include "chrome/browser/profiles/profile.h"
-#include "content/public/browser/browser_context.h"
 #include "net/base/escape.h"
-#include "webkit/browser/fileapi/external_mount_points.h"
 
 namespace file_manager {
 namespace util {
@@ -25,6 +23,10 @@ namespace {
 const char kDownloadsFolderName[] = "Downloads";
 const base::FilePath::CharType kOldDownloadsFolderPath[] =
     FILE_PATH_LITERAL("/home/chronos/user/Downloads");
+const base::FilePath::CharType kOldDriveFolderPath[] =
+    FILE_PATH_LITERAL("/special/drive");
+const base::FilePath::CharType kNoHashDriveFolderPath[] =
+    FILE_PATH_LITERAL("/special/drive-");
 
 }  // namespace
 
@@ -47,6 +49,7 @@ bool MigratePathFromOldFormat(Profile* profile,
                               base::FilePath* new_path) {
   // M34:
   // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx
+  // /special/drive => /special/drive-xxx
   //
   // Old path format comes either from stored old settings or from the initial
   // default value set in DownloadPrefs::RegisterProfilePrefs in profile-unaware
@@ -54,16 +57,25 @@ bool MigratePathFromOldFormat(Profile* profile,
   // and in the latter case it is DownloadPrefs::GetDefaultDownloadDirectory().
   // Those two paths coincides as long as $HOME=/home/chronos/user, but the
   // environment variable is phasing out (crbug.com/333031) so we care both.
-  const base::FilePath old_bases[] = {
-      base::FilePath(kOldDownloadsFolderPath),
-      DownloadPrefs::GetDefaultDownloadDirectory(),
+
+  const base::FilePath downloads = GetDownloadsFolderForProfile(profile);
+  const base::FilePath drive = drive::util::GetDriveMountPointPath(profile);
+  const base::FilePath bases[][2] = {
+    {base::FilePath(kOldDownloadsFolderPath),      downloads},
+    {DownloadPrefs::GetDefaultDownloadDirectory(), downloads},
+    {base::FilePath(kOldDriveFolderPath),          drive},
+    // TODO(kinaba): http://crbug.com/341284 Remove after M34 branching.
+    // For a short period we incorrectly set "/special/drive-" as the Drive path
+    // that needs to be fixed.
+    {base::FilePath(kNoHashDriveFolderPath),       drive},
   };
-  for (size_t i = 0; i < arraysize(old_bases); ++i) {
-    const base::FilePath& old_base = old_bases[i];
+
+  for (size_t i = 0; i < arraysize(bases); ++i) {
+    const base::FilePath& old_base = bases[i][0];
+    const base::FilePath& new_base = bases[i][1];
     base::FilePath relative;
     if (old_path == old_base ||
         old_base.AppendRelativePath(old_path, &relative)) {
-      const base::FilePath new_base = GetDownloadsFolderForProfile(profile);
       *new_path = new_base.Append(relative);
       return old_path != *new_path;
     }
@@ -85,30 +97,5 @@ std::string GetDownloadsMountPointName(Profile* profile) {
   return net::EscapePath(kDownloadsFolderName + id);
 }
 
-bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) {
-  // Although we show only profile's own "Downloads" folder in Files.app,
-  // in the backend we need to mount all profile's download directory globally.
-  // Otherwise, Files.app cannot support cross-profile file copies, etc.
-  // For this reason, we need to register to the global GetSystemInstance().
-  const std::string mount_point_name = GetDownloadsMountPointName(profile);
-  fileapi::ExternalMountPoints* const mount_points =
-      fileapi::ExternalMountPoints::GetSystemInstance();
-
-  // In some tests we want to override existing Downloads mount point, so we
-  // first revoke the existing mount point (if any).
-  mount_points->RevokeFileSystem(mount_point_name);
-  return mount_points->RegisterFileSystem(
-      mount_point_name, fileapi::kFileSystemTypeNativeLocal,
-      fileapi::FileSystemMountOption(), path);
-}
-
-bool FindDownloadsMountPointPath(Profile* profile, base::FilePath* path) {
-  const std::string mount_point_name = GetDownloadsMountPointName(profile);
-  fileapi::ExternalMountPoints* const mount_points =
-      fileapi::ExternalMountPoints::GetSystemInstance();
-
-  return mount_points->GetRegisteredPath(mount_point_name, path);
-}
-
 }  // namespace util
 }  // namespace file_manager