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

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

Issue 48903012: Switch "Downloads" directory path to the per-profile ones for multi-profile support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | « no previous file | 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 "chrome/browser/chromeos/drive/file_system_util.h" 11 #include "chrome/browser/chromeos/drive/file_system_util.h"
12 #include "chrome/browser/profiles/profile.h"
11 13
12 namespace file_manager { 14 namespace file_manager {
13 namespace util { 15 namespace util {
14 16
15 const char kDownloadsFolderName[] = "Downloads"; 17 const char kDownloadsFolderName[] = "Downloads";
16 const base::FilePath::CharType kOldDownloadsFolderPath[] = 18 const base::FilePath::CharType kOldDownloadsFolderPath[] =
17 FILE_PATH_LITERAL("/home/chronos/user/Downloads"); 19 FILE_PATH_LITERAL("/home/chronos/user/Downloads");
18 20
19 base::FilePath GetDownloadsFolderForProfile(Profile* profile) { 21 base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
20 // TODO(kinaba) crbug/309556: "Downloads" directory should be per-profile. 22 if (!base::SysInfo::IsRunningOnChromeOS()) {
21 // 23 // On the developer run on Linux desktop build, user $HOME/Downloads
22 // For this to be per-profile, a unique directory path from profile->GetPath() 24 // for ease for accessing local files for debugging.
23 // should be used rather than the HOME directory. We'll switch to the new path 25 base::FilePath path;
24 // once we have upgraded all code locations assuming the old path. 26 CHECK(PathService::Get(base::DIR_HOME, &path));
25 base::FilePath path; 27 return path.AppendASCII(kDownloadsFolderName);
26 CHECK(PathService::Get(base::DIR_HOME, &path)); 28 }
27 return path.AppendASCII(kDownloadsFolderName); 29
30 return profile->GetPath().AppendASCII(kDownloadsFolderName);
28 } 31 }
29 32
30 bool MigratePathFromOldFormat(Profile* profile, 33 bool MigratePathFromOldFormat(Profile* profile,
31 const base::FilePath& old_path, 34 const base::FilePath& old_path,
32 base::FilePath* new_path) { 35 base::FilePath* new_path) {
33 // /special/drive/xxx => /special/drive/root/xxx 36 // /special/drive/xxx => /special/drive/root/xxx
34 if (drive::util::NeedsNamespaceMigration(old_path)) { 37 if (drive::util::NeedsNamespaceMigration(old_path)) {
35 *new_path = drive::util::ConvertToMyDriveNamespace(old_path); 38 *new_path = drive::util::ConvertToMyDriveNamespace(old_path);
36 return true; 39 return true;
37 } 40 }
38 41
39 // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx 42 // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx
40 const base::FilePath old_base(kOldDownloadsFolderPath); 43 const base::FilePath old_base(kOldDownloadsFolderPath);
41 base::FilePath relative; 44 base::FilePath relative;
42 if (old_path == old_base || 45 if (old_path == old_base ||
43 old_base.AppendRelativePath(old_path, &relative)) { 46 old_base.AppendRelativePath(old_path, &relative)) {
44 const base::FilePath new_base = GetDownloadsFolderForProfile(profile); 47 const base::FilePath new_base = GetDownloadsFolderForProfile(profile);
45 *new_path = new_base.Append(relative); 48 *new_path = new_base.Append(relative);
46 return old_path != *new_path; 49 return old_path != *new_path;
47 } 50 }
48 51
49 return false; 52 return false;
50 } 53 }
51 54
52 55
53 } // namespace util 56 } // namespace util
54 } // namespace file_manager 57 } // namespace file_manager
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698