Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / file_manager / path_util.cc
index 7f5f35d..cf9b0ed 100644 (file)
@@ -6,14 +6,13 @@
 
 #include "base/files/file_path.h"
 #include "base/logging.h"
-#include "base/path_service.h"
 #include "base/sys_info.h"
 #include "chrome/browser/chromeos/drive/file_system_util.h"
-#include "chrome/browser/chromeos/login/user.h"
-#include "chrome/browser/chromeos/login/user_manager.h"
 #include "chrome/browser/chromeos/profiles/profile_helper.h"
 #include "chrome/browser/download/download_prefs.h"
 #include "chrome/browser/profiles/profile.h"
+#include "components/user_manager/user.h"
+#include "components/user_manager/user_manager.h"
 #include "net/base/escape.h"
 
 namespace file_manager {
@@ -26,20 +25,25 @@ const base::FilePath::CharType kOldDownloadsFolderPath[] =
     FILE_PATH_LITERAL("/home/chronos/user/Downloads");
 const base::FilePath::CharType kOldDriveFolderPath[] =
     FILE_PATH_LITERAL("/special/drive");
+// Unintended path introduced in crbug.com/363026.
+const base::FilePath::CharType kBuggyDriveFolderPath[] =
+    FILE_PATH_LITERAL("/special/drive-user");
 
 }  // namespace
 
 base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
+  // On non-ChromeOS system (test+development), the primary profile uses
+  // $HOME/Downloads for ease for accessing local files for debugging.
   if (!base::SysInfo::IsRunningOnChromeOS() &&
-      !chromeos::UserManager::IsMultipleProfilesAllowed()) {
-    // On the developer run on Linux desktop build, if multiple profiles are
-    // not enabled, use $HOME/Downloads for ease for accessing local files for
-    // debugging.
-    base::FilePath path;
-    CHECK(PathService::Get(base::DIR_HOME, &path));
-    return path.AppendASCII(kDownloadsFolderName);
+      user_manager::UserManager::IsInitialized()) {
+    const user_manager::User* const user =
+        chromeos::ProfileHelper::Get()->GetUserByProfile(
+            profile->GetOriginalProfile());
+    const user_manager::User* const primary_user =
+        user_manager::UserManager::Get()->GetPrimaryUser();
+    if (user == primary_user)
+      return DownloadPrefs::GetDefaultDownloadDirectory();
   }
-
   return profile->GetPath().AppendASCII(kDownloadsFolderName);
 }
 
@@ -66,14 +70,15 @@ bool MigratePathFromOldFormat(Profile* profile,
   bases.push_back(std::make_pair(DownloadPrefs::GetDefaultDownloadDirectory(),
                                  downloads));
   bases.push_back(std::make_pair(base::FilePath(kOldDriveFolderPath), drive));
+  bases.push_back(std::make_pair(base::FilePath(kBuggyDriveFolderPath), drive));
 
   // Trying migrating u-<hash>/Downloads to the current download path. This is
   // no-op when multi-profile is enabled. This is necessary for (1) back
   // migration when multi-profile flag is enabled and then disabled, or (2) in
   // some edge cases (crbug.com/356322) that u-<hash> path is temporarily used.
-  if (chromeos::UserManager::IsInitialized()) {
-    const chromeos::User* const user =
-        chromeos::UserManager::Get()->GetUserByProfile(profile);
+  if (user_manager::UserManager::IsInitialized()) {
+    const user_manager::User* const user =
+        chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
     if (user) {
       const base::FilePath hashed_downloads =
           chromeos::ProfileHelper::GetProfilePathByUserIdHash(
@@ -101,12 +106,13 @@ std::string GetDownloadsMountPointName(Profile* profile) {
   // to "Downloads". Note that some profiles (like login or test profiles)
   // are not associated with an user account. In that case, no suffix is added
   // because such a profile never belongs to a multi-profile session.
-  chromeos::User* const user =
-      chromeos::UserManager::IsInitialized() ?
-          chromeos::UserManager::Get()->GetUserByProfile(
-              profile->GetOriginalProfile()) : NULL;
+  user_manager::User* const user =
+      user_manager::UserManager::IsInitialized()
+          ? chromeos::ProfileHelper::Get()->GetUserByProfile(
+                profile->GetOriginalProfile())
+          : NULL;
   const std::string id = user ? "-" + user->username_hash() : "";
-  return net::EscapePath(kDownloadsFolderName + id);
+  return net::EscapeQueryParamValue(kDownloadsFolderName + id, false);
 }
 
 }  // namespace util