| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/profiles/profile_shortcut_manager.h" | 5 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/installer/util/auto_launch_util.h" | 25 #include "chrome/installer/util/auto_launch_util.h" |
| 26 #include "chrome/installer/util/browser_distribution.h" | 26 #include "chrome/installer/util/browser_distribution.h" |
| 27 #include "chrome/installer/util/shell_util.h" | 27 #include "chrome/installer/util/shell_util.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 30 #include "skia/ext/image_operations.h" | 30 #include "skia/ext/image_operations.h" |
| 31 #include "skia/ext/platform_canvas.h" | 31 #include "skia/ext/platform_canvas.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/gfx/icon_util.h" | 34 #include "ui/gfx/icon_util.h" |
| 35 #include "ui/gfx/image/image.h" |
| 35 | 36 |
| 36 using content::BrowserThread; | 37 using content::BrowserThread; |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 const char kProfileIconFileName[] = "Google Profile.ico"; | 41 const char kProfileIconFileName[] = "Google Profile.ico"; |
| 41 const int kProfileAvatarShortcutBadgeWidth = 28; | 42 const int kProfileAvatarShortcutBadgeWidth = 28; |
| 42 const int kProfileAvatarShortcutBadgeHeight = 28; | 43 const int kProfileAvatarShortcutBadgeHeight = 28; |
| 43 const int kShortcutIconSize = 48; | 44 const int kShortcutIconSize = 48; |
| 44 | 45 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 const base::Callback<bool(void)>& bool_function) { | 114 const base::Callback<bool(void)>& bool_function) { |
| 114 bool_function.Run(); | 115 bool_function.Run(); |
| 115 } | 116 } |
| 116 | 117 |
| 117 // Renames an existing Chrome desktop profile shortcut. Must be called on the | 118 // Renames an existing Chrome desktop profile shortcut. Must be called on the |
| 118 // FILE thread. | 119 // FILE thread. |
| 119 void RenameChromeDesktopShortcutForProfile( | 120 void RenameChromeDesktopShortcutForProfile( |
| 120 const string16& old_shortcut_file, | 121 const string16& old_shortcut_file, |
| 121 const string16& new_shortcut_file) { | 122 const string16& new_shortcut_file) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 124 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 123 FilePath shortcut_path; | 125 FilePath shortcut_path; |
| 124 if (ShellUtil::GetDesktopPath(false, // User's directory instead of system. | 126 if (ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist, |
| 125 &shortcut_path)) { | 127 ShellUtil::CURRENT_USER, &shortcut_path)) { |
| 126 FilePath old_shortcut_path = shortcut_path.Append(old_shortcut_file); | 128 FilePath old_shortcut_path = shortcut_path.Append(old_shortcut_file); |
| 127 FilePath new_shortcut_path = shortcut_path.Append(new_shortcut_file); | 129 FilePath new_shortcut_path = shortcut_path.Append(new_shortcut_file); |
| 128 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) | 130 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) |
| 129 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; | 131 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; |
| 130 } | 132 } |
| 131 } | 133 } |
| 132 | 134 |
| 133 // Create or update a profile desktop shortcut. Must be called on the FILE | 135 // Create or update a profile desktop shortcut. Must be called on the FILE |
| 134 // thread. | 136 // thread. |
| 135 void CreateOrUpdateProfileDesktopShortcut( | 137 void CreateOrUpdateProfileDesktopShortcut( |
| 136 const FilePath& profile_path, | 138 const FilePath& profile_path, |
| 137 const string16& profile_name, | 139 const string16& profile_name, |
| 138 const SkBitmap& avatar_image, | 140 const SkBitmap& avatar_image, |
| 139 bool create) { | 141 bool create) { |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 141 FilePath shortcut_icon = | 143 FilePath shortcut_icon = |
| 142 CreateChromeDesktopShortcutIconForProfile(profile_path, avatar_image); | 144 CreateChromeDesktopShortcutIconForProfile(profile_path, avatar_image); |
| 143 | 145 |
| 144 FilePath chrome_exe; | 146 FilePath chrome_exe; |
| 145 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | 147 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 148 NOTREACHED(); |
| 146 return; | 149 return; |
| 150 } |
| 147 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 151 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 148 if (!dist) | |
| 149 return; | |
| 150 string16 description(dist->GetAppDescription()); | |
| 151 | 152 |
| 152 uint32 options = create ? ShellUtil::SHORTCUT_CREATE_ALWAYS : | 153 ShellUtil::ChromeShortcutProperties properties(ShellUtil::CURRENT_USER); |
| 153 ShellUtil::SHORTCUT_NO_OPTIONS; | 154 properties.set_chrome_exe(chrome_exe); |
| 154 ShellUtil::CreateChromeDesktopShortcut( | 155 properties.set_arguments(CreateProfileShortcutFlags(profile_path)); |
| 155 dist, | 156 if (!shortcut_icon.empty()) |
| 156 chrome_exe.value(), | 157 properties.set_icon(shortcut_icon); |
| 157 description, | 158 properties.set_shortcut_name( |
| 158 profile_name, | 159 ProfileShortcutManager::GetShortcutNameForProfile(profile_name)); |
| 159 CreateProfileShortcutFlags(profile_path), | 160 ShellUtil::ChromeShortcutOperation operation = |
| 160 shortcut_icon.empty() ? chrome_exe.value() : shortcut_icon.value(), | 161 create ? ShellUtil::SHORTCUT_CREATE_ALWAYS : |
| 161 shortcut_icon.empty() ? dist->GetIconIndex() : 0, | 162 ShellUtil::SHORTCUT_REPLACE_EXISTING; |
| 162 ShellUtil::CURRENT_USER, | 163 ShellUtil::CreateOrUpdateChromeShortcut( |
| 163 options); | 164 ShellUtil::SHORTCUT_DESKTOP, dist, properties, operation); |
| 164 } | 165 } |
| 165 | 166 |
| 166 } // namespace | 167 } // namespace |
| 167 | 168 |
| 168 class ProfileShortcutManagerWin : public ProfileShortcutManager, | 169 class ProfileShortcutManagerWin : public ProfileShortcutManager, |
| 169 public ProfileInfoCacheObserver { | 170 public ProfileInfoCacheObserver { |
| 170 public: | 171 public: |
| 171 explicit ProfileShortcutManagerWin(ProfileManager* manager); | 172 explicit ProfileShortcutManagerWin(ProfileManager* manager); |
| 172 virtual ~ProfileShortcutManagerWin(); | 173 virtual ~ProfileShortcutManagerWin(); |
| 173 | 174 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 200 bool ProfileShortcutManager::IsFeatureEnabled() { | 201 bool ProfileShortcutManager::IsFeatureEnabled() { |
| 201 return false; | 202 return false; |
| 202 } | 203 } |
| 203 | 204 |
| 204 // static | 205 // static |
| 205 ProfileShortcutManager* ProfileShortcutManager::Create( | 206 ProfileShortcutManager* ProfileShortcutManager::Create( |
| 206 ProfileManager* manager) { | 207 ProfileManager* manager) { |
| 207 return new ProfileShortcutManagerWin(manager); | 208 return new ProfileShortcutManagerWin(manager); |
| 208 } | 209 } |
| 209 | 210 |
| 211 // static |
| 212 string16 ProfileShortcutManager::GetShortcutNameForProfile( |
| 213 const string16& profile_name) { |
| 214 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 215 string16 shortcut_name(dist->GetAppShortCutName()); |
| 216 shortcut_name.append(L" ("); |
| 217 shortcut_name.append(profile_name); |
| 218 shortcut_name.append(L")"); |
| 219 return shortcut_name; |
| 220 } |
| 221 |
| 210 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) | 222 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) |
| 211 : profile_manager_(manager) { | 223 : profile_manager_(manager) { |
| 212 profile_manager_->GetProfileInfoCache().AddObserver(this); | 224 profile_manager_->GetProfileInfoCache().AddObserver(this); |
| 213 } | 225 } |
| 214 | 226 |
| 215 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { | 227 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { |
| 216 profile_manager_->GetProfileInfoCache().RemoveObserver(this); | 228 profile_manager_->GetProfileInfoCache().RemoveObserver(this); |
| 217 } | 229 } |
| 218 | 230 |
| 219 void ProfileShortcutManagerWin::CreateProfileShortcut( | 231 void ProfileShortcutManagerWin::CreateProfileShortcut( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 244 UpdateShortcutForProfileAtPath( | 256 UpdateShortcutForProfileAtPath( |
| 245 profile_manager_->GetProfileInfoCache().GetPathOfProfileAtIndex(0), | 257 profile_manager_->GetProfileInfoCache().GetPathOfProfileAtIndex(0), |
| 246 false); | 258 false); |
| 247 } | 259 } |
| 248 | 260 |
| 249 string16 profile_name_updated; | 261 string16 profile_name_updated; |
| 250 if (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() != 0) | 262 if (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() != 0) |
| 251 profile_name_updated = profile_name; | 263 profile_name_updated = profile_name; |
| 252 | 264 |
| 253 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 265 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 254 string16 shortcut; | 266 BrowserThread::PostTask( |
| 255 // If we can find the shortcut, delete it | 267 BrowserThread::FILE, FROM_HERE, |
| 256 if (ShellUtil::GetChromeShortcutName(dist, false, | 268 base::Bind(&CallBoolFunction, base::Bind( |
| 257 profile_name_updated, &shortcut)) { | 269 &ShellUtil::RemoveChromeShortcut, ShellUtil::SHORTCUT_DESKTOP, |
| 258 std::vector<string16> appended_names(1, shortcut); | 270 dist, ShellUtil::CURRENT_USER, |
| 259 BrowserThread::PostTask( | 271 &GetShortcutNameForProfile(profile_name_updated)))); |
| 260 BrowserThread::FILE, FROM_HERE, | 272 |
| 261 base::Bind(&CallBoolFunction, base::Bind( | |
| 262 &ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames, | |
| 263 appended_names))); | |
| 264 } | |
| 265 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); | 273 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); |
| 266 BrowserThread::PostTask( | 274 BrowserThread::PostTask( |
| 267 BrowserThread::FILE, FROM_HERE, | 275 BrowserThread::FILE, FROM_HERE, |
| 268 base::Bind(&CallBoolFunction, base::Bind( | 276 base::Bind(&CallBoolFunction, base::Bind( |
| 269 &file_util::Delete, icon_path, false))); | 277 &file_util::Delete, icon_path, false))); |
| 270 } | 278 } |
| 271 | 279 |
| 272 void ProfileShortcutManagerWin::OnProfileNameChanged( | 280 void ProfileShortcutManagerWin::OnProfileNameChanged( |
| 273 const FilePath& profile_path, | 281 const FilePath& profile_path, |
| 274 const string16& old_profile_name) { | 282 const string16& old_profile_name) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 287 GetIndexOfProfileWithPath(profile_path); | 295 GetIndexOfProfileWithPath(profile_path); |
| 288 if (profile_index == std::string::npos) | 296 if (profile_index == std::string::npos) |
| 289 return; | 297 return; |
| 290 // If the shortcut will have an appended name, get the profile name. | 298 // If the shortcut will have an appended name, get the profile name. |
| 291 string16 new_profile_name = | 299 string16 new_profile_name = |
| 292 (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() == 1) ? | 300 (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() == 1) ? |
| 293 string16() : | 301 string16() : |
| 294 profile_manager_->GetProfileInfoCache(). | 302 profile_manager_->GetProfileInfoCache(). |
| 295 GetNameOfProfileAtIndex(profile_index); | 303 GetNameOfProfileAtIndex(profile_index); |
| 296 | 304 |
| 297 string16 old_shortcut_file; | |
| 298 string16 new_shortcut_file; | |
| 299 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 305 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 300 if (ShellUtil::GetChromeShortcutName( | 306 string16 old_shortcut_file(GetShortcutNameForProfile(old_profile_name)); |
| 301 dist, false, old_profile_name, &old_shortcut_file) && | 307 string16 new_shortcut_file(GetShortcutNameForProfile(new_profile_name)); |
| 302 ShellUtil::GetChromeShortcutName( | 308 BrowserThread::PostTask( |
| 303 dist, false, new_profile_name, &new_shortcut_file)) { | 309 BrowserThread::FILE, FROM_HERE, |
| 304 BrowserThread::PostTask( | 310 base::Bind(&RenameChromeDesktopShortcutForProfile, |
| 305 BrowserThread::FILE, FROM_HERE, | 311 old_shortcut_file, |
| 306 base::Bind(&RenameChromeDesktopShortcutForProfile, | 312 new_shortcut_file)); |
| 307 old_shortcut_file, | |
| 308 new_shortcut_file)); | |
| 309 } | |
| 310 } | 313 } |
| 311 | 314 |
| 312 FilePath ProfileShortcutManagerWin::GetOtherProfilePath( | 315 FilePath ProfileShortcutManagerWin::GetOtherProfilePath( |
| 313 const FilePath& profile_path) { | 316 const FilePath& profile_path) { |
| 314 DCHECK_EQ(2U, profile_manager_->GetProfileInfoCache().GetNumberOfProfiles()); | 317 DCHECK_EQ(2U, profile_manager_->GetProfileInfoCache().GetNumberOfProfiles()); |
| 315 // Get the index of the current profile, in order to find the index of the | 318 // Get the index of the current profile, in order to find the index of the |
| 316 // other profile. | 319 // other profile. |
| 317 size_t current_profile_index = profile_manager_->GetProfileInfoCache(). | 320 size_t current_profile_index = profile_manager_->GetProfileInfoCache(). |
| 318 GetIndexOfProfileWithPath(profile_path); | 321 GetIndexOfProfileWithPath(profile_path); |
| 319 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; | 322 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 } | 368 } |
| 366 BrowserThread::PostTask( | 369 BrowserThread::PostTask( |
| 367 BrowserThread::FILE, FROM_HERE, | 370 BrowserThread::FILE, FROM_HERE, |
| 368 base::Bind(&CreateOrUpdateProfileDesktopShortcut, | 371 base::Bind(&CreateOrUpdateProfileDesktopShortcut, |
| 369 profile_path, new_shortcut_appended_name, | 372 profile_path, new_shortcut_appended_name, |
| 370 profile_avatar_bitmap_copy, create_always)); | 373 profile_avatar_bitmap_copy, create_always)); |
| 371 | 374 |
| 372 profile_manager_->GetProfileInfoCache().SetShortcutNameOfProfileAtIndex( | 375 profile_manager_->GetProfileInfoCache().SetShortcutNameOfProfileAtIndex( |
| 373 profile_index, new_shortcut_appended_name); | 376 profile_index, new_shortcut_appended_name); |
| 374 } | 377 } |
| OLD | NEW |