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

Side by Side Diff: chrome/browser/ui/browser_init.cc

Issue 9317002: Make the auto-launch experiment profile-aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Uploading again post gclient sync (no other changes) Created 8 years, 10 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/browser_init.h" 5 #include "chrome/browser/ui/browser_init.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 namespace { 135 namespace {
136 136
137 static const int kMaxInfobarShown = 5; 137 static const int kMaxInfobarShown = 5;
138 138
139 #if defined(OS_WIN) 139 #if defined(OS_WIN)
140 // The delegate for the infobar shown when Chrome was auto-launched. 140 // The delegate for the infobar shown when Chrome was auto-launched.
141 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { 141 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate {
142 public: 142 public:
143 AutolaunchInfoBarDelegate(InfoBarTabHelper* infobar_helper, 143 AutolaunchInfoBarDelegate(InfoBarTabHelper* infobar_helper,
144 PrefService* prefs); 144 PrefService* prefs,
145 Profile* profile);
145 virtual ~AutolaunchInfoBarDelegate(); 146 virtual ~AutolaunchInfoBarDelegate();
146 147
147 private: 148 private:
148 void AllowExpiry() { should_expire_ = true; } 149 void AllowExpiry() { should_expire_ = true; }
149 150
150 // ConfirmInfoBarDelegate: 151 // ConfirmInfoBarDelegate:
151 virtual bool ShouldExpire( 152 virtual bool ShouldExpire(
152 const content::LoadCommittedDetails& details) const OVERRIDE; 153 const content::LoadCommittedDetails& details) const OVERRIDE;
153 virtual gfx::Image* GetIcon() const OVERRIDE; 154 virtual gfx::Image* GetIcon() const OVERRIDE;
154 virtual string16 GetMessageText() const OVERRIDE; 155 virtual string16 GetMessageText() const OVERRIDE;
155 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 156 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
156 virtual bool Accept() OVERRIDE; 157 virtual bool Accept() OVERRIDE;
157 virtual bool Cancel() OVERRIDE; 158 virtual bool Cancel() OVERRIDE;
158 159
159 // The prefs to use. 160 // The prefs to use.
160 PrefService* prefs_; 161 PrefService* prefs_;
161 162
162 // Whether the user clicked one of the buttons. 163 // Whether the user clicked one of the buttons.
163 bool action_taken_; 164 bool action_taken_;
164 165
165 // Whether the info-bar should be dismissed on the next navigation. 166 // Whether the info-bar should be dismissed on the next navigation.
166 bool should_expire_; 167 bool should_expire_;
167 168
169 Profile* profile_;
170
168 // Used to delay the expiration of the info-bar. 171 // Used to delay the expiration of the info-bar.
169 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_; 172 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_;
170 173
171 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); 174 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate);
172 }; 175 };
173 176
174 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( 177 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate(
175 InfoBarTabHelper* infobar_helper, 178 InfoBarTabHelper* infobar_helper,
176 PrefService* prefs) 179 PrefService* prefs,
180 Profile* profile)
177 : ConfirmInfoBarDelegate(infobar_helper), 181 : ConfirmInfoBarDelegate(infobar_helper),
178 prefs_(prefs), 182 prefs_(prefs),
179 action_taken_(false), 183 action_taken_(false),
180 should_expire_(false), 184 should_expire_(false),
185 profile_(profile),
181 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 186 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
182 auto_launch_trial::UpdateInfobarShownMetric(); 187 auto_launch_trial::UpdateInfobarShownMetric();
183 188
184 int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar); 189 int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar);
185 prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1); 190 prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1);
186 191
187 // We want the info-bar to stick-around for a few seconds and then be hidden 192 // We want the info-bar to stick-around for a few seconds and then be hidden
188 // on the next navigation after that. 193 // on the next navigation after that.
189 MessageLoop::current()->PostDelayedTask( 194 MessageLoop::current()->PostDelayedTask(
190 FROM_HERE, 195 FROM_HERE,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Track infobar reponse. 238 // Track infobar reponse.
234 auto_launch_trial::UpdateInfobarResponseMetric( 239 auto_launch_trial::UpdateInfobarResponseMetric(
235 auto_launch_trial::INFOBAR_CUT_IT_OUT); 240 auto_launch_trial::INFOBAR_CUT_IT_OUT);
236 // Also make sure we keep track of how many disable and how many enable. 241 // Also make sure we keep track of how many disable and how many enable.
237 const bool auto_launch = false; 242 const bool auto_launch = false;
238 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch); 243 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch);
239 244
240 content::BrowserThread::PostTask( 245 content::BrowserThread::PostTask(
241 content::BrowserThread::FILE, FROM_HERE, 246 content::BrowserThread::FILE, FROM_HERE,
242 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, 247 base::Bind(&auto_launch_util::SetWillLaunchAtLogin,
243 auto_launch, FilePath())); 248 auto_launch, FilePath(), profile_->GetPath()));
244 return true; 249 return true;
245 } 250 }
246 251
247 #endif // OS_WIN 252 #endif // OS_WIN
248 253
249 // DefaultBrowserInfoBarDelegate ---------------------------------------------- 254 // DefaultBrowserInfoBarDelegate ----------------------------------------------
250 255
251 // The delegate for the infobar shown when Chrome is not the default browser. 256 // The delegate for the infobar shown when Chrome is not the default browser.
252 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { 257 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
253 public: 258 public:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 Browser* browser = BrowserList::GetLastActive(); 361 Browser* browser = BrowserList::GetLastActive();
357 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); 362 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
358 363
359 // Don't show the info-bar if there are already info-bars showing. 364 // Don't show the info-bar if there are already info-bars showing.
360 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); 365 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
361 if (infobar_helper->infobar_count() > 0) 366 if (infobar_helper->infobar_count() > 0)
362 return; 367 return;
363 368
364 infobar_helper->AddInfoBar( 369 infobar_helper->AddInfoBar(
365 new AutolaunchInfoBarDelegate(infobar_helper, 370 new AutolaunchInfoBarDelegate(infobar_helper,
366 tab->profile()->GetPrefs())); 371 tab->profile()->GetPrefs(), tab->profile()));
367 } 372 }
368 #endif 373 #endif
369 374
370 void NotifyNotDefaultBrowserCallback() { 375 void NotifyNotDefaultBrowserCallback() {
371 Browser* browser = BrowserList::GetLastActive(); 376 Browser* browser = BrowserList::GetLastActive();
372 if (!browser) 377 if (!browser)
373 return; // Reached during ui tests. 378 return; // Reached during ui tests.
374 379
375 // In ChromeBot tests, there might be a race. This line appears to get 380 // In ChromeBot tests, there might be a race. This line appears to get
376 // called during shutdown and |tab| can be NULL. 381 // called during shutdown and |tab| can be NULL.
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 } 1483 }
1479 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 1484 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
1480 base::Bind(&CheckDefaultBrowserCallback)); 1485 base::Bind(&CheckDefaultBrowserCallback));
1481 } 1486 }
1482 1487
1483 bool BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) { 1488 bool BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) {
1484 #if defined(OS_WIN) 1489 #if defined(OS_WIN)
1485 if (!auto_launch_trial::IsInAutoLaunchGroup()) 1490 if (!auto_launch_trial::IsInAutoLaunchGroup())
1486 return false; 1491 return false;
1487 1492
1493 // Only supported on the main profile for now.
1494 if (profile->GetPath().BaseName().value() != ASCIIToUTF16("Default"))
grt (UTC plus 2) 2012/02/01 18:45:15 "Default" -> chrome::kInitialProfile
1495 return false;
1496
1488 int infobar_shown = 1497 int infobar_shown =
1489 profile->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar); 1498 profile->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar);
1490 if (infobar_shown >= kMaxInfobarShown) 1499 if (infobar_shown >= kMaxInfobarShown)
1491 return false; 1500 return false;
1492 1501
1493 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1502 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1494 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || 1503 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) ||
1495 first_run::IsChromeFirstRun()) { 1504 first_run::IsChromeFirstRun()) {
1496 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1505 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
grt (UTC plus 2) 2012/02/01 18:45:15 it just occurred to me that this should never run
Finnur 2012/02/06 16:30:36 This is already guarded against by the IsInAutoLau
grt (UTC plus 2) 2012/02/06 17:54:48 Since Chrome and Chrome Frame can use the same bit
1497 base::Bind(&CheckAutoLaunchCallback)); 1506 base::Bind(&CheckAutoLaunchCallback));
1498 return true; 1507 return true;
1499 } 1508 }
1500 #endif 1509 #endif
1501 return false; 1510 return false;
1502 } 1511 }
1503 1512
1504 size_t BrowserInit::LaunchWithProfile::ShowSyncPromoDialog( 1513 size_t BrowserInit::LaunchWithProfile::ShowSyncPromoDialog(
1505 bool process_startup, 1514 bool process_startup,
1506 Browser** browser, 1515 Browser** browser,
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 1841
1833 Profile* profile = ProfileManager::GetLastUsedProfile(); 1842 Profile* profile = ProfileManager::GetLastUsedProfile();
1834 if (!profile) { 1843 if (!profile) {
1835 // We should only be able to get here if the profile already exists and 1844 // We should only be able to get here if the profile already exists and
1836 // has been created. 1845 // has been created.
1837 NOTREACHED(); 1846 NOTREACHED();
1838 return; 1847 return;
1839 } 1848 }
1840 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); 1849 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL);
1841 } 1850 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698