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/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" |
11 #include "apps/switches.h" | 11 #include "apps/switches.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/environment.h" | 16 #include "base/environment.h" |
17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
23 #include "base/metrics/statistics_recorder.h" | 23 #include "base/metrics/statistics_recorder.h" |
24 #include "base/prefs/pref_service.h" | 24 #include "base/prefs/pref_service.h" |
25 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_split.h" | 26 #include "base/strings/string_split.h" |
27 #include "base/strings/string_tokenizer.h" | |
27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
28 #include "base/threading/thread_restrictions.h" | 29 #include "base/threading/thread_restrictions.h" |
29 #include "chrome/browser/app_mode/app_mode_utils.h" | 30 #include "chrome/browser/app_mode/app_mode_utils.h" |
30 #include "chrome/browser/auto_launch_trial.h" | 31 #include "chrome/browser/auto_launch_trial.h" |
31 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
32 #include "chrome/browser/chrome_notification_types.h" | 33 #include "chrome/browser/chrome_notification_types.h" |
33 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 34 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
34 #include "chrome/browser/extensions/startup_helper.h" | 35 #include "chrome/browser/extensions/startup_helper.h" |
35 #include "chrome/browser/extensions/unpacked_installer.h" | 36 #include "chrome/browser/extensions/unpacked_installer.h" |
36 #include "chrome/browser/first_run/first_run.h" | 37 #include "chrome/browser/first_run/first_run.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
56 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
57 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
58 #include "chrome/installer/util/browser_distribution.h" | 59 #include "chrome/installer/util/browser_distribution.h" |
59 #include "components/google/core/browser/google_util.h" | 60 #include "components/google/core/browser/google_util.h" |
60 #include "components/search_engines/util.h" | 61 #include "components/search_engines/util.h" |
61 #include "components/signin/core/common/profile_management_switches.h" | 62 #include "components/signin/core/common/profile_management_switches.h" |
62 #include "components/url_fixer/url_fixer.h" | 63 #include "components/url_fixer/url_fixer.h" |
63 #include "content/public/browser/browser_thread.h" | 64 #include "content/public/browser/browser_thread.h" |
64 #include "content/public/browser/child_process_security_policy.h" | 65 #include "content/public/browser/child_process_security_policy.h" |
65 #include "content/public/browser/navigation_controller.h" | 66 #include "content/public/browser/navigation_controller.h" |
67 #include "extensions/common/switches.h" | |
66 #include "net/base/net_util.h" | 68 #include "net/base/net_util.h" |
67 | 69 |
68 #if defined(USE_ASH) | 70 #if defined(USE_ASH) |
69 #include "ash/shell.h" | 71 #include "ash/shell.h" |
70 #endif | 72 #endif |
71 | 73 |
72 #if defined(OS_CHROMEOS) | 74 #if defined(OS_CHROMEOS) |
73 #include "chrome/browser/chromeos/app_mode/app_launch_utils.h" | 75 #include "chrome/browser/chromeos/app_mode/app_launch_utils.h" |
74 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | 76 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
75 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" | 77 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 FROM_HERE, | 604 FROM_HERE, |
603 base::Bind(&DumpBrowserHistograms, output_file)); | 605 base::Bind(&DumpBrowserHistograms, output_file)); |
604 } | 606 } |
605 silent_launch = true; | 607 silent_launch = true; |
606 } | 608 } |
607 | 609 |
608 // If we don't want to launch a new browser window or tab we are done here. | 610 // If we don't want to launch a new browser window or tab we are done here. |
609 if (silent_launch) | 611 if (silent_launch) |
610 return true; | 612 return true; |
611 | 613 |
612 VLOG(2) << "ProcessCmdLineImpl: PLACE 4"; | 614 VLOG(2) << "ProcessCmdLineImpl: PLACE 4.A"; |
615 if (command_line.HasSwitch(extensions::switches::kLoadApps) && | |
616 !IncognitoModePrefs::ShouldLaunchIncognito( | |
617 command_line, last_used_profile->GetPrefs())) { | |
618 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) | |
619 return false; | |
620 | |
621 // Return early here since we don't want to open a browser window. | |
James Hawkins
2014/11/18 01:24:33
Optional nit: Consider rewording to remove ambiguo
Zachary Kuznia
2014/11/18 23:32:22
Done.
| |
622 // The exception is when there are no browser windows, since we don't want | |
623 // chrome to shut down. | |
624 // TODO(jackhou): Do this properly once keep-alive is handled by the | |
625 // background page of apps. Tracked at http://crbug.com/175381 | |
626 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) | |
627 return true; | |
628 } | |
629 | |
630 VLOG(2) << "ProcessCmdLineImpl: PLACE 4.B"; | |
613 // Check for --load-and-launch-app. | 631 // Check for --load-and-launch-app. |
614 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && | 632 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && |
615 !IncognitoModePrefs::ShouldLaunchIncognito( | 633 !IncognitoModePrefs::ShouldLaunchIncognito( |
616 command_line, last_used_profile->GetPrefs())) { | 634 command_line, last_used_profile->GetPrefs())) { |
617 CommandLine::StringType path = command_line.GetSwitchValueNative( | 635 CommandLine::StringType path = command_line.GetSwitchValueNative( |
618 apps::kLoadAndLaunchApp); | 636 apps::kLoadAndLaunchApp); |
619 | 637 |
620 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( | 638 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( |
621 base::FilePath(path), command_line, cur_dir)) { | 639 base::FilePath(path), command_line, cur_dir)) { |
622 return false; | 640 return false; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.B"; | 767 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.B"; |
750 // This must be done after all profiles have been launched so the observer | 768 // This must be done after all profiles have been launched so the observer |
751 // knows about all profiles to wait for before activating this one. | 769 // knows about all profiles to wait for before activating this one. |
752 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); | 770 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); |
753 } | 771 } |
754 VLOG(2) << "ProcessCmdLineImpl: END"; | 772 VLOG(2) << "ProcessCmdLineImpl: END"; |
755 return true; | 773 return true; |
756 } | 774 } |
757 | 775 |
758 // static | 776 // static |
777 bool StartupBrowserCreator::ProcessLoadApps(const CommandLine& command_line, | |
James Hawkins
2014/11/18 01:24:34
nit: Document method and parameters.
Zachary Kuznia
2014/11/18 23:32:21
Documentation added to header file.
| |
778 const base::FilePath& cur_dir, | |
779 Profile* last_used_profile) { | |
780 CommandLine::StringType path_list = | |
781 command_line.GetSwitchValueNative(extensions::switches::kLoadApps); | |
782 | |
783 base::StringTokenizerT<CommandLine::StringType, | |
784 CommandLine::StringType::const_iterator> | |
785 tokenizer(path_list, FILE_PATH_LITERAL(",")); | |
786 | |
787 bool first_app = true; | |
James Hawkins
2014/11/18 01:24:33
Why not just manually call tokenizer.getNext() out
Zachary Kuznia
2014/11/18 23:32:21
Done.
| |
788 while (tokenizer.GetNext()) { | |
789 base::FilePath app_absolute_dir = | |
790 base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token())); | |
791 | |
792 if (first_app) { | |
793 first_app = false; | |
794 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( | |
James Hawkins
2014/11/18 01:24:33
This is somewhat confusing. We're launching the f
Zachary Kuznia
2014/11/18 23:32:21
The first app is loaded so that app_shell and chro
| |
795 app_absolute_dir, command_line, cur_dir)) { | |
796 return false; | |
797 } | |
798 } else { | |
799 if (!apps::AppLoadService::Get(last_used_profile)->Load( | |
800 app_absolute_dir)) { | |
801 return false; | |
802 } | |
803 } | |
804 } | |
805 | |
806 return true; | |
807 } | |
808 | |
809 // static | |
759 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( | 810 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( |
760 const CommandLine& command_line, | 811 const CommandLine& command_line, |
761 const base::FilePath& cur_dir, | 812 const base::FilePath& cur_dir, |
762 Profile* profile, | 813 Profile* profile, |
763 Profile::CreateStatus status) { | 814 Profile::CreateStatus status) { |
764 if (status == Profile::CREATE_STATUS_INITIALIZED) | 815 if (status == Profile::CREATE_STATUS_INITIALIZED) |
765 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, | 816 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, |
766 NULL); | 817 NULL); |
767 } | 818 } |
768 | 819 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 // If we are showing the app list then chrome isn't shown so load the app | 858 // If we are showing the app list then chrome isn't shown so load the app |
808 // list's profile rather than chrome's. | 859 // list's profile rather than chrome's. |
809 if (command_line.HasSwitch(switches::kShowAppList)) { | 860 if (command_line.HasSwitch(switches::kShowAppList)) { |
810 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 861 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
811 GetProfilePath(user_data_dir); | 862 GetProfilePath(user_data_dir); |
812 } | 863 } |
813 | 864 |
814 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 865 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
815 user_data_dir); | 866 user_data_dir); |
816 } | 867 } |
OLD | NEW |