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

Side by Side Diff: chrome/browser/chromeos/profiles/profile_helper.cc

Issue 14581006: [cros mp] Load profiles from /home/chronos/u-[$hash], add GetUserIdHashFromProfile() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 7 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/profiles/profile_helper.h" 5 #include "chrome/browser/chromeos/profiles/profile_helper.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/browsing_data/browsing_data_helper.h" 9 #include "chrome/browser/browsing_data/browsing_data_helper.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chrome/browser/chromeos/cros/cros_library.h"
11 #include "chrome/browser/chromeos/cros/network_library.h" 11 #include "chrome/browser/chromeos/cros/network_library.h"
12 #include "chrome/browser/chromeos/login/user_manager.h" 12 #include "chrome/browser/chromeos/login/user_manager.h"
13 #include "chrome/browser/chromeos/sms_observer.h" 13 #include "chrome/browser/chromeos/sms_observer.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 namespace { 21 namespace {
22 22
23 // TODO(nkostylev): Remove this hack when http://crbug.com/224291 is fixed. 23 base::FilePath GetProfilePathByUserIdHash(const std::string user_id_hash) {
24 // Now user homedirs are mounted to /home/user which is different from 24 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
25 // user data dir (/home/chronos). 25 // Fails for KioskTest.InstallAndLaunchApp test - crbug.com/238985
26 base::FilePath GetChromeOSProfileDir(const base::FilePath& path) { 26 // Will probably fail for Guest session / restart after a crash -
27 base::FilePath profile_dir(FILE_PATH_LITERAL("/home/user/")); 27 // crbug.com/238998
28 profile_dir = profile_dir.Append(path); 28 // TODO(nkostylev): Remove this check once these bugs are fixed.
29 return profile_dir; 29 if (command_line.HasSwitch(switches::kMultiProfiles))
30 DCHECK(!user_id_hash.empty());
31 ProfileManager* profile_manager = g_browser_process->profile_manager();
32 base::FilePath profile_path = profile_manager->user_data_dir();
33 return profile_path.Append(
34 base::FilePath(ProfileHelper::kProfileDirPrefix + user_id_hash));
30 } 35 }
31 36
32 } // namespace 37 } // namespace
33 38
34 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
35 // ProfileHelper, public 40 // ProfileHelper, public
36 41
42 // static
43 const char ProfileHelper::kProfileDirPrefix[] = "u-";
44
37 ProfileHelper::ProfileHelper() 45 ProfileHelper::ProfileHelper()
38 : signin_profile_clear_requested_(false) { 46 : signin_profile_clear_requested_(false) {
39 } 47 }
40 48
41 ProfileHelper::~ProfileHelper() { 49 ProfileHelper::~ProfileHelper() {
42 } 50 }
43 51
44 // static 52 // static
45 Profile* ProfileHelper::GetProfileByUserIdHash( 53 Profile* ProfileHelper::GetProfileByUserIdHash(
46 const std::string& user_id_hash) { 54 const std::string& user_id_hash) {
47 ProfileManager* profile_manager = g_browser_process->profile_manager(); 55 ProfileManager* profile_manager = g_browser_process->profile_manager();
48 return profile_manager->GetProfile( 56 return profile_manager->GetProfile(GetProfilePathByUserIdHash(user_id_hash));
49 GetChromeOSProfileDir(base::FilePath(user_id_hash)));
50 } 57 }
51 58
52 // static 59 // static
53 Profile* ProfileHelper::GetSigninProfile() { 60 Profile* ProfileHelper::GetSigninProfile() {
54 ProfileManager* profile_manager = g_browser_process->profile_manager(); 61 ProfileManager* profile_manager = g_browser_process->profile_manager();
55 base::FilePath user_data_dir = profile_manager->user_data_dir(); 62 base::FilePath user_data_dir = profile_manager->user_data_dir();
56 base::FilePath signin_profile_dir = 63 base::FilePath signin_profile_dir =
57 user_data_dir.AppendASCII(chrome::kInitialProfile); 64 user_data_dir.AppendASCII(chrome::kInitialProfile);
58 return profile_manager->GetProfile(signin_profile_dir)-> 65 return profile_manager->GetProfile(signin_profile_dir)->
59 GetOffTheRecordProfile(); 66 GetOffTheRecordProfile();
60 } 67 }
61 68
62 // static 69 // static
70 std::string ProfileHelper::GetUserIdHashFromProfile(Profile* profile) {
71 if (!profile)
72 return std::string();
73
74 // Check that profile directory starts with the correct prefix.
75 std::string profile_dir = profile->GetPath().BaseName().value();
76 std::string prefix(ProfileHelper::kProfileDirPrefix);
77 if (profile_dir.find(prefix) != 0) {
78 NOTREACHED();
79 return std::string();
80 }
81
82 return profile_dir.substr(prefix.length(),
83 profile_dir.length() - prefix.length());
84 }
85
86 // static
63 bool ProfileHelper::IsSigninProfile(Profile* profile) { 87 bool ProfileHelper::IsSigninProfile(Profile* profile) {
64 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; 88 return profile->GetPath().BaseName().value() == chrome::kInitialProfile;
65 } 89 }
66 90
67 // static 91 // static
68 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { 92 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
69 // Initialize Chrome OS preferences like touch pad sensitivity. For the 93 // Initialize Chrome OS preferences like touch pad sensitivity. For the
70 // preferences to work in the guest mode, the initialization has to be 94 // preferences to work in the guest mode, the initialization has to be
71 // done after |profile| is switched to the incognito profile (which 95 // done after |profile| is switched to the incognito profile (which
72 // is actually GuestSessionProfile in the guest mode). See the 96 // is actually GuestSessionProfile in the guest mode). See the
73 // GetOffTheRecordProfile() call above. 97 // GetOffTheRecordProfile() call above.
74 profile->InitChromeOSPreferences(); 98 profile->InitChromeOSPreferences();
75 99
76 if (process_startup) { 100 if (process_startup) {
77 static chromeos::SmsObserver* sms_observer = 101 static chromeos::SmsObserver* sms_observer =
78 new chromeos::SmsObserver(); 102 new chromeos::SmsObserver();
79 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 103 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
80 AddNetworkManagerObserver(sms_observer); 104 AddNetworkManagerObserver(sms_observer);
81 105
82 profile->SetupChromeOSEnterpriseExtensionObserver(); 106 profile->SetupChromeOSEnterpriseExtensionObserver();
83 } 107 }
84 } 108 }
85 109
110 base::FilePath ProfileHelper::GetActiveUserProfileDir() {
111 DCHECK(!active_user_id_hash_.empty());
112 return base::FilePath(
113 ProfileHelper::kProfileDirPrefix + active_user_id_hash_);
114 }
115
86 void ProfileHelper::Initialize() { 116 void ProfileHelper::Initialize() {
87 UserManager::Get()->AddSessionStateObserver(this); 117 UserManager::Get()->AddSessionStateObserver(this);
88 } 118 }
89 119
90 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { 120 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) {
91 on_clear_callbacks_.push_back(on_clear_callback); 121 on_clear_callbacks_.push_back(on_clear_callback);
92 if (signin_profile_clear_requested_) 122 if (signin_profile_clear_requested_)
93 return; 123 return;
94 signin_profile_clear_requested_ = true; 124 signin_profile_clear_requested_ = true;
95 BrowsingDataRemover* remover = 125 BrowsingDataRemover* remover =
(...skipping 13 matching lines...) Expand all
109 on_clear_callbacks_[i].Run(); 139 on_clear_callbacks_[i].Run();
110 } 140 }
111 on_clear_callbacks_.clear(); 141 on_clear_callbacks_.clear();
112 } 142 }
113 143
114 //////////////////////////////////////////////////////////////////////////////// 144 ////////////////////////////////////////////////////////////////////////////////
115 // ProfileHelper, UserManager::UserSessionStateObserver implementation: 145 // ProfileHelper, UserManager::UserSessionStateObserver implementation:
116 146
117 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { 147 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
118 active_user_id_hash_ = hash; 148 active_user_id_hash_ = hash;
119 LOG(INFO) << "Switching to custom profile_dir: " << active_user_id_hash_; 149 base::FilePath profile_path = GetProfilePathByUserIdHash(hash);
150 LOG(INFO) << "Switching to profile path: " << profile_path.value();
120 } 151 }
121 152
122 } // namespace chromeos 153 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/profiles/profile_helper.h ('k') | chrome/browser/chromeos/profiles/profile_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698