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

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: networking_private_api - use user_id_hash only if --multi-profiles switch is passed 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/chromeos/cros/cros_library.h" 9 #include "chrome/browser/chromeos/cros/cros_library.h"
10 #include "chrome/browser/chromeos/cros/network_library.h" 10 #include "chrome/browser/chromeos/cros/network_library.h"
11 #include "chrome/browser/chromeos/login/user_manager.h" 11 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/browser/chromeos/sms_observer.h" 12 #include "chrome/browser/chromeos/sms_observer.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 namespace { 20 namespace {
21 21
22 // TODO(nkostylev): Remove this hack when http://crbug.com/224291 is fixed. 22 base::FilePath GetProfilePathByUserIdHash(const std::string user_id_hash) {
23 // Now user homedirs are mounted to /home/user which is different from 23 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
24 // user data dir (/home/chronos). 24 // Fails for KioskTest.InstallAndLaunchApp test - crbug.com/238985
25 base::FilePath GetChromeOSProfileDir(const base::FilePath& path) { 25 // Will probably fail for Guest session / restart after a crash -
26 base::FilePath profile_dir(FILE_PATH_LITERAL("/home/user/")); 26 // crbug.com/238998
27 profile_dir = profile_dir.Append(path); 27 // TODO(nkostylev): Remove this check once these bugs are fixed.
28 return profile_dir; 28 if (command_line.HasSwitch(switches::kMultiProfiles))
29 DCHECK(!user_id_hash.empty());
30 ProfileManager* profile_manager = g_browser_process->profile_manager();
31 base::FilePath profile_path = profile_manager->user_data_dir();
32 return profile_path.Append(
33 base::FilePath(ProfileHelper::kProfileDirPrefix + user_id_hash));
29 } 34 }
30 35
31 } // namespace 36 } // namespace
32 37
33 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
34 // ProfileHelper, public 39 // ProfileHelper, public
35 40
41 // static
42 const char ProfileHelper::kProfileDirPrefix[] = "u-";
43
36 ProfileHelper::ProfileHelper() { 44 ProfileHelper::ProfileHelper() {
37 } 45 }
38 46
39 ProfileHelper::~ProfileHelper() { 47 ProfileHelper::~ProfileHelper() {
40 } 48 }
41 49
42 // static 50 // static
43 Profile* ProfileHelper::GetProfileByUserIdHash( 51 Profile* ProfileHelper::GetProfileByUserIdHash(
44 const std::string& user_id_hash) { 52 const std::string& user_id_hash) {
45 ProfileManager* profile_manager = g_browser_process->profile_manager(); 53 ProfileManager* profile_manager = g_browser_process->profile_manager();
46 return profile_manager->GetProfile( 54 return profile_manager->GetProfile(GetProfilePathByUserIdHash(user_id_hash));
47 GetChromeOSProfileDir(base::FilePath(user_id_hash)));
48 } 55 }
49 56
50 // static 57 // static
51 Profile* ProfileHelper::GetSigninProfile() { 58 Profile* ProfileHelper::GetSigninProfile() {
52 ProfileManager* profile_manager = g_browser_process->profile_manager(); 59 ProfileManager* profile_manager = g_browser_process->profile_manager();
53 base::FilePath user_data_dir = profile_manager->user_data_dir(); 60 base::FilePath user_data_dir = profile_manager->user_data_dir();
54 base::FilePath signin_profile_dir = 61 base::FilePath signin_profile_dir =
55 user_data_dir.AppendASCII(chrome::kInitialProfile); 62 user_data_dir.AppendASCII(chrome::kInitialProfile);
56 return profile_manager->GetProfile(signin_profile_dir)-> 63 return profile_manager->GetProfile(signin_profile_dir)->
57 GetOffTheRecordProfile(); 64 GetOffTheRecordProfile();
58 } 65 }
59 66
60 // static 67 // static
68 std::string ProfileHelper::GetUserIdHashFromProfile(Profile* profile) {
69 if (!profile)
70 return std::string();
71
72 // Check that profile directory starts with the correct prefix.
73 std::string profile_dir = profile->GetPath().BaseName().value();
74 std::string prefix(ProfileHelper::kProfileDirPrefix);
75 if (profile_dir.find(prefix) != 0) {
76 NOTREACHED();
77 return std::string();
78 }
79
80 return profile_dir.substr(prefix.length(),
81 profile_dir.length() - prefix.length());
82 }
83
84 // static
61 bool ProfileHelper::IsSigninProfile(Profile* profile) { 85 bool ProfileHelper::IsSigninProfile(Profile* profile) {
62 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; 86 return profile->GetPath().BaseName().value() == chrome::kInitialProfile;
63 } 87 }
64 88
65 // static 89 // static
66 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { 90 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
67 // Initialize Chrome OS preferences like touch pad sensitivity. For the 91 // Initialize Chrome OS preferences like touch pad sensitivity. For the
68 // preferences to work in the guest mode, the initialization has to be 92 // preferences to work in the guest mode, the initialization has to be
69 // done after |profile| is switched to the incognito profile (which 93 // done after |profile| is switched to the incognito profile (which
70 // is actually GuestSessionProfile in the guest mode). See the 94 // is actually GuestSessionProfile in the guest mode). See the
71 // GetOffTheRecordProfile() call above. 95 // GetOffTheRecordProfile() call above.
72 profile->InitChromeOSPreferences(); 96 profile->InitChromeOSPreferences();
73 97
74 if (process_startup) { 98 if (process_startup) {
75 static chromeos::SmsObserver* sms_observer = 99 static chromeos::SmsObserver* sms_observer =
76 new chromeos::SmsObserver(); 100 new chromeos::SmsObserver();
77 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 101 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
78 AddNetworkManagerObserver(sms_observer); 102 AddNetworkManagerObserver(sms_observer);
79 103
80 profile->SetupChromeOSEnterpriseExtensionObserver(); 104 profile->SetupChromeOSEnterpriseExtensionObserver();
81 } 105 }
82 } 106 }
83 107
108 base::FilePath ProfileHelper::GetActiveUserProfileDir() {
109 DCHECK(!active_user_id_hash_.empty());
110 return base::FilePath(
111 ProfileHelper::kProfileDirPrefix + active_user_id_hash_);
112 }
113
84 void ProfileHelper::Initialize() { 114 void ProfileHelper::Initialize() {
85 UserManager::Get()->AddSessionStateObserver(this); 115 UserManager::Get()->AddSessionStateObserver(this);
86 } 116 }
87 117
88 //////////////////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////////////////
89 // ProfileHelper, UserManager::UserSessionStateObserver implementation: 119 // ProfileHelper, UserManager::UserSessionStateObserver implementation:
90 120
91 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { 121 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
92 active_user_id_hash_ = hash; 122 active_user_id_hash_ = hash;
93 LOG(INFO) << "Switching to custom profile_dir: " << active_user_id_hash_; 123 base::FilePath profile_path = GetProfilePathByUserIdHash(hash);
124 LOG(INFO) << "Switching to profile path: " << profile_path.value();
94 } 125 }
95 126
96 } // namespace chromeos 127 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698