| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 false, file_util::FileEnumerator::DIRECTORIES); | 257 false, file_util::FileEnumerator::DIRECTORIES); |
| 258 std::wstring folder_name; | 258 std::wstring folder_name; |
| 259 while (!(folder_name = file_enum.Next().ToWStringHack()).empty()) { | 259 while (!(folder_name = file_enum.Next().ToWStringHack()).empty()) { |
| 260 folder_name = file_util::GetFilenameFromPath(folder_name); | 260 folder_name = file_util::GetFilenameFromPath(folder_name); |
| 261 std::wstring profile_name; | 261 std::wstring profile_name; |
| 262 if (GetProfileNameFromFolderName(folder_name, &profile_name)) | 262 if (GetProfileNameFromFolderName(folder_name, &profile_name)) |
| 263 profiles->push_back(profile_name); | 263 profiles->push_back(profile_name); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 bool UserDataManager::CreateDesktopShortcutForProfile( | 267 bool UserDataManager::CreateShortcutForProfileInFolder( |
| 268 const FilePath& folder, |
| 268 const std::wstring& profile_name) const { | 269 const std::wstring& profile_name) const { |
| 269 #if defined(OS_WIN) | 270 #if defined(OS_WIN) |
| 270 std::wstring exe_path; | 271 std::wstring exe_path; |
| 271 std::wstring shortcut_path; | 272 if (!PathService::Get(base::FILE_EXE, &exe_path)) |
| 272 if (!PathService::Get(base::FILE_EXE, &exe_path) || | |
| 273 !ShellUtil::GetDesktopPath(false, &shortcut_path)) | |
| 274 return false; | 273 return false; |
| 275 | 274 |
| 276 // Working directory. | 275 // Working directory. |
| 277 std::wstring exe_folder = file_util::GetDirectoryFromPath(exe_path); | 276 std::wstring exe_folder = file_util::GetDirectoryFromPath(exe_path); |
| 278 | 277 |
| 279 // Command and arguments. | 278 // Command and arguments. |
| 280 std::wstring cmd; | 279 std::wstring cmd; |
| 281 cmd = StringPrintf(L"\"%ls\"", exe_path.c_str()); | 280 cmd = StringPrintf(L"\"%ls\"", exe_path.c_str()); |
| 282 std::wstring user_data_dir = GetUserDataFolderForProfile(profile_name); | 281 std::wstring user_data_dir = GetUserDataFolderForProfile(profile_name); |
| 283 std::wstring args = CommandLine::PrefixedSwitchStringWithValue( | 282 std::wstring args = CommandLine::PrefixedSwitchStringWithValue( |
| 284 switches::kUserDataDir, | 283 switches::kUserDataDir, |
| 285 user_data_dir); | 284 user_data_dir); |
| 286 args = StringPrintf(L"\"%ls\"", args.c_str()); | 285 args = StringPrintf(L"\"%ls\"", args.c_str()); |
| 287 | 286 |
| 288 // Shortcut path. | 287 // Shortcut path. |
| 289 std::wstring shortcut_name = l10n_util::GetStringF( | 288 std::wstring shortcut_name = l10n_util::GetStringF( |
| 290 IDS_START_IN_PROFILE_SHORTCUT_NAME, | 289 IDS_START_IN_PROFILE_SHORTCUT_NAME, |
| 291 profile_name); | 290 profile_name); |
| 292 shortcut_name.append(L".lnk"); | 291 shortcut_name.append(L".lnk"); |
| 293 file_util::AppendToPath(&shortcut_path, shortcut_name); | 292 |
| 293 std::wstring shortcut_path = folder.Append(shortcut_name).ToWStringHack(); |
| 294 | 294 |
| 295 // Profile path from user_data_dir. | 295 // Profile path from user_data_dir. |
| 296 FilePath profile_path = FilePath(user_data_dir).Append( | 296 FilePath profile_path = FilePath(user_data_dir).Append( |
| 297 chrome::kNotSignedInProfile); | 297 chrome::kNotSignedInProfile); |
| 298 | 298 |
| 299 return file_util::CreateShortcutLink( | 299 return file_util::CreateShortcutLink( |
| 300 cmd.c_str(), | 300 cmd.c_str(), |
| 301 shortcut_path.c_str(), | 301 shortcut_path.c_str(), |
| 302 exe_folder.c_str(), | 302 exe_folder.c_str(), |
| 303 args.c_str(), | 303 args.c_str(), |
| 304 NULL, | 304 NULL, |
| 305 exe_path.c_str(), | 305 exe_path.c_str(), |
| 306 0, | 306 0, |
| 307 ShellIntegration::GetChromiumAppId(profile_path).c_str()); | 307 ShellIntegration::GetChromiumAppId(profile_path).c_str()); |
| 308 #else | 308 #else |
| 309 NOTIMPLEMENTED(); |
| 310 return false; |
| 311 #endif |
| 312 } |
| 313 |
| 314 bool UserDataManager::CreateDesktopShortcutForProfile( |
| 315 const std::wstring& profile_name) const { |
| 316 #if defined(OS_WIN) |
| 317 std::wstring desktop_path; |
| 318 if (!ShellUtil::GetDesktopPath(false, &desktop_path)) |
| 319 return false; |
| 320 |
| 321 return CreateShortcutForProfileInFolder(FilePath(desktop_path), profile_name); |
| 322 #else |
| 309 // TODO(port): should probably use freedesktop.org standard for desktop files. | 323 // TODO(port): should probably use freedesktop.org standard for desktop files. |
| 310 NOTIMPLEMENTED(); | 324 NOTIMPLEMENTED(); |
| 311 return false; | 325 return false; |
| 312 #endif | 326 #endif |
| 313 } | 327 } |
| 314 | 328 |
| 315 void UserDataManager::RefreshUserDataDirProfiles() const { | 329 void UserDataManager::RefreshUserDataDirProfiles() const { |
| 316 // UserDataDirProfilesUpdater will delete itself when done. | 330 // UserDataDirProfilesUpdater will delete itself when done. |
| 317 UserDataDirProfilesUpdater* updater = new UserDataDirProfilesUpdater(); | 331 UserDataDirProfilesUpdater* updater = new UserDataDirProfilesUpdater(); |
| 318 updater->Run(); | 332 updater->Run(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 &GetProfilesHelper::InvokeDelegate, | 376 &GetProfilesHelper::InvokeDelegate, |
| 363 profiles.release())); | 377 profiles.release())); |
| 364 } | 378 } |
| 365 | 379 |
| 366 void GetProfilesHelper::InvokeDelegate(std::vector<std::wstring>* profiles) { | 380 void GetProfilesHelper::InvokeDelegate(std::vector<std::wstring>* profiles) { |
| 367 scoped_ptr< std::vector<std::wstring> > udd_profiles(profiles); | 381 scoped_ptr< std::vector<std::wstring> > udd_profiles(profiles); |
| 368 // If the delegate is gone by now, no need to do any work. | 382 // If the delegate is gone by now, no need to do any work. |
| 369 if (delegate_) | 383 if (delegate_) |
| 370 delegate_->OnGetProfilesDone(*udd_profiles.get()); | 384 delegate_->OnGetProfilesDone(*udd_profiles.get()); |
| 371 } | 385 } |
| OLD | NEW |