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

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

Issue 444903002: [cros] user_manager component - move UserManagerBase and UserManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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
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/sys_info.h" 9 #include "base/sys_info.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h" 10 #include "chrome/browser/chromeos/drive/file_system_util.h"
11 #include "chrome/browser/chromeos/login/users/user_manager.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h" 11 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/download/download_prefs.h" 12 #include "chrome/browser/download/download_prefs.h"
14 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
15 #include "components/user_manager/user.h" 14 #include "components/user_manager/user.h"
15 #include "components/user_manager/user_manager.h"
16 #include "net/base/escape.h" 16 #include "net/base/escape.h"
17 17
18 namespace file_manager { 18 namespace file_manager {
19 namespace util { 19 namespace util {
20 20
21 namespace { 21 namespace {
22 22
23 const char kDownloadsFolderName[] = "Downloads"; 23 const char kDownloadsFolderName[] = "Downloads";
24 const base::FilePath::CharType kOldDownloadsFolderPath[] = 24 const base::FilePath::CharType kOldDownloadsFolderPath[] =
25 FILE_PATH_LITERAL("/home/chronos/user/Downloads"); 25 FILE_PATH_LITERAL("/home/chronos/user/Downloads");
26 const base::FilePath::CharType kOldDriveFolderPath[] = 26 const base::FilePath::CharType kOldDriveFolderPath[] =
27 FILE_PATH_LITERAL("/special/drive"); 27 FILE_PATH_LITERAL("/special/drive");
28 // Unintended path introduced in crbug.com/363026. 28 // Unintended path introduced in crbug.com/363026.
29 const base::FilePath::CharType kBuggyDriveFolderPath[] = 29 const base::FilePath::CharType kBuggyDriveFolderPath[] =
30 FILE_PATH_LITERAL("/special/drive-user"); 30 FILE_PATH_LITERAL("/special/drive-user");
31 31
32 } // namespace 32 } // namespace
33 33
34 base::FilePath GetDownloadsFolderForProfile(Profile* profile) { 34 base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
35 // On non-ChromeOS system (test+development), the primary profile uses 35 // On non-ChromeOS system (test+development), the primary profile uses
36 // $HOME/Downloads for ease for accessing local files for debugging. 36 // $HOME/Downloads for ease for accessing local files for debugging.
37 if (!base::SysInfo::IsRunningOnChromeOS() && 37 if (!base::SysInfo::IsRunningOnChromeOS() &&
38 chromeos::UserManager::IsInitialized()) { 38 user_manager::UserManager::IsInitialized()) {
39 const user_manager::User* const user = 39 const user_manager::User* const user =
40 chromeos::ProfileHelper::Get()->GetUserByProfile( 40 chromeos::ProfileHelper::Get()->GetUserByProfile(
41 profile->GetOriginalProfile()); 41 profile->GetOriginalProfile());
42 const user_manager::User* const primary_user = 42 const user_manager::User* const primary_user =
43 chromeos::UserManager::Get()->GetPrimaryUser(); 43 user_manager::UserManager::Get()->GetPrimaryUser();
44 if (user == primary_user) 44 if (user == primary_user)
45 return DownloadPrefs::GetDefaultDownloadDirectory(); 45 return DownloadPrefs::GetDefaultDownloadDirectory();
46 } 46 }
47 return profile->GetPath().AppendASCII(kDownloadsFolderName); 47 return profile->GetPath().AppendASCII(kDownloadsFolderName);
48 } 48 }
49 49
50 bool MigratePathFromOldFormat(Profile* profile, 50 bool MigratePathFromOldFormat(Profile* profile,
51 const base::FilePath& old_path, 51 const base::FilePath& old_path,
52 base::FilePath* new_path) { 52 base::FilePath* new_path) {
53 // M34: 53 // M34:
(...skipping 15 matching lines...) Expand all
69 downloads)); 69 downloads));
70 bases.push_back(std::make_pair(DownloadPrefs::GetDefaultDownloadDirectory(), 70 bases.push_back(std::make_pair(DownloadPrefs::GetDefaultDownloadDirectory(),
71 downloads)); 71 downloads));
72 bases.push_back(std::make_pair(base::FilePath(kOldDriveFolderPath), drive)); 72 bases.push_back(std::make_pair(base::FilePath(kOldDriveFolderPath), drive));
73 bases.push_back(std::make_pair(base::FilePath(kBuggyDriveFolderPath), drive)); 73 bases.push_back(std::make_pair(base::FilePath(kBuggyDriveFolderPath), drive));
74 74
75 // Trying migrating u-<hash>/Downloads to the current download path. This is 75 // Trying migrating u-<hash>/Downloads to the current download path. This is
76 // no-op when multi-profile is enabled. This is necessary for (1) back 76 // no-op when multi-profile is enabled. This is necessary for (1) back
77 // migration when multi-profile flag is enabled and then disabled, or (2) in 77 // migration when multi-profile flag is enabled and then disabled, or (2) in
78 // some edge cases (crbug.com/356322) that u-<hash> path is temporarily used. 78 // some edge cases (crbug.com/356322) that u-<hash> path is temporarily used.
79 if (chromeos::UserManager::IsInitialized()) { 79 if (user_manager::UserManager::IsInitialized()) {
80 const user_manager::User* const user = 80 const user_manager::User* const user =
81 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 81 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
82 if (user) { 82 if (user) {
83 const base::FilePath hashed_downloads = 83 const base::FilePath hashed_downloads =
84 chromeos::ProfileHelper::GetProfilePathByUserIdHash( 84 chromeos::ProfileHelper::GetProfilePathByUserIdHash(
85 user->username_hash()).AppendASCII(kDownloadsFolderName); 85 user->username_hash()).AppendASCII(kDownloadsFolderName);
86 bases.push_back(std::make_pair(hashed_downloads, downloads)); 86 bases.push_back(std::make_pair(hashed_downloads, downloads));
87 } 87 }
88 } 88 }
89 89
(...skipping 10 matching lines...) Expand all
100 100
101 return false; 101 return false;
102 } 102 }
103 103
104 std::string GetDownloadsMountPointName(Profile* profile) { 104 std::string GetDownloadsMountPointName(Profile* profile) {
105 // To distinguish profiles in multi-profile session, we append user name hash 105 // To distinguish profiles in multi-profile session, we append user name hash
106 // to "Downloads". Note that some profiles (like login or test profiles) 106 // to "Downloads". Note that some profiles (like login or test profiles)
107 // are not associated with an user account. In that case, no suffix is added 107 // are not associated with an user account. In that case, no suffix is added
108 // because such a profile never belongs to a multi-profile session. 108 // because such a profile never belongs to a multi-profile session.
109 user_manager::User* const user = 109 user_manager::User* const user =
110 chromeos::UserManager::IsInitialized() 110 user_manager::UserManager::IsInitialized()
111 ? chromeos::ProfileHelper::Get()->GetUserByProfile( 111 ? chromeos::ProfileHelper::Get()->GetUserByProfile(
112 profile->GetOriginalProfile()) 112 profile->GetOriginalProfile())
113 : NULL; 113 : NULL;
114 const std::string id = user ? "-" + user->username_hash() : ""; 114 const std::string id = user ? "-" + user->username_hash() : "";
115 return net::EscapeQueryParamValue(kDownloadsFolderName + id, false); 115 return net::EscapeQueryParamValue(kDownloadsFolderName + id, false);
116 } 116 }
117 117
118 } // namespace util 118 } // namespace util
119 } // namespace file_manager 119 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698