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_impl.h" | 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/google/google_util.h" | 35 #include "chrome/browser/google/google_util.h" |
36 #include "chrome/browser/net/predictor.h" | 36 #include "chrome/browser/net/predictor.h" |
37 #include "chrome/browser/net/url_fixer_upper.h" | 37 #include "chrome/browser/net/url_fixer_upper.h" |
38 #include "chrome/browser/notifications/desktop_notification_service.h" | 38 #include "chrome/browser/notifications/desktop_notification_service.h" |
39 #include "chrome/browser/performance_monitor/startup_timer.h" | 39 #include "chrome/browser/performance_monitor/startup_timer.h" |
40 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 40 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
41 #include "chrome/browser/prefs/pref_service.h" | 41 #include "chrome/browser/prefs/pref_service.h" |
42 #include "chrome/browser/prefs/session_startup_pref.h" | 42 #include "chrome/browser/prefs/session_startup_pref.h" |
43 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
44 #include "chrome/browser/profiles/profile_io_data.h" | 44 #include "chrome/browser/profiles/profile_io_data.h" |
45 #include "chrome/browser/protector/protected_prefs_watcher.h" | |
46 #include "chrome/browser/protector/protector_service.h" | |
47 #include "chrome/browser/protector/protector_service_factory.h" | |
48 #include "chrome/browser/protector/protector_utils.h" | |
49 #include "chrome/browser/rlz/rlz.h" | 45 #include "chrome/browser/rlz/rlz.h" |
50 #include "chrome/browser/sessions/session_restore.h" | 46 #include "chrome/browser/sessions/session_restore.h" |
51 #include "chrome/browser/sessions/session_service.h" | 47 #include "chrome/browser/sessions/session_service.h" |
52 #include "chrome/browser/sessions/session_service_factory.h" | 48 #include "chrome/browser/sessions/session_service_factory.h" |
53 #include "chrome/browser/shell_integration.h" | 49 #include "chrome/browser/shell_integration.h" |
54 #include "chrome/browser/ui/browser_commands.h" | 50 #include "chrome/browser/ui/browser_commands.h" |
55 #include "chrome/browser/ui/browser_finder.h" | 51 #include "chrome/browser/ui/browser_finder.h" |
56 #include "chrome/browser/ui/browser_list.h" | 52 #include "chrome/browser/ui/browser_list.h" |
57 #include "chrome/browser/ui/browser_navigator.h" | 53 #include "chrome/browser/ui/browser_navigator.h" |
58 #include "chrome/browser/ui/browser_tabrestore.h" | 54 #include "chrome/browser/ui/browser_tabrestore.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 #include "base/win/windows_version.h" | 104 #include "base/win/windows_version.h" |
109 #endif | 105 #endif |
110 | 106 |
111 #if defined(ENABLE_APP_LIST) | 107 #if defined(ENABLE_APP_LIST) |
112 #include "chrome/browser/ui/app_list/app_list_controller.h" | 108 #include "chrome/browser/ui/app_list/app_list_controller.h" |
113 #endif | 109 #endif |
114 | 110 |
115 using content::ChildProcessSecurityPolicy; | 111 using content::ChildProcessSecurityPolicy; |
116 using content::WebContents; | 112 using content::WebContents; |
117 using extensions::Extension; | 113 using extensions::Extension; |
118 using protector::ProtectedPrefsWatcher; | |
119 using protector::ProtectorService; | |
120 using protector::ProtectorServiceFactory; | |
121 | 114 |
122 extern bool in_synchronous_profile_launch; | 115 extern bool in_synchronous_profile_launch; |
123 | 116 |
124 namespace { | 117 namespace { |
125 | 118 |
126 // Utility functions ---------------------------------------------------------- | 119 // Utility functions ---------------------------------------------------------- |
127 | 120 |
128 enum LaunchMode { | 121 enum LaunchMode { |
129 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. | 122 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. |
130 LM_AS_WEBAPP, // Launched as a installed web application. | 123 LM_AS_WEBAPP, // Launched as a installed web application. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // not as chrome. | 348 // not as chrome. |
356 // Special case is when app switches are passed but we do want to restore | 349 // Special case is when app switches are passed but we do want to restore |
357 // session. In that case open app window + focus it after session is restored. | 350 // session. In that case open app window + focus it after session is restored. |
358 content::WebContents* app_contents = NULL; | 351 content::WebContents* app_contents = NULL; |
359 if (OpenApplicationWindow(profile, &app_contents)) { | 352 if (OpenApplicationWindow(profile, &app_contents)) { |
360 RecordLaunchModeHistogram(LM_AS_WEBAPP); | 353 RecordLaunchModeHistogram(LM_AS_WEBAPP); |
361 } else { | 354 } else { |
362 RecordLaunchModeHistogram(urls_to_open.empty() ? | 355 RecordLaunchModeHistogram(urls_to_open.empty() ? |
363 LM_TO_BE_DECIDED : LM_WITH_URLS); | 356 LM_TO_BE_DECIDED : LM_WITH_URLS); |
364 | 357 |
365 // Notify user if the Preferences backup is invalid or changes to settings | |
366 // affecting browser startup have been detected. | |
367 CheckPreferencesBackup(profile); | |
368 | |
369 ProcessLaunchURLs(process_startup, urls_to_open); | 358 ProcessLaunchURLs(process_startup, urls_to_open); |
370 | 359 |
371 // If this is an app launch, but we didn't open an app window, it may | 360 // If this is an app launch, but we didn't open an app window, it may |
372 // be an app tab. | 361 // be an app tab. |
373 OpenApplicationTab(profile); | 362 OpenApplicationTab(profile); |
374 | 363 |
375 #if defined(OS_MACOSX) | 364 #if defined(OS_MACOSX) |
376 if (process_startup) { | 365 if (process_startup) { |
377 // Check whether the auto-update system needs to be promoted from user | 366 // Check whether the auto-update system needs to be promoted from user |
378 // to system. | 367 // to system. |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 // If we have more than two startup tabs then skip the welcome page. | 946 // If we have more than two startup tabs then skip the welcome page. |
958 if (startup_urls->size() > 2) { | 947 if (startup_urls->size() > 2) { |
959 std::vector<GURL>::iterator it = std::find( | 948 std::vector<GURL>::iterator it = std::find( |
960 startup_urls->begin(), startup_urls->end(), GetWelcomePageURL()); | 949 startup_urls->begin(), startup_urls->end(), GetWelcomePageURL()); |
961 if (it != startup_urls->end()) | 950 if (it != startup_urls->end()) |
962 startup_urls->erase(it); | 951 startup_urls->erase(it); |
963 } | 952 } |
964 } | 953 } |
965 } | 954 } |
966 | 955 |
967 void StartupBrowserCreatorImpl::CheckPreferencesBackup(Profile* profile) { | |
968 ProtectorService* protector_service = | |
969 ProtectorServiceFactory::GetForProfile(profile); | |
970 ProtectedPrefsWatcher* prefs_watcher = protector_service->GetPrefsWatcher(); | |
971 | |
972 // Check if backup is valid. | |
973 if (!prefs_watcher->is_backup_valid()) { | |
974 protector_service->ShowChange(protector::CreatePrefsBackupInvalidChange()); | |
975 // Further checks make no sense. | |
976 return; | |
977 } | |
978 | |
979 // Check for session startup (including pinned tabs) changes. | |
980 if (SessionStartupPref::DidStartupPrefChange(profile) || | |
981 prefs_watcher->DidPrefChange(prefs::kPinnedTabs)) { | |
982 LOG(WARNING) << "Session startup settings have changed"; | |
983 SessionStartupPref new_pref = SessionStartupPref::GetStartupPref(profile); | |
984 StartupTabs new_tabs = PinnedTabCodec::ReadPinnedTabs(profile); | |
985 const base::Value* tabs_backup = | |
986 prefs_watcher->GetBackupForPref(prefs::kPinnedTabs); | |
987 protector_service->ShowChange(protector::CreateSessionStartupChange( | |
988 new_pref, | |
989 new_tabs, | |
990 SessionStartupPref::GetStartupPrefBackup(profile), | |
991 PinnedTabCodec::ReadPinnedTabs(tabs_backup))); | |
992 } | |
993 | |
994 // Check for homepage changes. | |
995 if (prefs_watcher->DidPrefChange(prefs::kHomePage) || | |
996 prefs_watcher->DidPrefChange(prefs::kHomePageIsNewTabPage) || | |
997 prefs_watcher->DidPrefChange(prefs::kShowHomeButton)) { | |
998 LOG(WARNING) << "Homepage has changed"; | |
999 PrefService* prefs = profile->GetPrefs(); | |
1000 std::string backup_homepage; | |
1001 bool backup_homepage_is_ntp = false; | |
1002 bool backup_show_home_button = false; | |
1003 if (!prefs_watcher->GetBackupForPref(prefs::kHomePage)-> | |
1004 GetAsString(&backup_homepage) || | |
1005 !prefs_watcher->GetBackupForPref(prefs::kHomePageIsNewTabPage)-> | |
1006 GetAsBoolean(&backup_homepage_is_ntp) || | |
1007 !prefs_watcher->GetBackupForPref(prefs::kShowHomeButton)-> | |
1008 GetAsBoolean(&backup_show_home_button)) { | |
1009 NOTREACHED(); | |
1010 } | |
1011 protector_service->ShowChange(protector::CreateHomepageChange( | |
1012 // New: | |
1013 prefs->GetString(prefs::kHomePage), | |
1014 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), | |
1015 prefs->GetBoolean(prefs::kShowHomeButton), | |
1016 // Backup: | |
1017 backup_homepage, | |
1018 backup_homepage_is_ntp, | |
1019 backup_show_home_button)); | |
1020 } | |
1021 } | |
1022 | |
1023 #if !defined(OS_WIN) || defined(USE_AURA) | 956 #if !defined(OS_WIN) || defined(USE_AURA) |
1024 // static | 957 // static |
1025 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( | 958 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( |
1026 Profile* profile, | 959 Profile* profile, |
1027 const std::vector<GURL>& startup_urls) { | 960 const std::vector<GURL>& startup_urls) { |
1028 return false; | 961 return false; |
1029 } | 962 } |
1030 #endif | 963 #endif |
OLD | NEW |