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

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: ProfileHelper - check for non-empty user_id_hash only with --multi-profiles switch 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 if (command_line.HasSwitch(switches::kMultiProfiles))
25 base::FilePath GetChromeOSProfileDir(const base::FilePath& path) { 25 DCHECK(!user_id_hash.empty());
26 base::FilePath profile_dir(FILE_PATH_LITERAL("/home/user/")); 26 ProfileManager* profile_manager = g_browser_process->profile_manager();
27 profile_dir = profile_dir.Append(path); 27 base::FilePath profile_path = profile_manager->user_data_dir();
28 return profile_dir; 28 return profile_path.Append(
29 base::FilePath(ProfileHelper::kProfileDirPrefix + user_id_hash));
29 } 30 }
30 31
31 } // namespace 32 } // namespace
32 33
33 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
34 // ProfileHelper, public 35 // ProfileHelper, public
35 36
37 // static
38 const char ProfileHelper::kProfileDirPrefix[] = "u-";
39
36 ProfileHelper::ProfileHelper() { 40 ProfileHelper::ProfileHelper() {
37 } 41 }
38 42
39 ProfileHelper::~ProfileHelper() { 43 ProfileHelper::~ProfileHelper() {
40 } 44 }
41 45
42 // static 46 // static
43 Profile* ProfileHelper::GetProfileByUserIdHash( 47 Profile* ProfileHelper::GetProfileByUserIdHash(
44 const std::string& user_id_hash) { 48 const std::string& user_id_hash) {
45 ProfileManager* profile_manager = g_browser_process->profile_manager(); 49 ProfileManager* profile_manager = g_browser_process->profile_manager();
46 return profile_manager->GetProfile( 50 return profile_manager->GetProfile(GetProfilePathByUserIdHash(user_id_hash));
47 GetChromeOSProfileDir(base::FilePath(user_id_hash)));
48 } 51 }
49 52
50 // static 53 // static
51 Profile* ProfileHelper::GetSigninProfile() { 54 Profile* ProfileHelper::GetSigninProfile() {
52 ProfileManager* profile_manager = g_browser_process->profile_manager(); 55 ProfileManager* profile_manager = g_browser_process->profile_manager();
53 base::FilePath user_data_dir = profile_manager->user_data_dir(); 56 base::FilePath user_data_dir = profile_manager->user_data_dir();
54 base::FilePath signin_profile_dir = 57 base::FilePath signin_profile_dir =
55 user_data_dir.AppendASCII(chrome::kInitialProfile); 58 user_data_dir.AppendASCII(chrome::kInitialProfile);
56 return profile_manager->GetProfile(signin_profile_dir)-> 59 return profile_manager->GetProfile(signin_profile_dir)->
57 GetOffTheRecordProfile(); 60 GetOffTheRecordProfile();
58 } 61 }
59 62
60 // static 63 // static
64 std::string ProfileHelper::GetUserIdHashFromProfile(Profile* profile) {
65 if (!profile)
66 return std::string();
67
68 // Check that profile directory starts with the correct prefix.
69 std::string profile_dir = profile->GetPath().BaseName().value();
70 std::string prefix(ProfileHelper::kProfileDirPrefix);
71 if (profile_dir.find(prefix) != 0) {
72 NOTREACHED();
73 return std::string();
74 }
75
76 return profile_dir.substr(prefix.length(),
77 profile_dir.length() - prefix.length());
78 }
79
80 // static
61 bool ProfileHelper::IsSigninProfile(Profile* profile) { 81 bool ProfileHelper::IsSigninProfile(Profile* profile) {
62 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; 82 return profile->GetPath().BaseName().value() == chrome::kInitialProfile;
63 } 83 }
64 84
65 // static 85 // static
66 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { 86 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
67 // Initialize Chrome OS preferences like touch pad sensitivity. For the 87 // Initialize Chrome OS preferences like touch pad sensitivity. For the
68 // preferences to work in the guest mode, the initialization has to be 88 // preferences to work in the guest mode, the initialization has to be
69 // done after |profile| is switched to the incognito profile (which 89 // done after |profile| is switched to the incognito profile (which
70 // is actually GuestSessionProfile in the guest mode). See the 90 // is actually GuestSessionProfile in the guest mode). See the
71 // GetOffTheRecordProfile() call above. 91 // GetOffTheRecordProfile() call above.
72 profile->InitChromeOSPreferences(); 92 profile->InitChromeOSPreferences();
73 93
74 if (process_startup) { 94 if (process_startup) {
75 static chromeos::SmsObserver* sms_observer = 95 static chromeos::SmsObserver* sms_observer =
76 new chromeos::SmsObserver(); 96 new chromeos::SmsObserver();
77 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 97 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
78 AddNetworkManagerObserver(sms_observer); 98 AddNetworkManagerObserver(sms_observer);
79 99
80 profile->SetupChromeOSEnterpriseExtensionObserver(); 100 profile->SetupChromeOSEnterpriseExtensionObserver();
81 } 101 }
82 } 102 }
83 103
104 base::FilePath ProfileHelper::GetActiveUserProfileDir() {
105 DCHECK(!active_user_id_hash_.empty());
106 return base::FilePath(
107 ProfileHelper::kProfileDirPrefix + active_user_id_hash_);
108 }
109
84 void ProfileHelper::Initialize() { 110 void ProfileHelper::Initialize() {
85 UserManager::Get()->AddSessionStateObserver(this); 111 UserManager::Get()->AddSessionStateObserver(this);
86 } 112 }
87 113
88 //////////////////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////////////////
89 // ProfileHelper, UserManager::UserSessionStateObserver implementation: 115 // ProfileHelper, UserManager::UserSessionStateObserver implementation:
90 116
91 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { 117 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
92 active_user_id_hash_ = hash; 118 active_user_id_hash_ = hash;
93 LOG(INFO) << "Switching to custom profile_dir: " << active_user_id_hash_; 119 base::FilePath profile_path = GetProfilePathByUserIdHash(hash);
120 LOG(INFO) << "Switching to profile path: " << profile_path.value();
94 } 121 }
95 122
96 } // namespace chromeos 123 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698