| 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/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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 } | 1494 } |
| 1487 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 1495 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 1488 base::Bind(&CheckDefaultBrowserCallback)); | 1496 base::Bind(&CheckDefaultBrowserCallback)); |
| 1489 } | 1497 } |
| 1490 | 1498 |
| 1491 bool BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) { | 1499 bool BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) { |
| 1492 #if defined(OS_WIN) | 1500 #if defined(OS_WIN) |
| 1493 if (!auto_launch_trial::IsInAutoLaunchGroup()) | 1501 if (!auto_launch_trial::IsInAutoLaunchGroup()) |
| 1494 return false; | 1502 return false; |
| 1495 | 1503 |
| 1504 // Only supported on the main profile for now. |
| 1505 if (profile->GetPath().BaseName().value() != |
| 1506 ASCIIToUTF16(chrome::kInitialProfile)) { |
| 1507 return false; |
| 1508 } |
| 1509 |
| 1496 int infobar_shown = | 1510 int infobar_shown = |
| 1497 profile->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar); | 1511 profile->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar); |
| 1498 if (infobar_shown >= kMaxInfobarShown) | 1512 if (infobar_shown >= kMaxInfobarShown) |
| 1499 return false; | 1513 return false; |
| 1500 | 1514 |
| 1501 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1515 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1516 if (command_line.HasSwitch(switches::kChromeFrame)) |
| 1517 return false; |
| 1518 |
| 1502 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || | 1519 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || |
| 1503 first_run::IsChromeFirstRun()) { | 1520 first_run::IsChromeFirstRun()) { |
| 1504 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1521 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 1505 base::Bind(&CheckAutoLaunchCallback)); | 1522 base::Bind(&CheckAutoLaunchCallback)); |
| 1506 return true; | 1523 return true; |
| 1507 } | 1524 } |
| 1508 #endif | 1525 #endif |
| 1509 return false; | 1526 return false; |
| 1510 } | 1527 } |
| 1511 | 1528 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 | 1861 |
| 1845 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1862 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 1846 if (!profile) { | 1863 if (!profile) { |
| 1847 // We should only be able to get here if the profile already exists and | 1864 // We should only be able to get here if the profile already exists and |
| 1848 // has been created. | 1865 // has been created. |
| 1849 NOTREACHED(); | 1866 NOTREACHED(); |
| 1850 return; | 1867 return; |
| 1851 } | 1868 } |
| 1852 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); | 1869 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
| 1853 } | 1870 } |
| OLD | NEW |