Index: chrome/browser/profiles/profile_shortcut_manager_win.cc |
=================================================================== |
--- chrome/browser/profiles/profile_shortcut_manager_win.cc (revision 0) |
+++ chrome/browser/profiles/profile_shortcut_manager_win.cc (revision 0) |
@@ -0,0 +1,196 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
+ |
+#include "base/bind.h" |
+#include "base/file_path.h" |
+#include "base/file_util.h" |
+#include "base/path_service.h" |
+#include "base/utf_string_conversions.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/profiles/profile_info_cache.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/common/chrome_constants.h" |
+#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/pref_names.h" |
+#include "chrome/installer/util/browser_distribution.h" |
+#include "chrome/installer/util/shell_util.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "grit/generated_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+using content::BrowserThread; |
+ |
+namespace { |
+ |
+// Creates the argument to pass to the Windows executable that launches Chrome |
+// with the profile in |profile_base_dir|. |
+// For example: --profile-directory="Profile 2" |
+string16 CreateProfileShortcutSwitch(string16 profile_base_dir) { |
+ string16 profile_directory; |
+ profile_directory = L"--"; |
+ profile_directory.append( |
+ UTF8ToUTF16(std::string(switches::kProfileDirectory))); |
+ profile_directory.append(L"=\""); |
+ profile_directory.append(profile_base_dir); |
+ profile_directory.append(L"\""); |
+ return profile_directory; |
robertshield
2011/11/18 03:58:57
base::StringPrintf could make this shorter.
Miranda Callahan
2011/11/18 19:00:36
Ah, didn't know about that. Thanks, done.
|
+} |
+ |
+} // namespace |
+ |
+ProfileShortcutManagerWin::ProfileShortcutManagerWin() { |
+} |
+ |
+ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { |
+} |
+ |
+void ProfileShortcutManagerWin::OnProfileAdded(string16 profile_name, |
+ string16 profile_base_dir) { |
+ // Launch task to add shortcut to desktop on Windows. If this is the very |
+ // first profile created, don't add the user name to the shortcut. |
+ // TODO(mirandac): respect master_preferences choice to create no shortcuts |
+ // (see http://crbug.com/104463) |
+ if (g_browser_process->profile_manager()->GetNumberOfProfiles() > 1) { |
+ string16 profile_directory; |
+ profile_directory.assign(CreateProfileShortcutSwitch(profile_base_dir)); |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&CreateChromeDesktopShortcutForProfile, |
+ profile_name, profile_directory, true)); |
+ |
+ // If this is the very first multi-user account created, change the |
+ // original shortcut to launch with the First User profile as well. |
+ PrefService* local_state = g_browser_process->local_state(); |
+ if (local_state->GetInteger(prefs::kProfilesNumCreated) == 2) { |
+ string16 old_shortcut; |
+ string16 new_shortcut; |
+ string16 default_name = l10n_util::GetStringUTF16( |
+ IDS_DEFAULT_PROFILE_NAME); |
+ string16 default_directory = |
+ CreateProfileShortcutSwitch(UTF8ToUTF16(chrome::kInitialProfile)); |
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ if (ShellUtil::GetChromeShortcutName(dist, false, L"", &old_shortcut) && |
+ ShellUtil::GetChromeShortcutName(dist, false, default_name, |
+ &new_shortcut)) { |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&RenameChromeDesktopShortcutForProfile, |
+ old_shortcut, new_shortcut)); |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&UpdateChromeDesktopShortcutForProfile, |
+ new_shortcut, default_directory)); |
+ } |
+ } |
+ } else { |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&CreateChromeDesktopShortcutForProfile, |
+ L"", L"", true)); |
+ } |
+} |
+ |
+void ProfileShortcutManagerWin::OnProfileRemoved(string16 profile_name) { |
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ string16 shortcut; |
+ if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, &shortcut)) { |
+ std::vector<string16> shortcuts; |
+ shortcuts.push_back(shortcut); |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&RemoveChromeDesktopShortcutsForProfiles, |
+ shortcuts)); |
+ } |
+} |
+ |
+void ProfileShortcutManagerWin::OnProfileNameChanged( |
+ string16 old_profile_name, |
+ string16 new_profile_name) { |
+ // Launch task to change name of desktop shortcut on Windows. |
+ // TODO(mirandac): respect master_preferences choice to create no shortcuts |
+ // (see http://crbug.com/104463) |
+ string16 old_shortcut; |
+ string16 new_shortcut; |
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ if (ShellUtil::GetChromeShortcutName( |
+ dist, false, old_profile_name, &old_shortcut) && |
+ ShellUtil::GetChromeShortcutName( |
+ dist, false, new_profile_name, &new_shortcut)) { |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&RenameChromeDesktopShortcutForProfile, |
+ old_shortcut, |
+ new_shortcut)); |
+ } |
+} |
+ |
+// static |
+void ProfileShortcutManagerWin::RemoveChromeDesktopShortcutsForProfiles( |
+ std::vector<string16> shortcut_names) { |
+ bool not_used = ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
+ shortcut_names); |
+} |
+ |
+// static |
+void ProfileShortcutManagerWin::CreateChromeDesktopShortcutForProfile( |
+ string16 profile_name, string16 directory, bool create) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
+ FilePath chrome_exe; |
+ if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
+ return; |
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ string16 description; |
+ if (!dist) |
+ return; |
+ else |
+ description = WideToUTF16(dist->GetAppDescription()); |
+ ShellUtil::CreateChromeDesktopShortcut( |
+ dist, |
+ chrome_exe.value(), |
+ description, |
+ profile_name, |
+ directory, |
+ ShellUtil::CURRENT_USER, |
+ false, // Use alternate text. |
+ create); // Create if it doesn't already exist. |
+} |
+ |
+// static |
+void ProfileShortcutManagerWin::RenameChromeDesktopShortcutForProfile( |
+ string16 old_shortcut, |
+ string16 new_shortcut) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
+ FilePath shortcut_path; |
+ if (ShellUtil::GetDesktopPath(false, // User's directory instead of system. |
+ &shortcut_path)) { |
+ FilePath old_profile = shortcut_path.Append(old_shortcut); |
+ FilePath new_profile = shortcut_path.Append(new_shortcut); |
+ file_util::Move(old_profile, new_profile); |
+ } |
+} |
+ |
+// static |
+void ProfileShortcutManagerWin::UpdateChromeDesktopShortcutForProfile( |
+ string16 shortcut, |
+ string16 arguments) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
+ FilePath shortcut_path; |
+ if (!ShellUtil::GetDesktopPath(false, &shortcut_path)) |
+ return; |
+ |
+ shortcut_path = shortcut_path.Append(shortcut); |
+ FilePath chrome_exe; |
+ if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
+ return; |
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ string16 description; |
+ if (!dist) |
+ return; |
+ else |
+ description = WideToUTF16(dist->GetAppDescription()); |
+ ShellUtil::UpdateChromeShortcut( |
+ dist, |
+ chrome_exe.value(), |
+ UTF8ToUTF16(shortcut_path.MaybeAsASCII()), |
+ arguments, |
+ description, |
+ false); |
+} |
Property changes on: chrome\browser\profiles\profile_shortcut_manager_win.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |