Chromium Code Reviews| 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/shell_integration_win.h" | 5 #include "chrome/browser/shell_integration_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <objbase.h> | 8 #include <objbase.h> |
| 9 #include <shlwapi.h> | 9 #include <shlwapi.h> |
| 10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
| 26 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
| 27 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
| 28 #include "base/metrics/histogram_macros.h" | 28 #include "base/metrics/histogram_macros.h" |
| 29 #include "base/metrics/user_metrics.h" | 29 #include "base/metrics/user_metrics.h" |
| 30 #include "base/metrics/user_metrics_action.h" | 30 #include "base/metrics/user_metrics_action.h" |
| 31 #include "base/path_service.h" | 31 #include "base/path_service.h" |
| 32 #include "base/strings/string_util.h" | 32 #include "base/strings/string_util.h" |
| 33 #include "base/strings/stringprintf.h" | 33 #include "base/strings/stringprintf.h" |
| 34 #include "base/strings/utf_string_conversions.h" | 34 #include "base/strings/utf_string_conversions.h" |
| 35 #include "base/task_scheduler/post_task.h" | |
| 35 #include "base/time/time.h" | 36 #include "base/time/time.h" |
| 36 #include "base/timer/timer.h" | 37 #include "base/timer/timer.h" |
| 37 #include "base/win/registry.h" | 38 #include "base/win/registry.h" |
| 38 #include "base/win/scoped_comptr.h" | 39 #include "base/win/scoped_comptr.h" |
| 39 #include "base/win/scoped_propvariant.h" | 40 #include "base/win/scoped_propvariant.h" |
| 40 #include "base/win/shortcut.h" | 41 #include "base/win/shortcut.h" |
| 41 #include "base/win/windows_version.h" | 42 #include "base/win/windows_version.h" |
| 42 #include "chrome/browser/policy/policy_path_parser.h" | 43 #include "chrome/browser/policy/policy_path_parser.h" |
| 43 #include "chrome/browser/shell_integration.h" | 44 #include "chrome/browser/shell_integration.h" |
| 44 #include "chrome/browser/web_applications/web_app.h" | 45 #include "chrome/browser/web_applications/web_app.h" |
| 45 #include "chrome/browser/win/settings_app_monitor.h" | 46 #include "chrome/browser/win/settings_app_monitor.h" |
| 46 #include "chrome/common/chrome_constants.h" | 47 #include "chrome/common/chrome_constants.h" |
| 47 #include "chrome/common/chrome_paths_internal.h" | 48 #include "chrome/common/chrome_paths_internal.h" |
| 48 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
| 49 #include "chrome/common/shell_handler_win.mojom.h" | 50 #include "chrome/common/shell_handler_win.mojom.h" |
| 50 #include "chrome/grit/generated_resources.h" | 51 #include "chrome/grit/generated_resources.h" |
| 51 #include "chrome/install_static/install_util.h" | 52 #include "chrome/install_static/install_util.h" |
| 52 #include "chrome/installer/util/browser_distribution.h" | 53 #include "chrome/installer/util/browser_distribution.h" |
| 53 #include "chrome/installer/util/install_util.h" | 54 #include "chrome/installer/util/install_util.h" |
| 54 #include "chrome/installer/util/scoped_user_protocol_entry.h" | 55 #include "chrome/installer/util/scoped_user_protocol_entry.h" |
| 55 #include "chrome/installer/util/shell_util.h" | 56 #include "chrome/installer/util/shell_util.h" |
| 56 #include "components/variations/variations_associated_data.h" | 57 #include "components/variations/variations_associated_data.h" |
| 57 #include "content/public/browser/browser_thread.h" | |
| 58 #include "content/public/browser/utility_process_mojo_client.h" | 58 #include "content/public/browser/utility_process_mojo_client.h" |
| 59 #include "ui/base/l10n/l10n_util.h" | 59 #include "ui/base/l10n/l10n_util.h" |
| 60 | 60 |
| 61 using content::BrowserThread; | |
| 62 | |
| 63 namespace shell_integration { | 61 namespace shell_integration { |
| 64 | 62 |
| 65 namespace { | 63 namespace { |
| 66 | 64 |
| 67 // Helper function for GetAppId to generates profile id | 65 // Helper function for GetAppId to generates profile id |
| 68 // from profile path. "profile_id" is composed of sanitized basenames of | 66 // from profile path. "profile_id" is composed of sanitized basenames of |
| 69 // user data dir and profile dir joined by a ".". | 67 // user data dir and profile dir joined by a ".". |
| 70 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { | 68 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { |
| 71 // Return empty string if profile_path is empty | 69 // Return empty string if profile_path is empty |
| 72 if (profile_path.empty()) | 70 if (profile_path.empty()) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 app_name = GetAppListAppName(); | 141 app_name = GetAppListAppName(); |
| 144 } else { | 142 } else { |
| 145 app_name = ShellUtil::GetBrowserModelId(is_per_user_install); | 143 app_name = ShellUtil::GetBrowserModelId(is_per_user_install); |
| 146 } | 144 } |
| 147 DCHECK(!app_name.empty()); | 145 DCHECK(!app_name.empty()); |
| 148 | 146 |
| 149 return win::GetAppModelIdForProfile(app_name, profile_path); | 147 return win::GetAppModelIdForProfile(app_name, profile_path); |
| 150 } | 148 } |
| 151 | 149 |
| 152 void MigrateTaskbarPinsCallback() { | 150 void MigrateTaskbarPinsCallback() { |
| 153 // This should run on the file thread. | 151 base::ThreadRestrictions::AssertIOAllowed(); |
| 154 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 155 | 152 |
| 156 // Get full path of chrome. | 153 // Get full path of chrome. |
| 157 base::FilePath chrome_exe; | 154 base::FilePath chrome_exe; |
| 158 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | 155 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
| 159 return; | 156 return; |
| 160 | 157 |
| 161 base::FilePath pins_path; | 158 base::FilePath pins_path; |
| 162 if (!PathService::Get(base::DIR_TASKBAR_PINS, &pins_path)) { | 159 if (!PathService::Get(base::DIR_TASKBAR_PINS, &pins_path)) { |
| 163 NOTREACHED(); | 160 NOTREACHED(); |
| 164 return; | 161 return; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 // This helper class manages both the timer and the registry watchers and makes | 318 // This helper class manages both the timer and the registry watchers and makes |
| 322 // sure the callback for the end of the settings interaction is only run once. | 319 // sure the callback for the end of the settings interaction is only run once. |
| 323 // This class also manages its own lifetime. | 320 // This class also manages its own lifetime. |
| 324 class OpenSystemSettingsHelper { | 321 class OpenSystemSettingsHelper { |
| 325 public: | 322 public: |
| 326 // Begin the monitoring and will call |on_finished_callback| when done. | 323 // Begin the monitoring and will call |on_finished_callback| when done. |
| 327 // Takes in a null-terminated array of |protocols| whose registry keys must be | 324 // Takes in a null-terminated array of |protocols| whose registry keys must be |
| 328 // watched. The array must contain at least one element. | 325 // watched. The array must contain at least one element. |
| 329 static void Begin(const wchar_t* const protocols[], | 326 static void Begin(const wchar_t* const protocols[], |
| 330 const base::Closure& on_finished_callback) { | 327 const base::Closure& on_finished_callback) { |
| 331 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 328 base::ThreadRestrictions::AssertIOAllowed(); |
| 332 | 329 |
| 333 delete instance_; | 330 delete instance_; |
| 334 instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback); | 331 instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback); |
| 335 } | 332 } |
| 336 | 333 |
| 337 private: | 334 private: |
| 338 // The reason the settings interaction concluded. Do not modify the ordering | 335 // The reason the settings interaction concluded. Do not modify the ordering |
| 339 // because it is used for UMA. | 336 // because it is used for UMA. |
| 340 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; | 337 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; |
| 341 | 338 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 357 } | 354 } |
| 358 // Only the watchers that were succesfully initialized are counted. | 355 // Only the watchers that were succesfully initialized are counted. |
| 359 registry_watcher_count_ = registry_key_watchers_.size(); | 356 registry_watcher_count_ = registry_key_watchers_.size(); |
| 360 | 357 |
| 361 timer_.Start( | 358 timer_.Start( |
| 362 FROM_HERE, base::TimeDelta::FromMinutes(2), | 359 FROM_HERE, base::TimeDelta::FromMinutes(2), |
| 363 base::Bind(&OpenSystemSettingsHelper::ConcludeInteraction, | 360 base::Bind(&OpenSystemSettingsHelper::ConcludeInteraction, |
| 364 weak_ptr_factory_.GetWeakPtr(), ConcludeReason::TIMEOUT)); | 361 weak_ptr_factory_.GetWeakPtr(), ConcludeReason::TIMEOUT)); |
| 365 } | 362 } |
| 366 | 363 |
| 364 ~OpenSystemSettingsHelper() { | |
| 365 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
| 366 } | |
| 367 | |
| 367 // Called when a change is detected on one of the registry keys being watched. | 368 // Called when a change is detected on one of the registry keys being watched. |
| 368 // Note: All types of modification to the registry key will trigger this | 369 // Note: All types of modification to the registry key will trigger this |
| 369 // function even if the value change is the only one that matters. This | 370 // function even if the value change is the only one that matters. This |
| 370 // is good enough for now. | 371 // is good enough for now. |
| 371 void OnRegistryKeyChanged() { | 372 void OnRegistryKeyChanged() { |
| 372 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 373 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 373 | |
| 374 // Make sure all the registry watchers have fired. | 374 // Make sure all the registry watchers have fired. |
| 375 if (--registry_watcher_count_ == 0) { | 375 if (--registry_watcher_count_ == 0) { |
| 376 UMA_HISTOGRAM_MEDIUM_TIMES( | 376 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 377 "DefaultBrowser.SettingsInteraction.RegistryWatcherDuration", | 377 "DefaultBrowser.SettingsInteraction.RegistryWatcherDuration", |
| 378 base::TimeTicks::Now() - start_time_); | 378 base::TimeTicks::Now() - start_time_); |
| 379 | 379 |
| 380 ConcludeInteraction(ConcludeReason::REGISTRY_WATCHER); | 380 ConcludeInteraction(ConcludeReason::REGISTRY_WATCHER); |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 // Ends the monitoring with the system settings. Will call | 384 // Ends the monitoring with the system settings. Will call |
| 385 // |on_finished_callback_| and then dispose of this class instance to make | 385 // |on_finished_callback_| and then dispose of this class instance to make |
| 386 // sure the callback won't get called subsequently. | 386 // sure the callback won't get called subsequently. |
| 387 void ConcludeInteraction(ConcludeReason conclude_reason) { | 387 void ConcludeInteraction(ConcludeReason conclude_reason) { |
| 388 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 388 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 389 | 389 |
| 390 UMA_HISTOGRAM_ENUMERATION( | 390 UMA_HISTOGRAM_ENUMERATION( |
| 391 "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason, | 391 "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason, |
| 392 NUM_CONCLUDE_REASON_TYPES); | 392 NUM_CONCLUDE_REASON_TYPES); |
| 393 on_finished_callback_.Run(); | 393 on_finished_callback_.Run(); |
| 394 delete instance_; | 394 delete instance_; |
| 395 instance_ = nullptr; | 395 instance_ = nullptr; |
| 396 } | 396 } |
| 397 | 397 |
| 398 // Helper function to create a registry watcher for a given |key_path|. Do | 398 // Helper function to create a registry watcher for a given |key_path|. Do |
| 399 // nothing on initialization failure. | 399 // nothing on initialization failure. |
| 400 void AddRegistryKeyWatcher(const wchar_t* key_path) { | 400 void AddRegistryKeyWatcher(const wchar_t* key_path) { |
| 401 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
| 402 | |
| 401 auto reg_key = base::MakeUnique<base::win::RegKey>(HKEY_CURRENT_USER, | 403 auto reg_key = base::MakeUnique<base::win::RegKey>(HKEY_CURRENT_USER, |
| 402 key_path, KEY_NOTIFY); | 404 key_path, KEY_NOTIFY); |
| 403 | 405 |
| 404 if (reg_key->Valid() && | 406 if (reg_key->Valid() && |
| 405 reg_key->StartWatching( | 407 reg_key->StartWatching( |
| 406 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged, | 408 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged, |
| 407 weak_ptr_factory_.GetWeakPtr()))) { | 409 weak_ptr_factory_.GetWeakPtr()))) { |
| 408 registry_key_watchers_.push_back(std::move(reg_key)); | 410 registry_key_watchers_.push_back(std::move(reg_key)); |
| 409 } | 411 } |
| 410 } | 412 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 426 // There can be multiple registry key watchers as some settings modify | 428 // There can be multiple registry key watchers as some settings modify |
| 427 // multiple protocol associations. e.g. Changing the default browser modifies | 429 // multiple protocol associations. e.g. Changing the default browser modifies |
| 428 // the http and https associations. | 430 // the http and https associations. |
| 429 std::vector<std::unique_ptr<base::win::RegKey>> registry_key_watchers_; | 431 std::vector<std::unique_ptr<base::win::RegKey>> registry_key_watchers_; |
| 430 | 432 |
| 431 base::OneShotTimer timer_; | 433 base::OneShotTimer timer_; |
| 432 | 434 |
| 433 // Records the time it takes for the final registry watcher to get signaled. | 435 // Records the time it takes for the final registry watcher to get signaled. |
| 434 base::TimeTicks start_time_; | 436 base::TimeTicks start_time_; |
| 435 | 437 |
| 438 SEQUENCE_CHECKER(sequence_checker_); | |
| 439 | |
| 436 // Weak ptrs are used to bind this class to the callbacks of the timer and the | 440 // Weak ptrs are used to bind this class to the callbacks of the timer and the |
| 437 // registry watcher. This makes it possible to self-delete after one of the | 441 // registry watcher. This makes it possible to self-delete after one of the |
| 438 // callbacks is executed to cancel the remaining ones. | 442 // callbacks is executed to cancel the remaining ones. |
| 439 base::WeakPtrFactory<OpenSystemSettingsHelper> weak_ptr_factory_; | 443 base::WeakPtrFactory<OpenSystemSettingsHelper> weak_ptr_factory_; |
| 440 | 444 |
| 441 DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper); | 445 DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper); |
| 442 }; | 446 }; |
| 443 | 447 |
| 444 OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr; | 448 OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr; |
| 445 | 449 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 457 const ResultCallback& result_callback); | 461 const ResultCallback& result_callback); |
| 458 | 462 |
| 459 void OnConnectionError(); | 463 void OnConnectionError(); |
| 460 void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar); | 464 void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar); |
| 461 | 465 |
| 462 content::UtilityProcessMojoClient<chrome::mojom::ShellHandler> shell_handler_; | 466 content::UtilityProcessMojoClient<chrome::mojom::ShellHandler> shell_handler_; |
| 463 | 467 |
| 464 ErrorCallback error_callback_; | 468 ErrorCallback error_callback_; |
| 465 ResultCallback result_callback_; | 469 ResultCallback result_callback_; |
| 466 | 470 |
| 471 SEQUENCE_CHECKER(sequence_checker_); | |
| 472 | |
| 467 DISALLOW_COPY_AND_ASSIGN(IsPinnedToTaskbarHelper); | 473 DISALLOW_COPY_AND_ASSIGN(IsPinnedToTaskbarHelper); |
| 468 }; | 474 }; |
| 469 | 475 |
| 470 // static | 476 // static |
| 471 void IsPinnedToTaskbarHelper::GetState(const ErrorCallback& error_callback, | 477 void IsPinnedToTaskbarHelper::GetState(const ErrorCallback& error_callback, |
| 472 const ResultCallback& result_callback) { | 478 const ResultCallback& result_callback) { |
| 473 // Self-deleting when the ShellHandler completes. | 479 // Self-deleting when the ShellHandler completes. |
| 474 new IsPinnedToTaskbarHelper(error_callback, result_callback); | 480 new IsPinnedToTaskbarHelper(error_callback, result_callback); |
| 475 } | 481 } |
| 476 | 482 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 490 &IsPinnedToTaskbarHelper::OnConnectionError, base::Unretained(this))); | 496 &IsPinnedToTaskbarHelper::OnConnectionError, base::Unretained(this))); |
| 491 shell_handler_.set_disable_sandbox(); | 497 shell_handler_.set_disable_sandbox(); |
| 492 shell_handler_.Start(); | 498 shell_handler_.Start(); |
| 493 | 499 |
| 494 shell_handler_.service()->IsPinnedToTaskbar( | 500 shell_handler_.service()->IsPinnedToTaskbar( |
| 495 base::Bind(&IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult, | 501 base::Bind(&IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult, |
| 496 base::Unretained(this))); | 502 base::Unretained(this))); |
| 497 } | 503 } |
| 498 | 504 |
| 499 void IsPinnedToTaskbarHelper::OnConnectionError() { | 505 void IsPinnedToTaskbarHelper::OnConnectionError() { |
| 506 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
| 507 | |
| 500 error_callback_.Run(); | 508 error_callback_.Run(); |
| 501 delete this; | 509 delete this; |
| 502 } | 510 } |
| 503 | 511 |
| 504 void IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult( | 512 void IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult( |
| 505 bool succeeded, | 513 bool succeeded, |
| 506 bool is_pinned_to_taskbar) { | 514 bool is_pinned_to_taskbar) { |
| 515 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
| 516 | |
| 507 result_callback_.Run(succeeded, is_pinned_to_taskbar); | 517 result_callback_.Run(succeeded, is_pinned_to_taskbar); |
| 508 delete this; | 518 delete this; |
| 509 } | 519 } |
| 510 | 520 |
| 511 } // namespace | 521 } // namespace |
| 512 | 522 |
| 513 bool SetAsDefaultBrowser() { | 523 bool SetAsDefaultBrowser() { |
| 524 base::ThreadRestrictions::AssertIOAllowed(); | |
| 525 | |
| 514 base::FilePath chrome_exe; | 526 base::FilePath chrome_exe; |
| 515 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 527 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 516 LOG(ERROR) << "Error getting app exe path"; | 528 LOG(ERROR) << "Error getting app exe path"; |
| 517 return false; | 529 return false; |
| 518 } | 530 } |
| 519 | 531 |
| 520 // From UI currently we only allow setting default browser for current user. | 532 // From UI currently we only allow setting default browser for current user. |
| 521 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 533 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 522 if (!ShellUtil::MakeChromeDefault(dist, ShellUtil::CURRENT_USER, chrome_exe, | 534 if (!ShellUtil::MakeChromeDefault(dist, ShellUtil::CURRENT_USER, chrome_exe, |
| 523 true /* elevate_if_not_admin */)) { | 535 true /* elevate_if_not_admin */)) { |
| 524 LOG(ERROR) << "Chrome could not be set as default browser."; | 536 LOG(ERROR) << "Chrome could not be set as default browser."; |
| 525 return false; | 537 return false; |
| 526 } | 538 } |
| 527 | 539 |
| 528 VLOG(1) << "Chrome registered as default browser."; | 540 VLOG(1) << "Chrome registered as default browser."; |
| 529 return true; | 541 return true; |
| 530 } | 542 } |
| 531 | 543 |
| 532 bool SetAsDefaultProtocolClient(const std::string& protocol) { | 544 bool SetAsDefaultProtocolClient(const std::string& protocol) { |
| 545 base::ThreadRestrictions::AssertIOAllowed(); | |
| 546 | |
| 533 if (protocol.empty()) | 547 if (protocol.empty()) |
| 534 return false; | 548 return false; |
| 535 | 549 |
| 536 base::FilePath chrome_exe; | 550 base::FilePath chrome_exe; |
| 537 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 551 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 538 LOG(ERROR) << "Error getting app exe path"; | 552 LOG(ERROR) << "Error getting app exe path"; |
| 539 return false; | 553 return false; |
| 540 } | 554 } |
| 541 | 555 |
| 542 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); | 556 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 | 632 |
| 619 DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) { | 633 DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) { |
| 620 return GetDefaultWebClientStateFromShellUtilDefaultState( | 634 return GetDefaultWebClientStateFromShellUtilDefaultState( |
| 621 ShellUtil::GetChromeDefaultProtocolClientState( | 635 ShellUtil::GetChromeDefaultProtocolClientState( |
| 622 base::UTF8ToUTF16(protocol))); | 636 base::UTF8ToUTF16(protocol))); |
| 623 } | 637 } |
| 624 | 638 |
| 625 namespace win { | 639 namespace win { |
| 626 | 640 |
| 627 bool SetAsDefaultBrowserUsingIntentPicker() { | 641 bool SetAsDefaultBrowserUsingIntentPicker() { |
| 642 base::ThreadRestrictions::AssertIOAllowed(); | |
| 643 | |
| 628 base::FilePath chrome_exe; | 644 base::FilePath chrome_exe; |
| 629 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 645 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 630 NOTREACHED() << "Error getting app exe path"; | 646 NOTREACHED() << "Error getting app exe path"; |
| 631 return false; | 647 return false; |
| 632 } | 648 } |
| 633 | 649 |
| 634 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 650 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 635 if (!ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe)) { | 651 if (!ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe)) { |
| 636 LOG(ERROR) << "Failed to launch the set-default-browser Windows UI."; | 652 LOG(ERROR) << "Failed to launch the set-default-browser Windows UI."; |
| 637 return false; | 653 return false; |
| 638 } | 654 } |
| 639 | 655 |
| 640 VLOG(1) << "Set-default-browser Windows UI completed."; | 656 VLOG(1) << "Set-default-browser Windows UI completed."; |
| 641 return true; | 657 return true; |
| 642 } | 658 } |
| 643 | 659 |
| 644 void SetAsDefaultBrowserUsingSystemSettings( | 660 void SetAsDefaultBrowserUsingSystemSettings( |
| 645 const base::Closure& on_finished_callback) { | 661 const base::Closure& on_finished_callback) { |
| 646 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 662 base::ThreadRestrictions::AssertIOAllowed(); |
| 647 | 663 |
| 648 base::FilePath chrome_exe; | 664 base::FilePath chrome_exe; |
| 649 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 665 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 650 NOTREACHED() << "Error getting app exe path"; | 666 NOTREACHED() << "Error getting app exe path"; |
| 651 on_finished_callback.Run(); | 667 on_finished_callback.Run(); |
| 652 return; | 668 return; |
| 653 } | 669 } |
| 654 | 670 |
| 655 // Create an action recorder that will open the settings app once it has | 671 // Create an action recorder that will open the settings app once it has |
| 656 // initialized. | 672 // initialized. |
| 657 std::unique_ptr<DefaultBrowserActionRecorder> recorder( | 673 std::unique_ptr<DefaultBrowserActionRecorder> recorder( |
| 658 new DefaultBrowserActionRecorder(base::Bind( | 674 new DefaultBrowserActionRecorder(base::Bind( |
| 659 base::IgnoreResult(&ShellUtil::ShowMakeChromeDefaultSystemUI), | 675 base::IgnoreResult(&ShellUtil::ShowMakeChromeDefaultSystemUI), |
| 660 base::Unretained(BrowserDistribution::GetDistribution()), | 676 base::Unretained(BrowserDistribution::GetDistribution()), |
| 661 chrome_exe))); | 677 chrome_exe))); |
| 662 | 678 |
| 663 // The helper manages its own lifetime. Bind the action recorder | 679 // The helper manages its own lifetime. Bind the action recorder |
| 664 // into the finished callback to keep it alive throughout the | 680 // into the finished callback to keep it alive throughout the |
| 665 // interaction. | 681 // interaction. |
| 666 static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr}; | 682 static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr}; |
| 667 OpenSystemSettingsHelper::Begin( | 683 OpenSystemSettingsHelper::Begin( |
| 668 kProtocols, base::Bind(&OnSettingsAppFinished, base::Passed(&recorder), | 684 kProtocols, base::Bind(&OnSettingsAppFinished, base::Passed(&recorder), |
| 669 on_finished_callback)); | 685 on_finished_callback)); |
| 670 } | 686 } |
| 671 | 687 |
| 672 bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) { | 688 bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) { |
| 689 base::ThreadRestrictions::AssertIOAllowed(); | |
| 690 | |
| 673 base::FilePath chrome_exe; | 691 base::FilePath chrome_exe; |
| 674 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 692 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 675 NOTREACHED() << "Error getting app exe path"; | 693 NOTREACHED() << "Error getting app exe path"; |
| 676 return false; | 694 return false; |
| 677 } | 695 } |
| 678 | 696 |
| 679 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 697 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 680 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); | 698 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
| 681 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, | 699 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, |
| 682 wprotocol)) { | 700 wprotocol)) { |
| 683 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; | 701 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; |
| 684 return false; | 702 return false; |
| 685 } | 703 } |
| 686 | 704 |
| 687 VLOG(1) << "Set-default-client Windows UI completed."; | 705 VLOG(1) << "Set-default-client Windows UI completed."; |
| 688 return true; | 706 return true; |
| 689 } | 707 } |
| 690 | 708 |
| 691 void SetAsDefaultProtocolClientUsingSystemSettings( | 709 void SetAsDefaultProtocolClientUsingSystemSettings( |
| 692 const std::string& protocol, | 710 const std::string& protocol, |
| 693 const base::Closure& on_finished_callback) { | 711 const base::Closure& on_finished_callback) { |
| 694 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 712 base::ThreadRestrictions::AssertIOAllowed(); |
| 695 | 713 |
| 696 base::FilePath chrome_exe; | 714 base::FilePath chrome_exe; |
| 697 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 715 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 698 NOTREACHED() << "Error getting app exe path"; | 716 NOTREACHED() << "Error getting app exe path"; |
| 699 on_finished_callback.Run(); | 717 on_finished_callback.Run(); |
| 700 return; | 718 return; |
| 701 } | 719 } |
| 702 | 720 |
| 703 // The helper manages its own lifetime. | 721 // The helper manages its own lifetime. |
| 704 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); | 722 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 722 | 740 |
| 723 base::string16 GetChromiumModelIdForProfile( | 741 base::string16 GetChromiumModelIdForProfile( |
| 724 const base::FilePath& profile_path) { | 742 const base::FilePath& profile_path) { |
| 725 return GetAppModelIdForProfile( | 743 return GetAppModelIdForProfile( |
| 726 ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall()), | 744 ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall()), |
| 727 profile_path); | 745 profile_path); |
| 728 } | 746 } |
| 729 | 747 |
| 730 void MigrateTaskbarPins() { | 748 void MigrateTaskbarPins() { |
| 731 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 749 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 732 return; | 750 return; |
|
gab
2017/05/26 18:44:06
Can we remove this check while you're here, we onl
Patrick Monette
2017/05/29 18:54:14
Will do in another CL
| |
| 733 | 751 |
| 734 // This needs to happen eventually (e.g. so that the appid is fixed and the | 752 // This needs to happen (e.g. so that the appid is fixed and the |
| 735 // run-time Chrome icon is merged with the taskbar shortcut), but this is not | 753 // run-time Chrome icon is merged with the taskbar shortcut), but it is not an |
| 736 // urgent and shouldn't delay Chrome startup. | 754 // urgent task. |
| 737 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; | 755 base::PostTaskWithTraits(FROM_HERE, |
| 738 BrowserThread::PostDelayedTask( | 756 {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 739 BrowserThread::FILE, FROM_HERE, | 757 base::Bind(&MigrateTaskbarPinsCallback)); |
| 740 base::Bind(&MigrateTaskbarPinsCallback), | |
| 741 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); | |
| 742 } | 758 } |
| 743 | 759 |
| 744 void GetIsPinnedToTaskbarState( | 760 void GetIsPinnedToTaskbarState( |
| 745 const ConnectionErrorCallback& on_error_callback, | 761 const ConnectionErrorCallback& on_error_callback, |
| 746 const IsPinnedToTaskbarCallback& result_callback) { | 762 const IsPinnedToTaskbarCallback& result_callback) { |
| 747 IsPinnedToTaskbarHelper::GetState(on_error_callback, result_callback); | 763 IsPinnedToTaskbarHelper::GetState(on_error_callback, result_callback); |
| 748 } | 764 } |
| 749 | 765 |
| 750 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, | 766 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, |
| 751 const base::FilePath& path) { | 767 const base::FilePath& path) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 base::win::SHORTCUT_UPDATE_EXISTING)) { | 866 base::win::SHORTCUT_UPDATE_EXISTING)) { |
| 851 ++shortcuts_migrated; | 867 ++shortcuts_migrated; |
| 852 } | 868 } |
| 853 } | 869 } |
| 854 return shortcuts_migrated; | 870 return shortcuts_migrated; |
| 855 } | 871 } |
| 856 | 872 |
| 857 } // namespace win | 873 } // namespace win |
| 858 | 874 |
| 859 } // namespace shell_integration | 875 } // namespace shell_integration |
| OLD | NEW |