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

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: Addressing review comments 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 // Weak pointer to the profile, not owned by us.
170 Profile* profile_;
171
168 // Used to delay the expiration of the info-bar. 172 // Used to delay the expiration of the info-bar.
169 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_; 173 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_;
170 174
171 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); 175 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate);
172 }; 176 };
173 177
174 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( 178 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate(
175 InfoBarTabHelper* infobar_helper, 179 InfoBarTabHelper* infobar_helper,
176 PrefService* prefs) 180 PrefService* prefs,
181 Profile* profile)
177 : ConfirmInfoBarDelegate(infobar_helper), 182 : ConfirmInfoBarDelegate(infobar_helper),
178 prefs_(prefs), 183 prefs_(prefs),
179 action_taken_(false), 184 action_taken_(false),
180 should_expire_(false), 185 should_expire_(false),
186 profile_(profile),
181 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 187 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
182 auto_launch_trial::UpdateInfobarShownMetric(); 188 auto_launch_trial::UpdateInfobarShownMetric();
183 189
184 int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar); 190 int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar);
185 prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1); 191 prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1);
186 192
187 // We want the info-bar to stick-around for a few seconds and then be hidden 193 // We want the info-bar to stick-around for a few seconds and then be hidden
188 // on the next navigation after that. 194 // on the next navigation after that.
189 MessageLoop::current()->PostDelayedTask( 195 MessageLoop::current()->PostDelayedTask(
190 FROM_HERE, 196 FROM_HERE,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Track infobar reponse. 239 // Track infobar reponse.
234 auto_launch_trial::UpdateInfobarResponseMetric( 240 auto_launch_trial::UpdateInfobarResponseMetric(
235 auto_launch_trial::INFOBAR_CUT_IT_OUT); 241 auto_launch_trial::INFOBAR_CUT_IT_OUT);
236 // Also make sure we keep track of how many disable and how many enable. 242 // Also make sure we keep track of how many disable and how many enable.
237 const bool auto_launch = false; 243 const bool auto_launch = false;
238 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch); 244 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch);
239 245
240 content::BrowserThread::PostTask( 246 content::BrowserThread::PostTask(
241 content::BrowserThread::FILE, FROM_HERE, 247 content::BrowserThread::FILE, FROM_HERE,
242 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, 248 base::Bind(&auto_launch_util::SetWillLaunchAtLogin,
243 auto_launch, FilePath())); 249 auto_launch,
250 FilePath(),
251 profile_->GetPath().BaseName().value()));
244 return true; 252 return true;
245 } 253 }
246 254
247 #endif // OS_WIN 255 #endif // OS_WIN
248 256
249 // DefaultBrowserInfoBarDelegate ---------------------------------------------- 257 // DefaultBrowserInfoBarDelegate ----------------------------------------------
250 258
251 // The delegate for the infobar shown when Chrome is not the default browser. 259 // The delegate for the infobar shown when Chrome is not the default browser.
252 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { 260 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
253 public: 261 public:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 Browser* browser = BrowserList::GetLastActive(); 364 Browser* browser = BrowserList::GetLastActive();
357 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); 365 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
358 366
359 // Don't show the info-bar if there are already info-bars showing. 367 // Don't show the info-bar if there are already info-bars showing.
360 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); 368 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
361 if (infobar_helper->infobar_count() > 0) 369 if (infobar_helper->infobar_count() > 0)
362 return; 370 return;
363 371
364 infobar_helper->AddInfoBar( 372 infobar_helper->AddInfoBar(
365 new AutolaunchInfoBarDelegate(infobar_helper, 373 new AutolaunchInfoBarDelegate(infobar_helper,
366 tab->profile()->GetPrefs())); 374 tab->profile()->GetPrefs(), tab->profile()));
367 } 375 }
368 #endif 376 #endif
369 377
370 void NotifyNotDefaultBrowserCallback() { 378 void NotifyNotDefaultBrowserCallback() {
371 Browser* browser = BrowserList::GetLastActive(); 379 Browser* browser = BrowserList::GetLastActive();
372 if (!browser) 380 if (!browser)
373 return; // Reached during ui tests. 381 return; // Reached during ui tests.
374 382
375 // In ChromeBot tests, there might be a race. This line appears to get 383 // In ChromeBot tests, there might be a race. This line appears to get
376 // called during shutdown and |tab| can be NULL. 384 // called during shutdown and |tab| can be NULL.
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 } 1486 }
1479 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 1487 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
1480 base::Bind(&CheckDefaultBrowserCallback)); 1488 base::Bind(&CheckDefaultBrowserCallback));
1481 } 1489 }
1482 1490
1483 bool BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) { 1491 bool BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) {
1484 #if defined(OS_WIN) 1492 #if defined(OS_WIN)
1485 if (!auto_launch_trial::IsInAutoLaunchGroup()) 1493 if (!auto_launch_trial::IsInAutoLaunchGroup())
1486 return false; 1494 return false;
1487 1495
1496 // Only supported on the main profile for now.
1497 if (profile->GetPath().BaseName().value() !=
1498 ASCIIToUTF16(chrome::kInitialProfile)) {
1499 return false;
1500 }
1501
1488 int infobar_shown = 1502 int infobar_shown =
1489 profile->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar); 1503 profile->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar);
1490 if (infobar_shown >= kMaxInfobarShown) 1504 if (infobar_shown >= kMaxInfobarShown)
1491 return false; 1505 return false;
1492 1506
1493 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1507 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1508 if (command_line.HasSwitch(switches::kChromeFrame))
1509 return false;
1510
1494 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || 1511 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) ||
1495 first_run::IsChromeFirstRun()) { 1512 first_run::IsChromeFirstRun()) {
1496 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1513 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1497 base::Bind(&CheckAutoLaunchCallback)); 1514 base::Bind(&CheckAutoLaunchCallback));
1498 return true; 1515 return true;
1499 } 1516 }
1500 #endif 1517 #endif
1501 return false; 1518 return false;
1502 } 1519 }
1503 1520
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 1849
1833 Profile* profile = ProfileManager::GetLastUsedProfile(); 1850 Profile* profile = ProfileManager::GetLastUsedProfile();
1834 if (!profile) { 1851 if (!profile) {
1835 // We should only be able to get here if the profile already exists and 1852 // We should only be able to get here if the profile already exists and
1836 // has been created. 1853 // has been created.
1837 NOTREACHED(); 1854 NOTREACHED();
1838 return; 1855 return;
1839 } 1856 }
1840 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); 1857 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL);
1841 } 1858 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698