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/installer/setup/install.h" | 5 #include "chrome/installer/setup/install.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 #include <time.h> | 8 #include <time.h> |
9 #include <winuser.h> | 9 #include <winuser.h> |
10 | 10 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 << " to " << src_path.value(); | 249 << " to " << src_path.value(); |
250 return true; | 250 return true; |
251 } else { | 251 } else { |
252 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest | 252 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest |
253 << " to " << src_path.value(); | 253 << " to " << src_path.value(); |
254 return false; | 254 return false; |
255 } | 255 } |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 void CreateOrUpdateStartMenuAndTaskbarShortcuts( | 259 bool CreateOrUpdateStartMenuAndTaskbarShortcuts( |
260 const InstallerState& installer_state, | 260 const InstallerState& installer_state, |
261 const FilePath& setup_exe, | 261 const FilePath& setup_exe, |
262 const Product& product, | 262 const Product& product, |
263 uint32 options) { | 263 uint32 options) { |
264 bool is_successful = true; | |
gab
2012/08/30 20:26:27
nit: We try to avoid is_* in chromium. Please rena
huangs
2012/08/30 20:46:31
Done.
| |
264 // TODO(tommi): Change this function to use WorkItemList. | 265 // TODO(tommi): Change this function to use WorkItemList. |
265 DCHECK(product.is_chrome()); | 266 DCHECK(product.is_chrome()); |
266 | 267 |
267 // Information used for all shortcut types | 268 // Information used for all shortcut types |
268 BrowserDistribution* browser_dist = product.distribution(); | 269 BrowserDistribution* browser_dist = product.distribution(); |
269 const string16 product_name(browser_dist->GetAppShortCutName()); | 270 const string16 product_name(browser_dist->GetAppShortCutName()); |
270 const string16 product_desc(browser_dist->GetAppDescription()); | 271 const string16 product_desc(browser_dist->GetAppDescription()); |
271 // Chrome link target | 272 // Chrome link target |
272 FilePath chrome_exe( | 273 FilePath chrome_exe( |
273 installer_state.target_path().Append(installer::kChromeExe)); | 274 installer_state.target_path().Append(installer::kChromeExe)); |
274 | 275 |
275 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); | 276 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); |
276 const char* operation = create_always ? "Creating" : "Updating"; | 277 const char* operation = create_always ? "Creating" : "Updating"; |
277 | 278 |
278 // Create Start Menu shortcuts. | 279 // Create Start Menu shortcuts. |
279 // The location of Start->Programs->Google Chrome folder | 280 // The location of Start->Programs->Google Chrome folder |
280 FilePath start_menu_folder_path; | 281 FilePath start_menu_folder_path; |
281 int dir_enum = installer_state.system_install() ? | 282 int dir_enum = installer_state.system_install() ? |
282 base::DIR_COMMON_START_MENU : base::DIR_START_MENU; | 283 base::DIR_COMMON_START_MENU : base::DIR_START_MENU; |
283 if (!PathService::Get(dir_enum, &start_menu_folder_path)) { | 284 if (!PathService::Get(dir_enum, &start_menu_folder_path)) { |
284 LOG(ERROR) << "Failed to get start menu path."; | 285 LOG(ERROR) << "Failed to get start menu path."; |
285 return; | 286 return false; |
286 } | 287 } |
287 | 288 |
288 start_menu_folder_path = start_menu_folder_path.Append(product_name); | 289 start_menu_folder_path = start_menu_folder_path.Append(product_name); |
289 | 290 |
290 // Create/update Chrome link (points to chrome.exe) & Uninstall Chrome link | 291 // Create/update Chrome link (points to chrome.exe) & Uninstall Chrome link |
291 // (which points to setup.exe) under |start_menu_folder_path|. | 292 // (which points to setup.exe) under |start_menu_folder_path|. |
292 | 293 |
293 // Chrome link (launches Chrome) | 294 // Chrome link (launches Chrome) |
294 FilePath chrome_link(start_menu_folder_path.Append(product_name + L".lnk")); | 295 FilePath chrome_link(start_menu_folder_path.Append(product_name + L".lnk")); |
295 | 296 |
296 if (create_always && !file_util::PathExists(start_menu_folder_path)) | 297 if (create_always && !file_util::PathExists(start_menu_folder_path)) |
297 file_util::CreateDirectoryW(start_menu_folder_path); | 298 file_util::CreateDirectoryW(start_menu_folder_path); |
298 | 299 |
299 VLOG(1) << operation << " shortcut to " << chrome_exe.value() << " at " | 300 VLOG(1) << operation << " shortcut to " << chrome_exe.value() << " at " |
300 << chrome_link.value(); | 301 << chrome_link.value(); |
301 if (!ShellUtil::UpdateChromeShortcut(browser_dist, chrome_exe.value(), | 302 if (!ShellUtil::UpdateChromeShortcut(browser_dist, chrome_exe.value(), |
302 chrome_link.value(), string16(), product_desc, chrome_exe.value(), | 303 chrome_link.value(), string16(), product_desc, chrome_exe.value(), |
303 browser_dist->GetIconIndex(), options)) { | 304 browser_dist->GetIconIndex(), options)) { |
304 LOG(WARNING) << operation << " shortcut at " << chrome_link.value() | 305 LOG(WARNING) << operation << " shortcut at " << chrome_link.value() |
305 << " failed."; | 306 << " failed."; |
307 is_successful = false; | |
306 } else if (create_always && | 308 } else if (create_always && |
307 base::win::GetVersion() >= base::win::VERSION_WIN7) { | 309 base::win::GetVersion() >= base::win::VERSION_WIN7) { |
308 // If the Start Menu shortcut was successfully created and |create_always|, | 310 // If the Start Menu shortcut was successfully created and |create_always|, |
309 // proceed to pin the Start Menu shortcut to the taskbar on Win7+. | 311 // proceed to pin the Start Menu shortcut to the taskbar on Win7+. |
310 VLOG(1) << "Pinning new shortcut at " << chrome_link.value() | 312 VLOG(1) << "Pinning new shortcut at " << chrome_link.value() |
311 << " to taskbar"; | 313 << " to taskbar"; |
312 if (!file_util::TaskbarPinShortcutLink(chrome_link.value().c_str())) { | 314 if (!file_util::TaskbarPinShortcutLink(chrome_link.value().c_str())) { |
313 LOG(ERROR) << "Failed to pin shortcut to taskbar: " | 315 LOG(ERROR) << "Failed to pin shortcut to taskbar: " |
314 << chrome_link.value(); | 316 << chrome_link.value(); |
315 } | 317 } |
318 is_successful = false; | |
316 } | 319 } |
317 | 320 |
318 // Create/update uninstall link if we are not an MSI install. MSI | 321 // Create/update uninstall link if we are not an MSI install. MSI |
319 // installations are, for the time being, managed only through the | 322 // installations are, for the time being, managed only through the |
320 // Add/Remove Programs dialog. | 323 // Add/Remove Programs dialog. |
321 // TODO(robertshield): We could add a shortcut to msiexec /X {GUID} here. | 324 // TODO(robertshield): We could add a shortcut to msiexec /X {GUID} here. |
322 if (!installer_state.is_msi()) { | 325 if (!installer_state.is_msi()) { |
323 // Uninstall Chrome link | 326 // Uninstall Chrome link |
324 FilePath uninstall_link(start_menu_folder_path.Append( | 327 FilePath uninstall_link(start_menu_folder_path.Append( |
325 browser_dist->GetUninstallLinkName() + L".lnk")); | 328 browser_dist->GetUninstallLinkName() + L".lnk")); |
326 | 329 |
327 CommandLine arguments(CommandLine::NO_PROGRAM); | 330 CommandLine arguments(CommandLine::NO_PROGRAM); |
328 AppendUninstallCommandLineFlags(installer_state, product, &arguments); | 331 AppendUninstallCommandLineFlags(installer_state, product, &arguments); |
329 VLOG(1) << operation << " uninstall link at " << uninstall_link.value(); | 332 VLOG(1) << operation << " uninstall link at " << uninstall_link.value(); |
330 if (!file_util::CreateOrUpdateShortcutLink(setup_exe.value().c_str(), | 333 if (!file_util::CreateOrUpdateShortcutLink(setup_exe.value().c_str(), |
331 uninstall_link.value().c_str(), NULL, | 334 uninstall_link.value().c_str(), NULL, |
332 arguments.GetCommandLineString().c_str(), NULL, | 335 arguments.GetCommandLineString().c_str(), NULL, |
333 setup_exe.value().c_str(), 0, NULL, | 336 setup_exe.value().c_str(), 0, NULL, |
334 create_always ? file_util::SHORTCUT_CREATE_ALWAYS : | 337 create_always ? file_util::SHORTCUT_CREATE_ALWAYS : |
335 file_util::SHORTCUT_NO_OPTIONS)) { | 338 file_util::SHORTCUT_NO_OPTIONS)) { |
336 LOG(WARNING) << operation << " uninstall link at " | 339 LOG(WARNING) << operation << " uninstall link at " |
337 << uninstall_link.value() << " failed."; | 340 << uninstall_link.value() << " failed."; |
341 is_successful = false; | |
338 } | 342 } |
339 } | 343 } |
344 return is_successful; | |
340 } | 345 } |
341 | 346 |
342 void CreateOrUpdateDesktopAndQuickLaunchShortcuts( | 347 bool CreateOrUpdateDesktopAndQuickLaunchShortcuts( |
343 const InstallerState& installer_state, | 348 const InstallerState& installer_state, |
344 const Product& product, | 349 const Product& product, |
345 uint32 options) { | 350 uint32 options) { |
351 bool is_successful = true; | |
gab
2012/08/30 20:26:28
nit: same here
huangs
2012/08/30 20:46:31
Done.
| |
346 // TODO(tommi): Change this function to use WorkItemList. | 352 // TODO(tommi): Change this function to use WorkItemList. |
347 DCHECK(product.is_chrome()); | 353 DCHECK(product.is_chrome()); |
348 | 354 |
349 // Information used for all shortcut types | 355 // Information used for all shortcut types |
350 BrowserDistribution* browser_dist = product.distribution(); | 356 BrowserDistribution* browser_dist = product.distribution(); |
351 const string16 product_name(browser_dist->GetAppShortCutName()); | 357 const string16 product_name(browser_dist->GetAppShortCutName()); |
352 const string16 product_desc(browser_dist->GetAppDescription()); | 358 const string16 product_desc(browser_dist->GetAppDescription()); |
353 // Chrome link target | 359 // Chrome link target |
354 FilePath chrome_exe( | 360 FilePath chrome_exe( |
355 installer_state.target_path().Append(installer::kChromeExe)); | 361 installer_state.target_path().Append(installer::kChromeExe)); |
356 | 362 |
357 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); | 363 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); |
358 const char* operation = create_always ? "Creating" : "Updating"; | 364 const char* operation = create_always ? "Creating" : "Updating"; |
359 | 365 |
360 ShellUtil::ShellChange desktop_level = ShellUtil::CURRENT_USER; | 366 ShellUtil::ShellChange desktop_level = ShellUtil::CURRENT_USER; |
361 int quick_launch_levels = ShellUtil::CURRENT_USER; | 367 int quick_launch_levels = ShellUtil::CURRENT_USER; |
362 if (installer_state.system_install()) { | 368 if (installer_state.system_install()) { |
363 desktop_level = ShellUtil::SYSTEM_LEVEL; | 369 desktop_level = ShellUtil::SYSTEM_LEVEL; |
364 quick_launch_levels |= ShellUtil::SYSTEM_LEVEL; | 370 quick_launch_levels |= ShellUtil::SYSTEM_LEVEL; |
365 } | 371 } |
366 | 372 |
367 VLOG(1) << operation << " desktop shortcut for " << chrome_exe.value(); | 373 VLOG(1) << operation << " desktop shortcut for " << chrome_exe.value(); |
368 if (!ShellUtil::CreateChromeDesktopShortcut( | 374 if (!ShellUtil::CreateChromeDesktopShortcut( |
369 browser_dist, chrome_exe.value(), product_desc, string16(), | 375 browser_dist, chrome_exe.value(), product_desc, string16(), |
370 string16(), chrome_exe.value(), browser_dist->GetIconIndex(), | 376 string16(), chrome_exe.value(), browser_dist->GetIconIndex(), |
371 desktop_level, options)) { | 377 desktop_level, options)) { |
372 LOG(WARNING) << operation << " desktop shortcut for " << chrome_exe.value() | 378 LOG(WARNING) << operation << " desktop shortcut for " << chrome_exe.value() |
373 << " failed."; | 379 << " failed."; |
380 is_successful = false; | |
374 } | 381 } |
375 | 382 |
376 VLOG(1) << operation << " quick launch shortcut for " << chrome_exe.value(); | 383 VLOG(1) << operation << " quick launch shortcut for " << chrome_exe.value(); |
377 if (!ShellUtil::CreateChromeQuickLaunchShortcut( | 384 if (!ShellUtil::CreateChromeQuickLaunchShortcut( |
378 browser_dist, chrome_exe.value(), quick_launch_levels, options)) { | 385 browser_dist, chrome_exe.value(), quick_launch_levels, options)) { |
379 LOG(WARNING) << operation << " quick launch shortcut for " | 386 LOG(WARNING) << operation << " quick launch shortcut for " |
380 << chrome_exe.value() << " failed."; | 387 << chrome_exe.value() << " failed."; |
388 is_successful = false; | |
381 } | 389 } |
390 return is_successful; | |
382 } | 391 } |
383 | 392 |
384 void RegisterChromeOnMachine(const InstallerState& installer_state, | 393 void RegisterChromeOnMachine(const InstallerState& installer_state, |
385 const Product& product, | 394 const Product& product, |
386 bool make_chrome_default) { | 395 bool make_chrome_default) { |
387 DCHECK(product.is_chrome()); | 396 DCHECK(product.is_chrome()); |
388 | 397 |
389 // Try to add Chrome to Media Player shim inclusion list. We don't do any | 398 // Try to add Chrome to Media Player shim inclusion list. We don't do any |
390 // error checking here because this operation will fail if user doesn't | 399 // error checking here because this operation will fail if user doesn't |
391 // have admin rights and we want to ignore the error. | 400 // have admin rights and we want to ignore the error. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 | 554 |
546 installer_state.RemoveOldVersionDirectories( | 555 installer_state.RemoveOldVersionDirectories( |
547 new_version, | 556 new_version, |
548 existing_version.get(), | 557 existing_version.get(), |
549 install_temp_path); | 558 install_temp_path); |
550 } | 559 } |
551 | 560 |
552 return result; | 561 return result; |
553 } | 562 } |
554 | 563 |
564 bool HandleOsUpgradeForBrowser(const InstallerState& installer_state, | |
565 const Product& chrome, | |
566 const FilePath& setup_exe) { | |
567 DCHECK(chrome.is_chrome()); | |
568 bool is_successful = true; | |
gab
2012/08/30 20:26:28
nit: and here
huangs
2012/08/30 20:46:31
Done.
| |
569 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register | |
570 // Chrome, so that Metro Chrome would work if Chrome is the default browser. | |
571 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | |
572 VLOG(1) << "Updating and registering shortcuts."; | |
573 uint32 shortcut_options = ShellUtil::SHORTCUT_DUAL_MODE; | |
574 if (!CreateOrUpdateDesktopAndQuickLaunchShortcuts( | |
575 installer_state, chrome, shortcut_options)) { | |
576 is_successful = false; | |
577 } | |
578 if (!CreateOrUpdateStartMenuAndTaskbarShortcuts( | |
gab
2012/08/30 20:26:28
Unify the ifs, i.e. if (!1 || !2 || !3) {}
huangs
2012/08/30 20:46:31
Discussed: Doing success = fun() && success; inste
| |
579 installer_state, setup_exe, chrome, shortcut_options)) { | |
580 is_successful = false; | |
581 } | |
582 RegisterChromeOnMachine(installer_state, chrome, false); | |
gab
2012/08/30 20:26:28
Add this call to the list of possible failures too
| |
583 } | |
584 return is_successful; | |
585 } | |
586 | |
555 } // namespace installer | 587 } // namespace installer |
OLD | NEW |