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

Unified Diff: chrome/browser/profiles/profile_shortcut_manager_win.cc

Issue 11299160: Find shortcuts that don't have a profile command line set when creating 2nd profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_shortcut_manager_win.cc
===================================================================
--- chrome/browser/profiles/profile_shortcut_manager_win.cc (revision 169477)
+++ chrome/browser/profiles/profile_shortcut_manager_win.cc (working copy)
@@ -98,13 +98,6 @@
return icon_path;
}
-// Returns the command-line flags to launch Chrome with the given profile.
-string16 CreateProfileShortcutFlags(const FilePath& profile_path) {
- return base::StringPrintf(L"--%ls=\"%ls\"",
- ASCIIToUTF16(switches::kProfileDirectory).c_str(),
- profile_path.BaseName().value().c_str());
-}
-
// Gets the directory where to create desktop shortcuts.
bool GetDesktopShortcutsDirectory(FilePath* directory) {
const bool result =
@@ -115,32 +108,27 @@
return result;
}
-// Returns true if the file at |path| is a Chrome shortcut with the given
-// |command_line|.
-bool IsChromeShortcutWithCommandLine(const FilePath& path,
- const FilePath& chrome_exe,
- const string16& command_line) {
+// Returns true if the file at |path| is a Chrome shortcut and returns its
+// command line in output parameter |command_line|.
+bool IsChromeShortcut(const FilePath& path,
+ const FilePath& chrome_exe,
+ string16* command_line) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
if (path.Extension() != installer::kLnkExt)
return false;
FilePath target_path;
- string16 command_line_args;
- if (!base::win::ResolveShortcut(path, &target_path, &command_line_args))
+ if (!base::win::ResolveShortcut(path, &target_path, command_line))
return false;
-
- // TODO(asvitkine): Change this to build a CommandLine object and ensure all
- // args from |command_line| are present in the shortcut's CommandLine. This
- // will be more robust when |command_line| contains multiple args.
- return target_path == chrome_exe &&
- command_line_args.find(command_line) != string16::npos;
+ return target_path == chrome_exe;
}
// Populates |paths| with the file paths of Chrome desktop shortcuts that have
// the specified |command_line|.
void ListDesktopShortcutsWithCommandLine(const FilePath& chrome_exe,
const string16& command_line,
+ bool include_empty_command_lines,
std::vector<FilePath>* paths) {
FilePath shortcuts_directory;
if (!GetDesktopShortcutsDirectory(&shortcuts_directory))
@@ -150,8 +138,17 @@
file_util::FileEnumerator::FILES);
for (FilePath path = enumerator.Next(); !path.empty();
path = enumerator.Next()) {
- if (IsChromeShortcutWithCommandLine(path, chrome_exe, command_line))
+ string16 shortcut_command_line;
+ if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line))
+ continue;
+
+ // TODO(asvitkine): Change this to build a CommandLine object and ensure all
+ // args from |command_line| are present in the shortcut's CommandLine. This
+ // will be more robust when |command_line| contains multiple args.
+ if ((shortcut_command_line.empty() && include_empty_command_lines) ||
+ (shortcut_command_line.find(command_line) != string16::npos)) {
paths->push_back(path);
+ }
}
}
@@ -183,6 +180,7 @@
void CreateOrUpdateDesktopShortcutsForProfile(const FilePath& profile_path,
const string16& profile_name,
const SkBitmap& avatar_image,
+ bool include_empty_command_lines,
bool create) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
@@ -202,14 +200,16 @@
if (!shortcut_icon.empty())
properties.set_icon(shortcut_icon, 0);
- const string16 command_line = CreateProfileShortcutFlags(profile_path);
+ const string16 command_line =
+ profiles::internal::CreateProfileShortcutFlags(profile_path);
properties.set_arguments(command_line);
ShellUtil::ShortcutOperation operation =
ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING;
std::vector<FilePath> shortcuts;
- ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, &shortcuts);
+ ListDesktopShortcutsWithCommandLine(chrome_exe, command_line,
+ include_empty_command_lines, &shortcuts);
if (create && shortcuts.empty()) {
const string16 shortcut_name =
profiles::internal::GetShortcutFilenameForProfile(profile_name,
@@ -238,9 +238,11 @@
return;
}
- const string16 command_line = CreateProfileShortcutFlags(profile_path);
+ const string16 command_line =
+ profiles::internal::CreateProfileShortcutFlags(profile_path);
std::vector<FilePath> shortcuts;
- ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, &shortcuts);
+ ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false,
+ &shortcuts);
BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
for (size_t i = 0; i < shortcuts.size(); ++i) {
@@ -271,6 +273,12 @@
return shortcut_name + installer::kLnkExt;
}
+string16 CreateProfileShortcutFlags(const FilePath& profile_path) {
+ return base::StringPrintf(L"--%ls=\"%ls\"",
+ ASCIIToUTF16(switches::kProfileDirectory).c_str(),
+ profile_path.BaseName().value().c_str());
+}
+
} // namespace internal
} // namespace profiles
@@ -296,16 +304,17 @@
void ProfileShortcutManagerWin::CreateProfileShortcut(
const FilePath& profile_path) {
- UpdateShortcutsForProfileAtPath(profile_path, true);
+ UpdateShortcutsForProfileAtPath(profile_path, false, true);
}
void ProfileShortcutManagerWin::OnProfileAdded(const FilePath& profile_path) {
const size_t profile_count =
profile_manager_->GetProfileInfoCache().GetNumberOfProfiles();
if (profile_count == 1) {
- UpdateShortcutsForProfileAtPath(profile_path, true);
+ UpdateShortcutsForProfileAtPath(profile_path, true, true);
sail 2012/11/26 21:27:16 these UpdateShortcutsForProfileAtPath() calls are
Alexei Svitkine (slow) 2012/11/27 22:31:26 Done. Let me know if you have better suggestions f
} else if (profile_count == 2) {
- UpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), false);
+ UpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), true,
+ false);
}
}
@@ -320,7 +329,8 @@
// If there is only one profile remaining, remove the badging information
// from an existing shortcut.
if (cache.GetNumberOfProfiles() == 1)
- UpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), false);
+ UpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), false,
+ false);
sail 2012/11/26 21:27:16 indentation looks wrong here
Alexei Svitkine (slow) 2012/11/27 22:31:26 Done.
const FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
@@ -331,12 +341,12 @@
void ProfileShortcutManagerWin::OnProfileNameChanged(
const FilePath& profile_path,
const string16& old_profile_name) {
- UpdateShortcutsForProfileAtPath(profile_path, false);
+ UpdateShortcutsForProfileAtPath(profile_path, false, false);
}
void ProfileShortcutManagerWin::OnProfileAvatarChanged(
const FilePath& profile_path) {
- UpdateShortcutsForProfileAtPath(profile_path, false);
+ UpdateShortcutsForProfileAtPath(profile_path, false, false);
}
void ProfileShortcutManagerWin::StartProfileShortcutNameChange(
@@ -379,6 +389,7 @@
void ProfileShortcutManagerWin::UpdateShortcutsForProfileAtPath(
const FilePath& profile_path,
+ bool include_empty_command_lines,
sail 2012/11/26 21:27:16 this name is too implementation specific. Maybe pi
Alexei Svitkine (slow) 2012/11/27 22:31:26 Hopefully, this should be clearer with the enum pa
bool create_always) {
ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache();
size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path);
@@ -418,7 +429,8 @@
BrowserThread::FILE, FROM_HERE,
base::Bind(&CreateOrUpdateDesktopShortcutsForProfile,
profile_path, new_shortcut_appended_name,
- profile_avatar_bitmap_copy, create_always));
+ profile_avatar_bitmap_copy, include_empty_command_lines,
+ create_always));
cache->SetShortcutNameOfProfileAtIndex(profile_index,
new_shortcut_appended_name);

Powered by Google App Engine
This is Rietveld 408576698