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/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/file_util.h" | 17 #include "base/file_util.h" |
| 18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.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/path_service.h" | 24 #include "base/path_service.h" |
| 25 #include "base/prefs/pref_service.h" | 25 #include "base/prefs/pref_service.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
| 28 #include "base/strings/stringprintf.h" | |
| 28 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_restrictions.h" | 30 #include "base/threading/thread_restrictions.h" |
| 30 #include "chrome/browser/app_mode/app_mode_utils.h" | 31 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 31 #include "chrome/browser/auto_launch_trial.h" | 32 #include "chrome/browser/auto_launch_trial.h" |
| 32 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
| 34 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 35 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 35 #include "chrome/browser/extensions/startup_helper.h" | 36 #include "chrome/browser/extensions/startup_helper.h" |
| 36 #include "chrome/browser/extensions/unpacked_installer.h" | 37 #include "chrome/browser/extensions/unpacked_installer.h" |
| 37 #include "chrome/browser/first_run/first_run.h" | 38 #include "chrome/browser/first_run/first_run.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 95 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 95 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" | 96 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" |
| 96 #include "chrome/browser/printing/print_dialog_cloud.h" | 97 #include "chrome/browser/printing/print_dialog_cloud.h" |
| 97 #endif | 98 #endif |
| 98 | 99 |
| 99 using content::BrowserThread; | 100 using content::BrowserThread; |
| 100 using content::ChildProcessSecurityPolicy; | 101 using content::ChildProcessSecurityPolicy; |
| 101 | 102 |
| 102 namespace { | 103 namespace { |
| 103 | 104 |
| 105 // The URL to the webstore page for a specific app. | |
| 106 const char kWebstoreUrlFormat[] = | |
|
tapted
2014/07/24 07:52:50
I don't think this constant belongs here..
jackhou1
2014/07/25 01:47:33
Kept this part in install_chrome_app.
| |
| 107 "https://chrome.google.com/webstore/detail/%s"; | |
| 108 | |
| 104 // Keeps track on which profiles have been launched. | 109 // Keeps track on which profiles have been launched. |
| 105 class ProfileLaunchObserver : public content::NotificationObserver { | 110 class ProfileLaunchObserver : public content::NotificationObserver { |
| 106 public: | 111 public: |
| 107 ProfileLaunchObserver() | 112 ProfileLaunchObserver() |
| 108 : profile_to_activate_(NULL), | 113 : profile_to_activate_(NULL), |
| 109 activated_profile_(false) { | 114 activated_profile_(false) { |
| 110 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 115 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 111 content::NotificationService::AllSources()); | 116 content::NotificationService::AllSources()); |
| 112 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 117 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 113 content::NotificationService::AllSources()); | 118 content::NotificationService::AllSources()); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 // The file is overwritten if it exists. This function should only be called in | 243 // The file is overwritten if it exists. This function should only be called in |
| 239 // the blocking pool. | 244 // the blocking pool. |
| 240 void DumpBrowserHistograms(const base::FilePath& output_file) { | 245 void DumpBrowserHistograms(const base::FilePath& output_file) { |
| 241 base::ThreadRestrictions::AssertIOAllowed(); | 246 base::ThreadRestrictions::AssertIOAllowed(); |
| 242 | 247 |
| 243 std::string output_string(base::StatisticsRecorder::ToJSON(std::string())); | 248 std::string output_string(base::StatisticsRecorder::ToJSON(std::string())); |
| 244 base::WriteFile(output_file, output_string.data(), | 249 base::WriteFile(output_file, output_string.data(), |
| 245 static_cast<int>(output_string.size())); | 250 static_cast<int>(output_string.size())); |
| 246 } | 251 } |
| 247 | 252 |
| 253 GURL GetAppInstallUrl(const std::string& app_id) { | |
| 254 return GURL(base::StringPrintf(kWebstoreUrlFormat, app_id.c_str())); | |
| 255 } | |
| 256 | |
| 248 } // namespace | 257 } // namespace |
| 249 | 258 |
| 250 StartupBrowserCreator::StartupBrowserCreator() | 259 StartupBrowserCreator::StartupBrowserCreator() |
| 251 : is_default_browser_dialog_suppressed_(false), | 260 : is_default_browser_dialog_suppressed_(false), |
| 252 show_main_browser_window_(true) { | 261 show_main_browser_window_(true) { |
| 253 } | 262 } |
| 254 | 263 |
| 255 StartupBrowserCreator::~StartupBrowserCreator() {} | 264 StartupBrowserCreator::~StartupBrowserCreator() {} |
| 256 | 265 |
| 257 // static | 266 // static |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // Note: This check should have been done in ProcessCmdLineImpl() | 303 // Note: This check should have been done in ProcessCmdLineImpl() |
| 295 // before calling this function. However chromeos/login/login_utils.cc | 304 // before calling this function. However chromeos/login/login_utils.cc |
| 296 // calls this function directly (see comments there) so it has to be checked | 305 // calls this function directly (see comments there) so it has to be checked |
| 297 // again. | 306 // again. |
| 298 const bool silent_launch = command_line.HasSwitch(switches::kSilentLaunch); | 307 const bool silent_launch = command_line.HasSwitch(switches::kSilentLaunch); |
| 299 | 308 |
| 300 if (!silent_launch) { | 309 if (!silent_launch) { |
| 301 StartupBrowserCreatorImpl lwp(cur_dir, command_line, this, is_first_run); | 310 StartupBrowserCreatorImpl lwp(cur_dir, command_line, this, is_first_run); |
| 302 const std::vector<GURL> urls_to_launch = | 311 const std::vector<GURL> urls_to_launch = |
| 303 GetURLsFromCommandLine(command_line, cur_dir, profile); | 312 GetURLsFromCommandLine(command_line, cur_dir, profile); |
| 313 | |
| 304 chrome::HostDesktopType host_desktop_type = | 314 chrome::HostDesktopType host_desktop_type = |
| 305 chrome::HOST_DESKTOP_TYPE_NATIVE; | 315 chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 306 | 316 |
| 307 #if defined(USE_ASH) && !defined(OS_CHROMEOS) | 317 #if defined(USE_ASH) && !defined(OS_CHROMEOS) |
| 308 // We want to maintain only one type of instance for now, either ASH | 318 // We want to maintain only one type of instance for now, either ASH |
| 309 // or desktop. | 319 // or desktop. |
| 310 // TODO(shrikant): Remove this code once we decide on running both desktop | 320 // TODO(shrikant): Remove this code once we decide on running both desktop |
| 311 // and ASH instances side by side. | 321 // and ASH instances side by side. |
| 312 if (ash::Shell::HasInstance()) | 322 if (ash::Shell::HasInstance()) |
| 313 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; | 323 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 } | 510 } |
| 501 | 511 |
| 502 if (command_line.HasSwitch(switches::kInstallFromWebstore)) { | 512 if (command_line.HasSwitch(switches::kInstallFromWebstore)) { |
| 503 extensions::StartupHelper helper; | 513 extensions::StartupHelper helper; |
| 504 helper.InstallFromWebstore(command_line, last_used_profile); | 514 helper.InstallFromWebstore(command_line, last_used_profile); |
| 505 // Nothing more needs to be done, so return false to stop launching and | 515 // Nothing more needs to be done, so return false to stop launching and |
| 506 // quit. | 516 // quit. |
| 507 return false; | 517 return false; |
| 508 } | 518 } |
| 509 | 519 |
| 520 std::vector<GURL> extra_urls_to_launch; | |
| 521 if (command_line.HasSwitch(switches::kInstallChromeApp)) { | |
| 522 extensions::StartupHelper helper; | |
| 523 helper.InstallChromeApp(command_line, last_used_profile); | |
| 524 extra_urls_to_launch.push_back(GetAppInstallUrl( | |
| 525 command_line.GetSwitchValueASCII(switches::kInstallChromeApp))); | |
| 526 } | |
| 527 | |
| 510 if (command_line.HasSwitch(switches::kValidateCrx)) { | 528 if (command_line.HasSwitch(switches::kValidateCrx)) { |
| 511 if (!process_startup) { | 529 if (!process_startup) { |
| 512 LOG(ERROR) << "chrome is already running; you must close all running " | 530 LOG(ERROR) << "chrome is already running; you must close all running " |
| 513 << "instances before running with the --" | 531 << "instances before running with the --" |
| 514 << switches::kValidateCrx << " flag"; | 532 << switches::kValidateCrx << " flag"; |
| 515 return false; | 533 return false; |
| 516 } | 534 } |
| 517 extensions::StartupHelper helper; | 535 extensions::StartupHelper helper; |
| 518 std::string message; | 536 std::string message; |
| 519 std::string error; | 537 std::string error; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 // background page of apps. Tracked at http://crbug.com/175381 | 620 // background page of apps. Tracked at http://crbug.com/175381 |
| 603 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) | 621 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) |
| 604 return true; | 622 return true; |
| 605 } | 623 } |
| 606 | 624 |
| 607 chrome::startup::IsProcessStartup is_process_startup = process_startup ? | 625 chrome::startup::IsProcessStartup is_process_startup = process_startup ? |
| 608 chrome::startup::IS_PROCESS_STARTUP : | 626 chrome::startup::IS_PROCESS_STARTUP : |
| 609 chrome::startup::IS_NOT_PROCESS_STARTUP; | 627 chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 610 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? | 628 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? |
| 611 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 629 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 630 CommandLine command_line_with_extra_urls(command_line); | |
| 631 for (std::vector<GURL>::const_iterator it = extra_urls_to_launch.begin(); | |
| 632 it != extra_urls_to_launch.end(); | |
| 633 ++it) { | |
| 634 if (it->is_valid()) | |
| 635 command_line_with_extra_urls.AppendArg(it->spec()); | |
| 636 } | |
| 612 // |last_opened_profiles| will be empty in the following circumstances: | 637 // |last_opened_profiles| will be empty in the following circumstances: |
| 613 // - This is the first launch. |last_used_profile| is the initial profile. | 638 // - This is the first launch. |last_used_profile| is the initial profile. |
| 614 // - The user exited the browser by closing all windows for all | 639 // - The user exited the browser by closing all windows for all |
| 615 // profiles. |last_used_profile| is the profile which owned the last open | 640 // profiles. |last_used_profile| is the profile which owned the last open |
| 616 // window. | 641 // window. |
| 617 // - Only incognito windows were open when the browser exited. | 642 // - Only incognito windows were open when the browser exited. |
| 618 // |last_used_profile| is the last used incognito profile. Restoring it will | 643 // |last_used_profile| is the last used incognito profile. Restoring it will |
| 619 // create a browser window for the corresponding original profile. | 644 // create a browser window for the corresponding original profile. |
| 620 if (last_opened_profiles.empty()) { | 645 if (last_opened_profiles.empty()) { |
| 621 // If the last used profile is locked or was a guest, show the user manager. | 646 // If the last used profile is locked or was a guest, show the user manager. |
| 622 if (switches::IsNewProfileManagement()) { | 647 if (switches::IsNewProfileManagement()) { |
| 623 ProfileInfoCache& profile_info = | 648 ProfileInfoCache& profile_info = |
| 624 g_browser_process->profile_manager()->GetProfileInfoCache(); | 649 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 625 size_t profile_index = profile_info.GetIndexOfProfileWithPath( | 650 size_t profile_index = profile_info.GetIndexOfProfileWithPath( |
| 626 last_used_profile->GetPath()); | 651 last_used_profile->GetPath()); |
| 627 bool signin_required = profile_index != std::string::npos && | 652 bool signin_required = profile_index != std::string::npos && |
| 628 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); | 653 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); |
| 629 if (signin_required || last_used_profile->IsGuestSession()) { | 654 if (signin_required || last_used_profile->IsGuestSession()) { |
| 630 chrome::ShowUserManager(base::FilePath()); | 655 chrome::ShowUserManager(base::FilePath()); |
| 631 return true; | 656 return true; |
| 632 } | 657 } |
| 633 } | 658 } |
| 634 if (!browser_creator->LaunchBrowser(command_line, last_used_profile, | 659 if (!browser_creator->LaunchBrowser(command_line_with_extra_urls, |
| 660 last_used_profile, | |
| 635 cur_dir, is_process_startup, | 661 cur_dir, is_process_startup, |
| 636 is_first_run, return_code)) { | 662 is_first_run, return_code)) { |
| 637 return false; | 663 return false; |
| 638 } | 664 } |
| 639 } else { | 665 } else { |
| 640 // Launch the last used profile with the full command line, and the other | 666 // Launch the last used profile with the full command line, and the other |
| 641 // opened profiles without the URLs to launch. | 667 // opened profiles without the URLs to launch. |
| 642 CommandLine command_line_without_urls(command_line.GetProgram()); | 668 CommandLine command_line_without_urls(command_line.GetProgram()); |
| 643 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); | 669 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); |
| 644 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); | 670 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 658 startup_pref.type == SessionStartupPref::DEFAULT && | 684 startup_pref.type == SessionStartupPref::DEFAULT && |
| 659 !HasPendingUncleanExit(*it)) | 685 !HasPendingUncleanExit(*it)) |
| 660 continue; | 686 continue; |
| 661 | 687 |
| 662 // Don't re-open a browser window for the guest profile. | 688 // Don't re-open a browser window for the guest profile. |
| 663 if (switches::IsNewProfileManagement() && | 689 if (switches::IsNewProfileManagement() && |
| 664 (*it)->IsGuestSession()) | 690 (*it)->IsGuestSession()) |
| 665 continue; | 691 continue; |
| 666 | 692 |
| 667 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? | 693 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? |
| 668 command_line : command_line_without_urls, *it, cur_dir, | 694 command_line_with_extra_urls : command_line_without_urls, *it, |
| 669 is_process_startup, is_first_run, return_code)) | 695 cur_dir, is_process_startup, is_first_run, return_code)) |
| 670 return false; | 696 return false; |
| 671 // We've launched at least one browser. | 697 // We've launched at least one browser. |
| 672 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; | 698 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 673 } | 699 } |
| 674 // This must be done after all profiles have been launched so the observer | 700 // This must be done after all profiles have been launched so the observer |
| 675 // knows about all profiles to wait for before activating this one. | 701 // knows about all profiles to wait for before activating this one. |
| 676 | 702 |
| 677 // If the last used profile was the guest one, we didn't open it so | 703 // If the last used profile was the guest one, we didn't open it so |
| 678 // we don't need to activate it either. | 704 // we don't need to activate it either. |
| 679 if (!switches::IsNewProfileManagement() && | 705 if (!switches::IsNewProfileManagement() && |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 } | 761 } |
| 736 | 762 |
| 737 if (command_line.HasSwitch(switches::kProfileDirectory)) { | 763 if (command_line.HasSwitch(switches::kProfileDirectory)) { |
| 738 return user_data_dir.Append( | 764 return user_data_dir.Append( |
| 739 command_line.GetSwitchValuePath(switches::kProfileDirectory)); | 765 command_line.GetSwitchValuePath(switches::kProfileDirectory)); |
| 740 } | 766 } |
| 741 | 767 |
| 742 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 768 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 743 user_data_dir); | 769 user_data_dir); |
| 744 } | 770 } |
| OLD | NEW |