Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/user_data_manager.h" | 7 #include "chrome/browser/user_data_manager.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/installer/util/browser_distribution.h" | 22 #include "chrome/installer/util/browser_distribution.h" |
| 23 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
| 24 | 24 |
| 25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 26 #include <windows.h> | 26 #include <windows.h> |
| 27 #include "chrome/installer/util/shell_util.h" | 27 #include "chrome/installer/util/shell_util.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // TODO: don't use wstrings in all this code. :( | |
|
Evan Stade
2009/10/19 22:54:31
TODO(evan)
| |
| 33 // But I'm not fixing it right now since this code is reported to be going | |
| 34 // away. | |
| 35 void DeprecatedPathServiceGet(int key, std::wstring* str) { | |
| 36 FilePath path; | |
| 37 PathService::Get(key, &path); | |
| 38 *str = path.ToWStringHack(); | |
| 39 } | |
| 40 | |
| 32 // Helper to start chrome for a given profile index. The helper takes care of | 41 // Helper to start chrome for a given profile index. The helper takes care of |
| 33 // enumerating profiles on the file thread and then it launches Chrome for the | 42 // enumerating profiles on the file thread and then it launches Chrome for the |
| 34 // appropriate profile on the original thread. | 43 // appropriate profile on the original thread. |
| 35 // An instance of this class should always be created on the heap, and it will | 44 // An instance of this class should always be created on the heap, and it will |
| 36 // delete itself when the launch is done. | 45 // delete itself when the launch is done. |
| 37 class LaunchChromeForProfileIndexHelper : GetProfilesHelper::Delegate { | 46 class LaunchChromeForProfileIndexHelper : GetProfilesHelper::Delegate { |
| 38 public: | 47 public: |
| 39 // Creates an instance with the given data manager and to launch chrome for | 48 // Creates an instance with the given data manager and to launch chrome for |
| 40 // the profile with the given index. | 49 // the profile with the given index. |
| 41 LaunchChromeForProfileIndexHelper(const UserDataManager* manager, int index); | 50 LaunchChromeForProfileIndexHelper(const UserDataManager* manager, int index); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // For e.g. a folder for the profile "Joe" would be named "User Data-Joe". | 97 // For e.g. a folder for the profile "Joe" would be named "User Data-Joe". |
| 89 static const wchar_t kProfileFolderSeparator[] = L"-"; | 98 static const wchar_t kProfileFolderSeparator[] = L"-"; |
| 90 | 99 |
| 91 // static | 100 // static |
| 92 UserDataManager* UserDataManager::instance_ = NULL; | 101 UserDataManager* UserDataManager::instance_ = NULL; |
| 93 | 102 |
| 94 // static | 103 // static |
| 95 UserDataManager* UserDataManager::Create() { | 104 UserDataManager* UserDataManager::Create() { |
| 96 DCHECK(!instance_); | 105 DCHECK(!instance_); |
| 97 std::wstring user_data; | 106 std::wstring user_data; |
| 98 PathService::Get(chrome::DIR_USER_DATA, &user_data); | 107 DeprecatedPathServiceGet(chrome::DIR_USER_DATA, &user_data); |
| 99 instance_ = new UserDataManager(user_data); | 108 instance_ = new UserDataManager(user_data); |
| 100 return instance_; | 109 return instance_; |
| 101 } | 110 } |
| 102 | 111 |
| 103 // static | 112 // static |
| 104 UserDataManager* UserDataManager::Get() { | 113 UserDataManager* UserDataManager::Get() { |
| 105 DCHECK(instance_); | 114 DCHECK(instance_); |
| 106 return instance_; | 115 return instance_; |
| 107 } | 116 } |
| 108 | 117 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 std::wstring folder_name = GetFolderNameFromProfileName(profile_name); | 182 std::wstring folder_name = GetFolderNameFromProfileName(profile_name); |
| 174 std::wstring folder_path(user_data_root_); | 183 std::wstring folder_path(user_data_root_); |
| 175 file_util::AppendToPath(&folder_path, folder_name); | 184 file_util::AppendToPath(&folder_path, folder_name); |
| 176 return folder_path; | 185 return folder_path; |
| 177 } | 186 } |
| 178 | 187 |
| 179 void UserDataManager::LaunchChromeForProfile( | 188 void UserDataManager::LaunchChromeForProfile( |
| 180 const std::wstring& profile_name) const { | 189 const std::wstring& profile_name) const { |
| 181 std::wstring user_data_dir = GetUserDataFolderForProfile(profile_name); | 190 std::wstring user_data_dir = GetUserDataFolderForProfile(profile_name); |
| 182 std::wstring command; | 191 std::wstring command; |
| 183 PathService::Get(base::FILE_EXE, &command); | 192 DeprecatedPathServiceGet(base::FILE_EXE, &command); |
| 184 CommandLine command_line(command); | 193 CommandLine command_line(command); |
| 185 command_line.AppendSwitch(switches::kEnableUserDataDirProfiles); | 194 command_line.AppendSwitch(switches::kEnableUserDataDirProfiles); |
| 186 command_line.AppendSwitchWithValue(switches::kUserDataDir, | 195 command_line.AppendSwitchWithValue(switches::kUserDataDir, |
| 187 user_data_dir); | 196 user_data_dir); |
| 188 std::wstring local_state_path; | 197 std::wstring local_state_path; |
| 189 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); | 198 DeprecatedPathServiceGet(chrome::FILE_LOCAL_STATE, &local_state_path); |
| 190 command_line.AppendSwitchWithValue(switches::kParentProfile, | 199 command_line.AppendSwitchWithValue(switches::kParentProfile, |
| 191 local_state_path); | 200 local_state_path); |
| 192 base::LaunchApp(command_line, false, false, NULL); | 201 base::LaunchApp(command_line, false, false, NULL); |
| 193 } | 202 } |
| 194 | 203 |
| 195 void UserDataManager::LaunchChromeForProfile(int index) const { | 204 void UserDataManager::LaunchChromeForProfile(int index) const { |
| 196 // Helper deletes itself when done. | 205 // Helper deletes itself when done. |
| 197 LaunchChromeForProfileIndexHelper* helper = | 206 LaunchChromeForProfileIndexHelper* helper = |
| 198 new LaunchChromeForProfileIndexHelper(this, index); | 207 new LaunchChromeForProfileIndexHelper(this, index); |
| 199 helper->StartLaunch(); | 208 helper->StartLaunch(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 &GetProfilesHelper::InvokeDelegate, | 312 &GetProfilesHelper::InvokeDelegate, |
| 304 profiles.release())); | 313 profiles.release())); |
| 305 } | 314 } |
| 306 | 315 |
| 307 void GetProfilesHelper::InvokeDelegate(std::vector<std::wstring>* profiles) { | 316 void GetProfilesHelper::InvokeDelegate(std::vector<std::wstring>* profiles) { |
| 308 scoped_ptr< std::vector<std::wstring> > udd_profiles(profiles); | 317 scoped_ptr< std::vector<std::wstring> > udd_profiles(profiles); |
| 309 // If the delegate is gone by now, no need to do any work. | 318 // If the delegate is gone by now, no need to do any work. |
| 310 if (delegate_) | 319 if (delegate_) |
| 311 delegate_->OnGetProfilesDone(*udd_profiles.get()); | 320 delegate_->OnGetProfilesDone(*udd_profiles.get()); |
| 312 } | 321 } |
| OLD | NEW |