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

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

Issue 12638005: Fix sync promo first run bugs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 "apps/app_restore_service.h" 10 #include "apps/app_restore_service.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 } 245 }
246 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) { 246 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) {
247 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) { 247 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) {
248 AppLauncherHandler::RecordAppLaunchType( 248 AppLauncherHandler::RecordAppLaunchType(
249 extension_misc::APP_LAUNCH_AUTOLAUNCH); 249 extension_misc::APP_LAUNCH_AUTOLAUNCH);
250 } 250 }
251 } 251 }
252 } 252 }
253 253
254 bool IsNewTabURL(Profile* profile, const GURL& url) {
255 GURL ntp_url(chrome::kChromeUINewTabURL);
256 return url == ntp_url ||
257 (url.is_empty() && profile->GetHomePage() == ntp_url);
258 }
259
260 void AddSyncPromoTab(Profile* profile, StartupTabs* tabs) {
261 SyncPromoUI::DidShowSyncPromoAtStartup(profile);
262
263 StartupTab sync_promo_tab;
264 GURL continue_url;
265 if (!SyncPromoUI::UseWebBasedSigninFlow())
266 continue_url = GURL(chrome::kChromeUINewTabURL);
267 sync_promo_tab.url = SyncPromoUI::GetSyncPromoURL(
268 continue_url, SyncPromoUI::SOURCE_START_PAGE, false);
269 sync_promo_tab.is_pinned = false;
270 tabs->insert(tabs->begin(), sync_promo_tab);
271
272 // If the next URL is the NTP then remove it, effectively replacing the NTP
273 // with the sync promo. This behavior is desired because completing or
274 // skipping the sync promo causes a redirect to the NTP.
275 if (tabs->size() > 1 && IsNewTabURL(profile, tabs->at(1).url))
276 tabs->erase(tabs->begin() + 1);
277 }
278
254 class WebContentsCloseObserver : public content::NotificationObserver { 279 class WebContentsCloseObserver : public content::NotificationObserver {
255 public: 280 public:
256 WebContentsCloseObserver() : contents_(NULL) {} 281 WebContentsCloseObserver() : contents_(NULL) {}
257 virtual ~WebContentsCloseObserver() {} 282 virtual ~WebContentsCloseObserver() {}
258 283
259 void SetContents(content::WebContents* contents) { 284 void SetContents(content::WebContents* contents) {
260 DCHECK(!contents_); 285 DCHECK(!contents_);
261 contents_ = contents; 286 contents_ = contents;
262 287
263 registrar_.Add(this, 288 registrar_.Add(this,
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 // Only use the set of urls specified in preferences if nothing was 724 // Only use the set of urls specified in preferences if nothing was
700 // specified on the command line. Filter out any urls that are to be 725 // specified on the command line. Filter out any urls that are to be
701 // restored by virtue of having been previously pinned. 726 // restored by virtue of having been previously pinned.
702 AddUniqueURLs(pref.urls, &tabs); 727 AddUniqueURLs(pref.urls, &tabs);
703 } else if (pref.type == SessionStartupPref::HOMEPAGE) { 728 } else if (pref.type == SessionStartupPref::HOMEPAGE) {
704 // If 'homepage' selected, either by the user or by a policy, we should 729 // If 'homepage' selected, either by the user or by a policy, we should
705 // have migrated them to another value. 730 // have migrated them to another value.
706 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; 731 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE";
707 } 732 }
708 733
734 if (pref.type != SessionStartupPref::LAST &&
735 SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_)) {
736 AddSyncPromoTab(profile_, &tabs);
737 }
738
709 if (tabs.empty()) 739 if (tabs.empty())
710 return NULL; 740 return NULL;
711 741
712 Browser* browser = OpenTabsInBrowser(NULL, true, tabs); 742 Browser* browser = OpenTabsInBrowser(NULL, true, tabs);
713 return browser; 743 return browser;
714 } 744 }
715 745
716 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls, 746 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls,
717 StartupTabs* tabs) { 747 StartupTabs* tabs) {
718 size_t num_existing_tabs = tabs->size(); 748 size_t num_existing_tabs = tabs->size();
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 command_line_.HasSwitch(switches::kResetLocalPassphrase); 932 command_line_.HasSwitch(switches::kResetLocalPassphrase);
903 if ((is_first_run_ || has_reset_local_passphrase_switch) && 933 if ((is_first_run_ || has_reset_local_passphrase_switch) &&
904 prefs->GetBoolean(prefs::kProfileIsManaged)) { 934 prefs->GetBoolean(prefs::kProfileIsManaged)) {
905 startup_urls->insert(startup_urls->begin(), 935 startup_urls->insert(startup_urls->begin(),
906 GURL(std::string(chrome::kChromeUISettingsURL) + 936 GURL(std::string(chrome::kChromeUISettingsURL) +
907 chrome::kManagedUserSettingsSubPage)); 937 chrome::kManagedUserSettingsSubPage));
908 if (has_reset_local_passphrase_switch) { 938 if (has_reset_local_passphrase_switch) {
909 prefs->SetString(prefs::kManagedModeLocalPassphrase, ""); 939 prefs->SetString(prefs::kManagedModeLocalPassphrase, "");
910 prefs->SetString(prefs::kManagedModeLocalSalt, ""); 940 prefs->SetString(prefs::kManagedModeLocalSalt, "");
911 } 941 }
912 } else if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_,
913 is_first_run_)) {
914 // If the sync promo page is going to be displayed then insert it at the
915 // front of the list.
916 GURL continue_url;
917 if (!SyncPromoUI::UseWebBasedSigninFlow()) {
918 continue_url = GURL(chrome::kChromeUINewTabURL);
919 }
920
921 SyncPromoUI::DidShowSyncPromoAtStartup(profile_);
922 GURL old_url = (*startup_urls)[0];
923 (*startup_urls)[0] =
924 SyncPromoUI::GetSyncPromoURL(continue_url,
925 SyncPromoUI::SOURCE_START_PAGE,
926 false);
927
928 // An empty URL means to go to the home page.
929 if (old_url.is_empty() &&
930 profile_->GetHomePage() == GURL(chrome::kChromeUINewTabURL)) {
931 old_url = GURL(chrome::kChromeUINewTabURL);
932 }
933
934 // If the old URL is not the NTP then insert it right after the sync promo.
935 if (old_url != GURL(chrome::kChromeUINewTabURL))
936 startup_urls->insert(startup_urls->begin() + 1, old_url);
937 } 942 }
938 } 943 }
939 944
940 #if !defined(OS_WIN) || defined(USE_AURA) 945 #if !defined(OS_WIN) || defined(USE_AURA)
941 // static 946 // static
942 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( 947 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser(
943 Profile* profile, 948 Profile* profile,
944 const std::vector<GURL>& startup_urls) { 949 const std::vector<GURL>& startup_urls) {
945 return false; 950 return false;
946 } 951 }
947 #endif 952 #endif
OLDNEW
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698