Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: chrome/browser/chromeos/file_manager/path_util.cc

Issue 216053002: Files.app multi-profile: add back migration to old path format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/file_manager/path_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/chromeos/file_manager/path_util.h" 5 #include "chrome/browser/chromeos/file_manager/path_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
11 #include "chrome/browser/chromeos/drive/file_system_util.h" 11 #include "chrome/browser/chromeos/drive/file_system_util.h"
12 #include "chrome/browser/chromeos/login/user.h" 12 #include "chrome/browser/chromeos/login/user.h"
13 #include "chrome/browser/chromeos/login/user_manager.h" 13 #include "chrome/browser/chromeos/login/user_manager.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h"
14 #include "chrome/browser/download/download_prefs.h" 15 #include "chrome/browser/download/download_prefs.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "net/base/escape.h" 17 #include "net/base/escape.h"
17 18
18 namespace file_manager { 19 namespace file_manager {
19 namespace util { 20 namespace util {
20 21
21 namespace { 22 namespace {
22 23
23 const char kDownloadsFolderName[] = "Downloads"; 24 const char kDownloadsFolderName[] = "Downloads";
24 const base::FilePath::CharType kOldDownloadsFolderPath[] = 25 const base::FilePath::CharType kOldDownloadsFolderPath[] =
25 FILE_PATH_LITERAL("/home/chronos/user/Downloads"); 26 FILE_PATH_LITERAL("/home/chronos/user/Downloads");
26 const base::FilePath::CharType kOldDriveFolderPath[] = 27 const base::FilePath::CharType kOldDriveFolderPath[] =
27 FILE_PATH_LITERAL("/special/drive"); 28 FILE_PATH_LITERAL("/special/drive");
28 const base::FilePath::CharType kNoHashDriveFolderPath[] =
29 FILE_PATH_LITERAL("/special/drive-");
30 29
31 } // namespace 30 } // namespace
32 31
33 base::FilePath GetDownloadsFolderForProfile(Profile* profile) { 32 base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
34 if (!base::SysInfo::IsRunningOnChromeOS() && 33 if (!base::SysInfo::IsRunningOnChromeOS() &&
35 !chromeos::UserManager::IsMultipleProfilesAllowed()) { 34 !chromeos::UserManager::IsMultipleProfilesAllowed()) {
36 // On the developer run on Linux desktop build, if multiple profiles are 35 // On the developer run on Linux desktop build, if multiple profiles are
37 // not enabled, use $HOME/Downloads for ease for accessing local files for 36 // not enabled, use $HOME/Downloads for ease for accessing local files for
38 // debugging. 37 // debugging.
39 base::FilePath path; 38 base::FilePath path;
(...skipping 13 matching lines...) Expand all
53 // 52 //
54 // Old path format comes either from stored old settings or from the initial 53 // Old path format comes either from stored old settings or from the initial
55 // default value set in DownloadPrefs::RegisterProfilePrefs in profile-unaware 54 // default value set in DownloadPrefs::RegisterProfilePrefs in profile-unaware
56 // code location. In the former case it is "/home/chronos/user/Downloads", 55 // code location. In the former case it is "/home/chronos/user/Downloads",
57 // and in the latter case it is DownloadPrefs::GetDefaultDownloadDirectory(). 56 // and in the latter case it is DownloadPrefs::GetDefaultDownloadDirectory().
58 // Those two paths coincides as long as $HOME=/home/chronos/user, but the 57 // Those two paths coincides as long as $HOME=/home/chronos/user, but the
59 // environment variable is phasing out (crbug.com/333031) so we care both. 58 // environment variable is phasing out (crbug.com/333031) so we care both.
60 59
61 const base::FilePath downloads = GetDownloadsFolderForProfile(profile); 60 const base::FilePath downloads = GetDownloadsFolderForProfile(profile);
62 const base::FilePath drive = drive::util::GetDriveMountPointPath(profile); 61 const base::FilePath drive = drive::util::GetDriveMountPointPath(profile);
63 const base::FilePath bases[][2] = {
64 {base::FilePath(kOldDownloadsFolderPath), downloads},
65 {DownloadPrefs::GetDefaultDownloadDirectory(), downloads},
66 {base::FilePath(kOldDriveFolderPath), drive},
67 // TODO(kinaba): http://crbug.com/341284 Remove after M34 branching.
68 // For a short period we incorrectly set "/special/drive-" as the Drive path
69 // that needs to be fixed.
70 {base::FilePath(kNoHashDriveFolderPath), drive},
71 };
72 62
73 for (size_t i = 0; i < arraysize(bases); ++i) { 63 std::vector<std::pair<base::FilePath, base::FilePath> > bases;
74 const base::FilePath& old_base = bases[i][0]; 64 bases.push_back(std::make_pair(base::FilePath(kOldDownloadsFolderPath),
75 const base::FilePath& new_base = bases[i][1]; 65 downloads));
66 bases.push_back(std::make_pair(DownloadPrefs::GetDefaultDownloadDirectory(),
67 downloads));
68 bases.push_back(std::make_pair(base::FilePath(kOldDriveFolderPath), drive));
69
70 // Trying migrating u-<hash>/Downloads to the current download path. This is
71 // no-op when multi-profile is enabled. This is necessary for (1) back
72 // migration when multi-profile flag is enabled and then disabled, or (2) in
73 // some edge cases (crbug.com/356322) that u-<hash> path is temporarily used.
74 if (chromeos::UserManager::IsInitialized()) {
75 const chromeos::User* const user =
76 chromeos::UserManager::Get()->GetUserByProfile(profile);
77 if (user) {
78 const base::FilePath hashed_downloads =
79 chromeos::ProfileHelper::GetProfilePathByUserIdHash(
80 user->username_hash()).AppendASCII(kDownloadsFolderName);
81 bases.push_back(std::make_pair(hashed_downloads, downloads));
82 }
83 }
84
85 for (size_t i = 0; i < bases.size(); ++i) {
86 const base::FilePath& old_base = bases[i].first;
87 const base::FilePath& new_base = bases[i].second;
76 base::FilePath relative; 88 base::FilePath relative;
77 if (old_path == old_base || 89 if (old_path == old_base ||
78 old_base.AppendRelativePath(old_path, &relative)) { 90 old_base.AppendRelativePath(old_path, &relative)) {
79 *new_path = new_base.Append(relative); 91 *new_path = new_base.Append(relative);
80 return old_path != *new_path; 92 return old_path != *new_path;
81 } 93 }
82 } 94 }
83 95
84 return false; 96 return false;
85 } 97 }
86 98
87 std::string GetDownloadsMountPointName(Profile* profile) { 99 std::string GetDownloadsMountPointName(Profile* profile) {
88 // To distinguish profiles in multi-profile session, we append user name hash 100 // To distinguish profiles in multi-profile session, we append user name hash
89 // to "Downloads". Note that some profiles (like login or test profiles) 101 // to "Downloads". Note that some profiles (like login or test profiles)
90 // are not associated with an user account. In that case, no suffix is added 102 // are not associated with an user account. In that case, no suffix is added
91 // because such a profile never belongs to a multi-profile session. 103 // because such a profile never belongs to a multi-profile session.
92 chromeos::User* const user = 104 chromeos::User* const user =
93 chromeos::UserManager::IsInitialized() ? 105 chromeos::UserManager::IsInitialized() ?
94 chromeos::UserManager::Get()->GetUserByProfile( 106 chromeos::UserManager::Get()->GetUserByProfile(
95 profile->GetOriginalProfile()) : NULL; 107 profile->GetOriginalProfile()) : NULL;
96 const std::string id = user ? "-" + user->username_hash() : ""; 108 const std::string id = user ? "-" + user->username_hash() : "";
97 return net::EscapePath(kDownloadsFolderName + id); 109 return net::EscapePath(kDownloadsFolderName + id);
98 } 110 }
99 111
100 } // namespace util 112 } // namespace util
101 } // namespace file_manager 113 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/path_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698