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

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

Issue 16141008: Do not show sync promo when RestoreOnStartupURLs policy is set (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 6 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
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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 265 }
266 } 266 }
267 } 267 }
268 268
269 bool IsNewTabURL(Profile* profile, const GURL& url) { 269 bool IsNewTabURL(Profile* profile, const GURL& url) {
270 GURL ntp_url(chrome::kChromeUINewTabURL); 270 GURL ntp_url(chrome::kChromeUINewTabURL);
271 return url == ntp_url || 271 return url == ntp_url ||
272 (url.is_empty() && profile->GetHomePage() == ntp_url); 272 (url.is_empty() && profile->GetHomePage() == ntp_url);
273 } 273 }
274 274
275 void AddSyncPromoTab(Profile* profile, StartupTabs* tabs) {
276 SyncPromoUI::DidShowSyncPromoAtStartup(profile);
277
278 StartupTab sync_promo_tab;
279 sync_promo_tab.url = SyncPromoUI::GetSyncPromoURL(
280 SyncPromoUI::SOURCE_START_PAGE, false);
281 sync_promo_tab.is_pinned = false;
282
283 // No need to add if the sync promo is already in the startup list.
284 for (StartupTabs::const_iterator it = tabs->begin(); it != tabs->end();
285 ++it) {
286 if (it->url == sync_promo_tab.url)
287 return;
288 }
289
290 tabs->insert(tabs->begin(), sync_promo_tab);
291
292 // If the next URL is the NTP then remove it, effectively replacing the NTP
293 // with the sync promo. This behavior is desired because completing or
294 // skipping the sync promo causes a redirect to the NTP.
295 if (tabs->size() > 1 && IsNewTabURL(profile, tabs->at(1).url))
296 tabs->erase(tabs->begin() + 1);
297 }
298
299 class WebContentsCloseObserver : public content::NotificationObserver { 275 class WebContentsCloseObserver : public content::NotificationObserver {
300 public: 276 public:
301 WebContentsCloseObserver() : contents_(NULL) {} 277 WebContentsCloseObserver() : contents_(NULL) {}
302 virtual ~WebContentsCloseObserver() {} 278 virtual ~WebContentsCloseObserver() {}
303 279
304 void SetContents(content::WebContents* contents) { 280 void SetContents(content::WebContents* contents) {
305 DCHECK(!contents_); 281 DCHECK(!contents_);
306 contents_ = contents; 282 contents_ = contents;
307 283
308 registrar_.Add(this, 284 registrar_.Add(this,
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 // Only use the set of urls specified in preferences if nothing was 732 // Only use the set of urls specified in preferences if nothing was
757 // specified on the command line. Filter out any urls that are to be 733 // specified on the command line. Filter out any urls that are to be
758 // restored by virtue of having been previously pinned. 734 // restored by virtue of having been previously pinned.
759 AddUniqueURLs(pref.urls, &tabs); 735 AddUniqueURLs(pref.urls, &tabs);
760 } else if (pref.type == SessionStartupPref::HOMEPAGE) { 736 } else if (pref.type == SessionStartupPref::HOMEPAGE) {
761 // If 'homepage' selected, either by the user or by a policy, we should 737 // If 'homepage' selected, either by the user or by a policy, we should
762 // have migrated them to another value. 738 // have migrated them to another value.
763 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; 739 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE";
764 } 740 }
765 741
766 if (pref.type != SessionStartupPref::LAST &&
767 SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_)) {
768 AddSyncPromoTab(profile_, &tabs);
769 }
770
771 if (tabs.empty()) 742 if (tabs.empty())
772 return NULL; 743 return NULL;
773 744
774 Browser* browser = OpenTabsInBrowser(NULL, true, tabs, desktop_type); 745 Browser* browser = OpenTabsInBrowser(NULL, true, tabs, desktop_type);
775 return browser; 746 return browser;
776 } 747 }
777 748
778 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls, 749 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls,
779 StartupTabs* tabs) { 750 StartupTabs* tabs) {
780 size_t num_existing_tabs = tabs->size(); 751 size_t num_existing_tabs = tabs->size();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 (browser_creator_ && 894 (browser_creator_ &&
924 browser_creator_->is_default_browser_dialog_suppressed())) && 895 browser_creator_->is_default_browser_dialog_suppressed())) &&
925 !chrome::ShowAutolaunchPrompt(browser)) { 896 !chrome::ShowAutolaunchPrompt(browser)) {
926 chrome::ShowDefaultBrowserPrompt(profile_, 897 chrome::ShowDefaultBrowserPrompt(profile_,
927 browser->host_desktop_type()); 898 browser->host_desktop_type());
928 } 899 }
929 } 900 }
930 } 901 }
931 } 902 }
932 903
933
934 void StartupBrowserCreatorImpl::AddStartupURLs( 904 void StartupBrowserCreatorImpl::AddStartupURLs(
935 std::vector<GURL>* startup_urls) const { 905 std::vector<GURL>* startup_urls) const {
936 // If we have urls specified by the first run master preferences use them 906 // If we have urls specified by the first run master preferences use them
937 // and nothing else. 907 // and nothing else.
938 if (browser_creator_ && startup_urls->empty()) { 908 if (browser_creator_ && startup_urls->empty()) {
939 if (!browser_creator_->first_run_tabs_.empty()) { 909 if (!browser_creator_->first_run_tabs_.empty()) {
940 std::vector<GURL>::iterator it = 910 std::vector<GURL>::iterator it =
941 browser_creator_->first_run_tabs_.begin(); 911 browser_creator_->first_run_tabs_.begin();
942 while (it != browser_creator_->first_run_tabs_.end()) { 912 while (it != browser_creator_->first_run_tabs_.end()) {
943 // Replace magic names for the actual urls. 913 // Replace magic names for the actual urls.
(...skipping 11 matching lines...) Expand all
955 } 925 }
956 926
957 // Otherwise open at least the new tab page (and the welcome page, if this 927 // Otherwise open at least the new tab page (and the welcome page, if this
958 // is the first time the browser is being started), or the set of URLs 928 // is the first time the browser is being started), or the set of URLs
959 // specified on the command line. 929 // specified on the command line.
960 if (startup_urls->empty()) { 930 if (startup_urls->empty()) {
961 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); 931 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL));
962 if (first_run::ShouldShowWelcomePage()) 932 if (first_run::ShouldShowWelcomePage())
963 startup_urls->push_back(internals::GetWelcomePageURL()); 933 startup_urls->push_back(internals::GetWelcomePageURL());
964 } 934 }
935
936 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_)) {
937 SyncPromoUI::DidShowSyncPromoAtStartup(profile_);
938
939 const GURL sync_promo_url = SyncPromoUI::GetSyncPromoURL(
940 SyncPromoUI::SOURCE_START_PAGE, false);
941
942 // No need to add if the sync promo is already in the startup list.
943 bool add_promo = true;
944 for (std::vector<GURL>::const_iterator it = startup_urls->begin();
945 it != startup_urls->end(); ++it) {
946 if (*it == sync_promo_url) {
947 add_promo = false;
948 break;
949 }
950 }
951
952 if (add_promo) {
953 // If the first URL is the NTP, replace it with the sync promo. This
954 // behavior is desired because completing or skipping the sync promo
955 // causes a redirect to the NTP.
956 if (!startup_urls->empty() && IsNewTabURL(profile_, startup_urls->at(0)))
957 startup_urls->at(0) = sync_promo_url;
958 else
959 startup_urls->insert(startup_urls->begin(), sync_promo_url);
960 }
961 }
965 } 962 }
966 963
967 #if !defined(OS_WIN) 964 #if !defined(OS_WIN)
968 // static 965 // static
969 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( 966 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser(
970 Profile* profile, 967 Profile* profile,
971 const std::vector<GURL>& startup_urls) { 968 const std::vector<GURL>& startup_urls) {
972 return false; 969 return false;
973 } 970 }
974 #endif 971 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698