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_win.h" | 5 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/app_icon_win.h" | 13 #include "chrome/browser/app_icon_win.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile_info_cache.h" | 16 #include "chrome/browser/profiles/profile_info_cache.h" |
17 #include "chrome/browser/profiles/profile_info_util.h" | 17 #include "chrome/browser/profiles/profile_info_util.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/installer/util/auto_launch_util.h" | 22 #include "chrome/installer/util/auto_launch_util.h" |
23 #include "chrome/installer/util/browser_distribution.h" | 23 #include "chrome/installer/util/browser_distribution.h" |
24 #include "chrome/installer/util/shell_util.h" | 24 #include "chrome/installer/util/shell_util.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
27 #include "skia/ext/image_operations.h" | 27 #include "skia/ext/image_operations.h" |
28 #include "skia/ext/platform_canvas.h" | 28 #include "skia/ext/platform_canvas.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
31 #include "ui/gfx/icon_util.h" | 31 #include "ui/gfx/icon_util.h" |
32 #include "ui/gfx/image/image.h" | |
33 | 32 |
34 using content::BrowserThread; | 33 using content::BrowserThread; |
35 | 34 |
36 namespace { | 35 namespace { |
37 | 36 |
38 const char kProfileIconFileName[] = "Google Profile.ico"; | 37 const char kProfileIconFileName[] = "Google Profile.ico"; |
39 const int kProfileAvatarShortcutBadgeWidth = 28; | 38 const int kProfileAvatarShortcutBadgeWidth = 28; |
40 const int kProfileAvatarShortcutBadgeHeight = 28; | 39 const int kProfileAvatarShortcutBadgeHeight = 28; |
41 const int kShortcutIconSize = 48; | 40 const int kShortcutIconSize = 48; |
42 | 41 |
43 // Creates the argument to pass to the Windows executable that launches Chrome | 42 struct ProfileShortcutInfo { |
44 // with the profile in |profile_base_dir|. | 43 string16 flags; |
45 // For example: --profile-directory="Profile 2" | 44 string16 profile_name; |
46 string16 CreateProfileShortcutSwitch(const string16& profile_base_dir) { | 45 gfx::Image avatar_image; |
47 return base::StringPrintf(L"--%ls=\"%ls\"", | |
48 ASCIIToUTF16(switches::kProfileDirectory).c_str(), | |
49 profile_base_dir.c_str()); | |
50 } | |
51 | 46 |
52 // Wrap a ShellUtil function that returns a bool so it can be posted in a | 47 ProfileShortcutInfo() : flags(string16()), profile_name(string16()), |
53 // task to the FILE thread. | 48 avatar_image(gfx::Image()) { |
54 void CallShellUtilBoolFunction( | 49 } |
55 const base::Callback<bool(void)>& bool_function) { | 50 |
56 bool_function.Run(); | 51 ProfileShortcutInfo(string16 p_flags, string16 p_profile_name, |
57 } | 52 gfx::Image p_avatar_image) : flags(p_flags), |
53 profile_name(p_profile_name), avatar_image(p_avatar_image) { | |
54 } | |
55 }; | |
56 | |
57 typedef std::map<FilePath, ProfileShortcutInfo> ProfileShortcutsMap; | |
58 ProfileShortcutsMap profile_shortcuts_; | |
58 | 59 |
59 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile, | 60 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile, |
60 // badging the browser distribution icon with the profile avatar. | 61 // badging the browser distribution icon with the profile avatar. |
61 // |profile_base_dir| is the base directory (and key) of the profile. Returns | 62 // |profile_base_dir| is the base directory (and key) of the profile. Returns |
62 // a path to the shortcut icon file on disk, which is empty if this fails. | 63 // a path to the shortcut icon file on disk, which is empty if this fails. |
63 // Use index 0 when assigning the resulting file as the icon. | 64 // Use index 0 when assigning the resulting file as the icon. |
64 FilePath CreateChromeDesktopShortcutIconForProfile( | 65 FilePath CreateChromeDesktopShortcutIconForProfile( |
65 const FilePath& profile_path, | 66 const FilePath& profile_path, |
66 const gfx::Image& avatar_image) { | 67 const gfx::Image& avatar_image) { |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
68 const SkBitmap* avatar_bitmap = avatar_image.ToSkBitmap(); | 69 const SkBitmap* avatar_bitmap = avatar_image.ToSkBitmap(); |
69 HICON app_icon_handle = GetAppIconForSize(kShortcutIconSize); | 70 HICON app_icon_handle = GetAppIconForSize(kShortcutIconSize); |
70 scoped_ptr<SkBitmap> app_icon_bitmap( | 71 scoped_ptr<SkBitmap> app_icon_bitmap( |
71 IconUtil::CreateSkBitmapFromHICON(app_icon_handle)); | 72 IconUtil::CreateSkBitmapFromHICON(app_icon_handle)); |
72 DestroyIcon(app_icon_handle); | 73 DestroyIcon(app_icon_handle); |
73 if (!app_icon_bitmap.get()) | 74 if (!app_icon_bitmap.get()) |
74 return FilePath(); | 75 return FilePath(); |
75 | 76 |
76 // TODO(stevet): Share this chunk of code with | 77 // TODO(hallielaine): Share this chunk of code with |
77 // avatar_menu_button::DrawTaskBarDecoration. | 78 // avatar_menu_button::DrawTaskBarDecoration. |
78 const SkBitmap* source_bitmap = NULL; | 79 const SkBitmap* source_bitmap = NULL; |
79 SkBitmap squarer_bitmap; | 80 SkBitmap squarer_bitmap; |
80 if ((avatar_bitmap->width() == profiles::kAvatarIconWidth) && | 81 if ((avatar_bitmap->width() == profiles::kAvatarIconWidth) && |
81 (avatar_bitmap->height() == profiles::kAvatarIconHeight)) { | 82 (avatar_bitmap->height() == profiles::kAvatarIconHeight)) { |
82 // Shave a couple of columns so the bitmap is more square. So when | 83 // Shave a couple of columns so the bitmap is more square. So when |
83 // resized to a square aspect ratio it looks pretty. | 84 // resized to a square aspect ratio it looks pretty. |
84 int x = 2; | 85 int x = 2; |
85 avatar_bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(x, 0, | 86 avatar_bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(x, 0, |
86 profiles::kAvatarIconWidth - x * 2, profiles::kAvatarIconHeight)); | 87 profiles::kAvatarIconWidth - x * 2, profiles::kAvatarIconHeight)); |
(...skipping 23 matching lines...) Expand all Loading... | |
110 offscreen_canvas->getDevice()->accessBitmap(false); | 111 offscreen_canvas->getDevice()->accessBitmap(false); |
111 | 112 |
112 // Finally, write the .ico file containing this new bitmap. | 113 // Finally, write the .ico file containing this new bitmap. |
113 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); | 114 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); |
114 if (!IconUtil::CreateIconFileFromSkBitmap(final_bitmap, icon_path)) | 115 if (!IconUtil::CreateIconFileFromSkBitmap(final_bitmap, icon_path)) |
115 return FilePath(); | 116 return FilePath(); |
116 | 117 |
117 return icon_path; | 118 return icon_path; |
118 } | 119 } |
119 | 120 |
120 // Creates a desktop shortcut to open Chrome with the given profile name and | 121 string16 CreateProfileShortcutFlags(const FilePath& profile_path) { |
121 // base directory. Iff |create|, create shortcut if it doesn't already exist. | 122 return base::StringPrintf(L"--%ls=\"%ls\"", |
122 // Must be called on the FILE thread. | 123 ASCIIToUTF16(switches::kProfileDirectory).c_str(), |
123 void CreateChromeDesktopShortcutForProfile( | 124 profile_path.BaseName().value().c_str()); |
124 const string16& profile_name, | 125 } |
125 const string16& profile_base_dir, | 126 |
126 const FilePath& profile_path, | 127 // Wrap a ShellUtil function that returns a bool so it can be posted in a |
127 const gfx::Image* avatar_image, | 128 // task to the FILE thread. |
128 bool create) { | 129 void CallShellUtilBoolFunction( |
130 const base::Callback<bool(void)>& bool_function) { | |
131 bool_function.Run(); | |
132 } | |
133 } // namespace | |
134 | |
135 ProfileShortcutManager::ProfileShortcutManager() { | |
sail
2012/08/13 22:09:36
This should be a separate class, ProfileShortcutMa
Halli
2012/08/14 18:25:57
Done.
| |
136 } | |
137 | |
138 ProfileShortcutManager::~ProfileShortcutManager() { | |
139 } | |
140 | |
141 // static | |
142 ProfileShortcutManager* ProfileShortcutManager::Create() { | |
143 return new ProfileShortcutManager(); | |
144 } | |
145 | |
146 // static | |
147 bool ProfileShortcutManager::IsFeatureEnabled() { | |
148 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
149 switches::kProfileDesktopShortcuts)) { | |
150 return true; | |
151 } | |
152 return false; | |
153 } | |
154 | |
155 void ProfileShortcutManager::CreateChromeDesktopShortcut( | |
156 const FilePath& profile_path, string16 profile_name, | |
157 const gfx::Image& avatar_image) { | |
158 FilePath shortcut_icon = CreateChromeDesktopShortcutIconForProfile( | |
159 profile_path, avatar_image); | |
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
130 FilePath chrome_exe; | 161 FilePath chrome_exe; |
131 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | 162 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
132 return; | 163 return; |
133 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
134 string16 description; | |
135 if (!dist) | |
136 return; | |
137 else | |
138 description = WideToUTF16(dist->GetAppDescription()); | |
139 const string16& directory = CreateProfileShortcutSwitch(profile_base_dir); | |
140 FilePath icon_path = avatar_image ? | |
141 CreateChromeDesktopShortcutIconForProfile(profile_path, *avatar_image) : | |
142 FilePath(); | |
143 | |
144 ShellUtil::CreateChromeDesktopShortcut( | |
145 dist, | |
146 chrome_exe.value(), | |
147 description, | |
148 profile_name, | |
149 directory, | |
150 icon_path.empty() ? chrome_exe.value() : icon_path.value(), | |
151 icon_path.empty() ? dist->GetIconIndex() : 0, | |
152 ShellUtil::CURRENT_USER, | |
153 create ? ShellUtil::SHORTCUT_CREATE_ALWAYS : | |
154 ShellUtil::SHORTCUT_NO_OPTIONS); | |
155 } | |
156 | |
157 // Renames an existing Chrome desktop profile shortcut. Must be called on the | |
158 // FILE thread. | |
159 void RenameChromeDesktopShortcutForProfile( | |
160 const string16& old_shortcut, | |
161 const string16& new_shortcut) { | |
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
163 FilePath shortcut_path; | |
164 if (ShellUtil::GetDesktopPath(false, // User's directory instead of system. | |
165 &shortcut_path)) { | |
166 FilePath old_profile = shortcut_path.Append(old_shortcut); | |
167 FilePath new_profile = shortcut_path.Append(new_shortcut); | |
168 file_util::Move(old_profile, new_profile); | |
169 } | |
170 } | |
171 | |
172 // Updates the arguments to a Chrome desktop shortcut for a profile. Must be | |
173 // called on the FILE thread. | |
174 void UpdateChromeDesktopShortcutForProfile( | |
175 const string16& shortcut, | |
176 const string16& arguments, | |
177 const FilePath& profile_path, | |
178 const gfx::Image* avatar_image) { | |
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
180 FilePath shortcut_path; | |
181 if (!ShellUtil::GetDesktopPath(false, &shortcut_path)) | |
182 return; | |
183 | |
184 shortcut_path = shortcut_path.Append(shortcut); | |
185 FilePath chrome_exe; | |
186 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | |
187 return; | |
188 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 164 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
189 string16 description; | 165 string16 description; |
190 if (!dist) | 166 if (!dist) |
191 return; | 167 return; |
192 else | 168 else |
193 description = WideToUTF16(dist->GetAppDescription()); | 169 description = WideToUTF16(dist->GetAppDescription()); |
194 FilePath icon_path = avatar_image ? | |
195 CreateChromeDesktopShortcutIconForProfile(profile_path, *avatar_image) : | |
196 FilePath(); | |
197 | 170 |
198 ShellUtil::UpdateChromeShortcut( | 171 // Add the profile to the map if it doesn't exist already |
172 if (!profile_shortcuts_.count(profile_path)) { | |
173 string16 flags = CreateProfileShortcutFlags(profile_path); | |
174 profile_shortcuts_.insert(std::make_pair(profile_path, | |
175 ProfileShortcutInfo(flags, profile_name, | |
176 avatar_image))); | |
177 } | |
178 | |
179 ShellUtil::CreateChromeDesktopShortcut( | |
199 dist, | 180 dist, |
200 chrome_exe.value(), | 181 chrome_exe.value(), |
201 shortcut_path.value(), | |
202 arguments, | |
203 description, | 182 description, |
204 icon_path.empty() ? chrome_exe.value() : icon_path.value(), | 183 profile_shortcuts_[profile_path].profile_name, |
205 icon_path.empty() ? dist->GetIconIndex() : 0, | 184 profile_shortcuts_[profile_path].flags, |
206 ShellUtil::SHORTCUT_NO_OPTIONS); | 185 shortcut_icon.empty() ? chrome_exe.value() : shortcut_icon.value(), |
186 shortcut_icon.empty() ? dist->GetIconIndex() : 0, | |
187 ShellUtil::CURRENT_USER, | |
188 ShellUtil::SHORTCUT_CREATE_ALWAYS); | |
207 } | 189 } |
208 | 190 |
209 void DeleteAutoLaunchValueForProfile( | 191 void ProfileShortcutManager::DeleteChromeDesktopShortcut( |
210 const FilePath& profile_path) { | 192 const FilePath& profile_path) { |
211 if (auto_launch_util::AutoStartRequested(profile_path.BaseName().value(), | 193 // If the profile to be deleted has a shortcut |
212 true, // Window requested. | 194 if (profile_shortcuts_.count(profile_path)) { |
213 FilePath())) { | 195 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
214 auto_launch_util::DisableForegroundStartAtLogin( | 196 string16 shortcut; |
215 profile_path.BaseName().value()); | 197 // If we can find the shortcut, delete it |
198 if (ShellUtil::GetChromeShortcutName(dist, false, | |
199 profile_shortcuts_[profile_path].profile_name, &shortcut)) { | |
200 std::vector<string16> appended_names(1, shortcut); | |
201 BrowserThread::PostTask( | |
202 BrowserThread::FILE, FROM_HERE, | |
203 base::Bind(&CallShellUtilBoolFunction, base::Bind( | |
204 &ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames, | |
205 appended_names))); | |
206 profile_shortcuts_.erase(profile_path); | |
207 } | |
216 } | 208 } |
217 } | 209 } |
218 | 210 |
219 } // namespace | |
220 | |
221 ProfileShortcutManagerWin::ProfileShortcutManagerWin() { | |
222 } | |
223 | |
224 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { | |
225 } | |
226 | |
227 void ProfileShortcutManagerWin::AddProfileShortcut( | |
228 const FilePath& profile_path) { | |
229 ProfileInfoCache& cache = | |
230 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
231 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | |
232 if (index == std::string::npos) | |
233 return; | |
234 | |
235 // Launch task to add shortcut to desktop on Windows. If this is the very | |
236 // first profile created, don't add the user name to the shortcut. | |
237 // TODO(mirandac): respect master_preferences choice to create no shortcuts | |
238 // (see http://crbug.com/104463) | |
239 if (g_browser_process->profile_manager()->GetNumberOfProfiles() > 1) { | |
240 { | |
241 // We make a copy of the Image to ensure that the underlying image data is | |
242 // AddRef'd, in case the original copy gets deleted. | |
243 gfx::Image* avatar_copy = | |
244 new gfx::Image(cache.GetAvatarIconOfProfileAtIndex(index)); | |
245 string16 profile_name = cache.GetNameOfProfileAtIndex(index); | |
246 string16 profile_base_dir = profile_path.BaseName().value(); | |
247 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
248 base::Bind(&CreateChromeDesktopShortcutForProfile, | |
249 profile_name, profile_base_dir, profile_path, | |
250 base::Owned(avatar_copy), true)); | |
251 } | |
252 | |
253 // If this is the second existing multi-user account created, change the | |
254 // original shortcut use the first profile's details (name, badge, | |
255 // argument). | |
256 if (cache.GetNumberOfProfiles() == 2) { | |
257 // Get the index of the first profile, based on the index of the second | |
258 // profile. It's either 0 or 1, whichever the second profile isn't. | |
259 size_t first_index = 0; | |
260 if (cache.GetIndexOfProfileWithPath(profile_path) == 0) | |
261 first_index = 1; | |
262 string16 first_name = cache.GetNameOfProfileAtIndex(first_index); | |
263 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
264 | |
265 string16 old_shortcut; | |
266 string16 new_shortcut; | |
267 if (ShellUtil::GetChromeShortcutName(dist, false, L"", &old_shortcut) && | |
268 ShellUtil::GetChromeShortcutName(dist, false, first_name, | |
269 &new_shortcut)) { | |
270 // Update doesn't allow changing the target, so rename first. | |
271 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
272 base::Bind(&RenameChromeDesktopShortcutForProfile, | |
273 old_shortcut, new_shortcut)); | |
274 | |
275 // Fetch the avatar for the first profile and make a copy of the Image | |
276 // to ensure that the underlying image data is AddRef'd, in case the | |
277 // original copy is deleted. | |
278 gfx::Image& first_avatar = | |
279 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
280 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex( | |
281 cache.GetAvatarIconIndexOfProfileAtIndex(first_index))); | |
282 gfx::Image* first_avatar_copy = new gfx::Image(first_avatar); | |
283 FilePath first_path = cache.GetPathOfProfileAtIndex(first_index); | |
284 | |
285 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
286 base::Bind(&UpdateChromeDesktopShortcutForProfile, | |
287 new_shortcut, | |
288 CreateProfileShortcutSwitch(UTF8ToUTF16( | |
289 first_path.BaseName().MaybeAsASCII())), | |
290 first_path, | |
291 base::Owned(first_avatar_copy))); | |
292 } | |
293 } | |
294 } else { // Only one profile, so create original shortcut, with no avatar. | |
295 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
296 base::Bind(&CreateChromeDesktopShortcutForProfile, | |
297 string16(), string16(), FilePath(), | |
298 static_cast<gfx::Image*>(NULL), true)); | |
299 } | |
300 } | |
301 | |
302 void ProfileShortcutManagerWin::OnProfileAdded( | |
303 const FilePath& profile_path) { | |
304 } | |
305 | |
306 void ProfileShortcutManagerWin::OnProfileWillBeRemoved( | |
307 const FilePath& profile_path) { | |
308 ProfileInfoCache& cache = | |
309 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
310 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | |
311 if (index == std::string::npos) | |
312 return; | |
313 string16 profile_name = cache.GetNameOfProfileAtIndex(index); | |
314 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
315 string16 shortcut; | |
316 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, &shortcut)) { | |
317 std::vector<string16> shortcuts(1, shortcut); | |
318 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
319 base::Bind(&CallShellUtilBoolFunction, | |
320 base::Bind( | |
321 &ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames, | |
322 shortcuts))); | |
323 } | |
324 } | |
325 | |
326 void ProfileShortcutManagerWin::OnProfileWasRemoved( | |
327 const FilePath& profile_path, | |
328 const string16& profile_name) { | |
329 BrowserThread::PostTask( | |
330 BrowserThread::FILE, FROM_HERE, | |
331 base::Bind(&DeleteAutoLaunchValueForProfile, profile_path)); | |
332 | |
333 // If there is one profile left, we want to remove the badge and name from it. | |
334 ProfileInfoCache& cache = | |
335 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
336 if (cache.GetNumberOfProfiles() != 1) | |
337 return; | |
338 | |
339 FilePath last_profile_path = cache.GetPathOfProfileAtIndex(0); | |
340 string16 old_shortcut; | |
341 string16 new_shortcut; | |
342 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
343 if (ShellUtil::GetChromeShortcutName( | |
344 dist, false, cache.GetNameOfProfileAtIndex(0), &old_shortcut) && | |
345 ShellUtil::GetChromeShortcutName( | |
346 dist, false, L"", &new_shortcut)) { | |
347 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
348 base::Bind(&RenameChromeDesktopShortcutForProfile, | |
349 old_shortcut, | |
350 new_shortcut)); | |
351 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
352 base::Bind(&UpdateChromeDesktopShortcutForProfile, | |
353 new_shortcut, | |
354 CreateProfileShortcutSwitch(UTF8ToUTF16( | |
355 last_profile_path.BaseName().MaybeAsASCII())), | |
356 last_profile_path, | |
357 static_cast<gfx::Image*>(NULL))); | |
358 } | |
359 } | |
360 | |
361 void ProfileShortcutManagerWin::OnProfileNameChanged( | |
362 const FilePath& profile_path, | |
363 const string16& old_profile_name) { | |
364 // Launch task to change name of desktop shortcut on Windows. | |
365 // TODO(mirandac): respect master_preferences choice to create no shortcuts | |
366 // (see http://crbug.com/104463) | |
367 ProfileInfoCache& cache = | |
368 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
369 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | |
370 if (index == std::string::npos) | |
371 return; | |
372 string16 new_profile_name = cache.GetNameOfProfileAtIndex(index); | |
373 | |
374 string16 old_shortcut; | |
375 string16 new_shortcut; | |
376 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
377 if (ShellUtil::GetChromeShortcutName( | |
378 dist, false, old_profile_name, &old_shortcut) && | |
379 ShellUtil::GetChromeShortcutName( | |
380 dist, false, new_profile_name, &new_shortcut)) { | |
381 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
382 base::Bind(&RenameChromeDesktopShortcutForProfile, | |
383 old_shortcut, | |
384 new_shortcut)); | |
385 } | |
386 } | |
387 | |
388 void ProfileShortcutManagerWin::OnProfileAvatarChanged( | |
389 const FilePath& profile_path) { | |
390 ProfileInfoCache& cache = | |
391 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
392 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | |
393 if (index == std::string::npos) | |
394 return; | |
395 string16 profile_name = cache.GetNameOfProfileAtIndex(index); | |
396 string16 profile_base_dir = | |
397 UTF8ToUTF16(profile_path.BaseName().MaybeAsASCII()); | |
398 const gfx::Image& avatar_image = cache.GetAvatarIconOfProfileAtIndex(index); | |
399 | |
400 // Launch task to change the icon of the desktop shortcut on windows. | |
401 string16 new_shortcut; | |
402 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
403 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, | |
404 &new_shortcut)) { | |
405 // We make a copy of the Image to ensure that the underlying image data is | |
406 // AddRef'd, in case the original copy gets deleted. | |
407 gfx::Image* avatar_copy = new gfx::Image(avatar_image); | |
408 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
409 base::Bind(&UpdateChromeDesktopShortcutForProfile, | |
410 new_shortcut, | |
411 CreateProfileShortcutSwitch(profile_base_dir), | |
412 profile_path, | |
413 base::Owned(avatar_copy))); | |
414 } | |
415 } | |
416 | |
417 // static | |
418 std::vector<string16> ProfileShortcutManagerWin::GenerateShortcutsFromProfiles( | |
419 const std::vector<string16>& profile_names) { | |
420 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
421 std::vector<string16> shortcuts; | |
422 shortcuts.reserve(profile_names.size()); | |
423 for (std::vector<string16>::const_iterator it = profile_names.begin(); | |
424 it != profile_names.end(); | |
425 ++it) { | |
426 string16 shortcut; | |
427 if (ShellUtil::GetChromeShortcutName(dist, false, *it, &shortcut)) | |
428 shortcuts.push_back(shortcut); | |
429 } | |
430 return shortcuts; | |
431 } | |
OLD | NEW |