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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 1349163008: Setting chrome as the default browser is now fixed on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: asvitkine comments #1 Created 5 years, 3 months 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 unified diff | Download patch
OLDNEW
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/ui/startup/startup_browser_creator.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 #include <set> 8 #include <set>
9 9
10 #include "apps/app_load_service.h" 10 #include "apps/app_load_service.h"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 // static 439 // static
440 void StartupBrowserCreator::RegisterLocalStatePrefs( 440 void StartupBrowserCreator::RegisterLocalStatePrefs(
441 PrefRegistrySimple* registry) { 441 PrefRegistrySimple* registry) {
442 #if defined(OS_WIN) 442 #if defined(OS_WIN)
443 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string()); 443 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string());
444 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true); 444 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true);
445 #endif 445 #endif
446 } 446 }
447 447
448 // static 448 // static
449 bool StartupBrowserCreator::HasUrlFilters() {
450 return !GetUrlFilters()->empty();
451 }
452
453 // static
454 bool StartupBrowserCreator::ExecuteFilterCallback(const GURL& url) {
455 UrlFilters* filters = GetUrlFilters();
456 auto it = filters->find(url);
457 if (it != filters->end()) {
grt (UTC plus 2) 2015/09/22 18:21:47 nit to reduce braces: if (it == filters->end())
458 it->second.Run();
459 return true;
460 }
461 return false;
462 }
463
464 // static
465 bool StartupBrowserCreator::UrlFilterExists(const GURL& url) {
466 UrlFilters* filters = GetUrlFilters();
467 return filters->find(url) != filters->end();
468 }
469
470 // static
471 void StartupBrowserCreator::AddUrlFilter(
472 const GURL& url,
473 const base::Callback<void(void)>& callback) {
474 GetUrlFilters()->insert({url, callback});
grt (UTC plus 2) 2015/09/22 18:21:47 how about: (*GetUrlFilters())[url] = callback;
475 }
476
477 // static
478 void StartupBrowserCreator::RemoveUrlFilter(const GURL& url) {
479 DCHECK(UrlFilterExists(url));
480
481 UrlFilters* filters = GetUrlFilters();
482 filters->erase(filters->find(url));
grt (UTC plus 2) 2015/09/22 18:21:47 remove the DCHECK above and change this to: size
483 }
484
485 // static
449 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( 486 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine(
450 const base::CommandLine& command_line, 487 const base::CommandLine& command_line,
451 const base::FilePath& cur_dir, 488 const base::FilePath& cur_dir,
452 Profile* profile) { 489 Profile* profile) {
453 std::vector<GURL> urls; 490 std::vector<GURL> urls;
454 491
455 const base::CommandLine::StringVector& params = command_line.GetArgs(); 492 const base::CommandLine::StringVector& params = command_line.GetArgs();
456 for (size_t i = 0; i < params.size(); ++i) { 493 for (size_t i = 0; i < params.size(); ++i) {
457 base::FilePath param = base::FilePath(params[i]); 494 base::FilePath param = base::FilePath(params[i]);
458 // Handle Vista way of searching - "? <search-term>" 495 // Handle Vista way of searching - "? <search-term>"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 541 }
505 542
506 // static 543 // static
507 bool StartupBrowserCreator::ProcessCmdLineImpl( 544 bool StartupBrowserCreator::ProcessCmdLineImpl(
508 const base::CommandLine& command_line, 545 const base::CommandLine& command_line,
509 const base::FilePath& cur_dir, 546 const base::FilePath& cur_dir,
510 bool process_startup, 547 bool process_startup,
511 Profile* last_used_profile, 548 Profile* last_used_profile,
512 const Profiles& last_opened_profiles, 549 const Profiles& last_opened_profiles,
513 StartupBrowserCreator* browser_creator) { 550 StartupBrowserCreator* browser_creator) {
551 DCHECK_CURRENTLY_ON(BrowserThread::UI);
514 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); 552 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl");
515 553
516 DCHECK(last_used_profile); 554 DCHECK(last_used_profile);
517 if (process_startup) { 555 if (process_startup) {
518 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 556 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
519 content::NavigationController::DisablePromptOnRepost(); 557 content::NavigationController::DisablePromptOnRepost();
520 } 558 }
521 559
522 bool silent_launch = false; 560 bool silent_launch = false;
523 561
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 680
643 // Return early here since we don't want to open a browser window. 681 // Return early here since we don't want to open a browser window.
644 // The exception is when there are no browser windows, since we don't want 682 // The exception is when there are no browser windows, since we don't want
645 // chrome to shut down. 683 // chrome to shut down.
646 // TODO(jackhou): Do this properly once keep-alive is handled by the 684 // TODO(jackhou): Do this properly once keep-alive is handled by the
647 // background page of apps. Tracked at http://crbug.com/175381 685 // background page of apps. Tracked at http://crbug.com/175381
648 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) 686 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0)
649 return true; 687 return true;
650 } 688 }
651 689
690 // Filters out specific urls.
grt (UTC plus 2) 2015/09/22 18:21:47 nit: Filters -> Filter
691 if (HasUrlFilters()) {
692 for (const auto& arg : command_line.GetArgs()) {
693 GURL url(arg);
694 if (url.is_valid() && browser_creator->ExecuteFilterCallback(url))
695 return true;
696 }
697 }
698
652 #if defined(OS_WIN) 699 #if defined(OS_WIN)
653 // Log whether this process was a result of an action in the Windows Jumplist. 700 // Log whether this process was a result of an action in the Windows Jumplist.
654 if (command_line.HasSwitch(switches::kWinJumplistAction)) { 701 if (command_line.HasSwitch(switches::kWinJumplistAction)) {
655 jumplist::LogJumplistActionFromSwitchValue( 702 jumplist::LogJumplistActionFromSwitchValue(
656 command_line.GetSwitchValueASCII(switches::kWinJumplistAction)); 703 command_line.GetSwitchValueASCII(switches::kWinJumplistAction));
657 } 704 }
658 #endif 705 #endif
659 706
660 chrome::startup::IsProcessStartup is_process_startup = process_startup ? 707 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
661 chrome::startup::IS_PROCESS_STARTUP : 708 chrome::startup::IS_PROCESS_STARTUP :
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 867 }
821 868
822 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL); 869 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL);
823 } 870 }
824 871
825 // static 872 // static
826 bool StartupBrowserCreator::ActivatedProfile() { 873 bool StartupBrowserCreator::ActivatedProfile() {
827 return profile_launch_observer.Get().activated_profile(); 874 return profile_launch_observer.Get().activated_profile();
828 } 875 }
829 876
877 // static
878 StartupBrowserCreator::UrlFilters* StartupBrowserCreator::GetUrlFilters() {
879 static UrlFilters* url_filters_ = new UrlFilters();
grt (UTC plus 2) 2015/09/22 18:21:47 in the vast majority of Chrome runs, there will ne
880 return url_filters_;
881 }
882
830 bool HasPendingUncleanExit(Profile* profile) { 883 bool HasPendingUncleanExit(Profile* profile) {
831 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && 884 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED &&
832 !profile_launch_observer.Get().HasBeenLaunched(profile); 885 !profile_launch_observer.Get().HasBeenLaunched(profile);
833 } 886 }
834 887
835 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, 888 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir,
836 const base::CommandLine& command_line) { 889 const base::CommandLine& command_line) {
837 if (command_line.HasSwitch(switches::kProfileDirectory)) { 890 if (command_line.HasSwitch(switches::kProfileDirectory)) {
838 return user_data_dir.Append( 891 return user_data_dir.Append(
839 command_line.GetSwitchValuePath(switches::kProfileDirectory)); 892 command_line.GetSwitchValuePath(switches::kProfileDirectory));
840 } 893 }
841 894
842 // If we are showing the app list then chrome isn't shown so load the app 895 // If we are showing the app list then chrome isn't shown so load the app
843 // list's profile rather than chrome's. 896 // list's profile rather than chrome's.
844 if (command_line.HasSwitch(switches::kShowAppList)) { 897 if (command_line.HasSwitch(switches::kShowAppList)) {
845 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> 898 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->
846 GetProfilePath(user_data_dir); 899 GetProfilePath(user_data_dir);
847 } 900 }
848 901
849 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 902 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
850 user_data_dir); 903 user_data_dir);
851 } 904 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698