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

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

Issue 8729009: Implement an AutoLaunch experiment for Chrome for certain brand codes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/environment.h" 12 #include "base/environment.h"
13 #include "base/event_recorder.h" 13 #include "base/event_recorder.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_split.h" 20 #include "base/string_split.h"
21 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "chrome/browser/auto_launch_trial.h"
23 #include "chrome/browser/automation/automation_provider.h" 24 #include "chrome/browser/automation/automation_provider.h"
24 #include "chrome/browser/automation/automation_provider_list.h" 25 #include "chrome/browser/automation/automation_provider_list.h"
25 #include "chrome/browser/automation/chrome_frame_automation_provider.h" 26 #include "chrome/browser/automation/chrome_frame_automation_provider.h"
26 #include "chrome/browser/automation/testing_automation_provider.h" 27 #include "chrome/browser/automation/testing_automation_provider.h"
27 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/component_updater/component_updater_service.h" 29 #include "chrome/browser/component_updater/component_updater_service.h"
29 #include "chrome/browser/component_updater/flash_component_installer.h" 30 #include "chrome/browser/component_updater/flash_component_installer.h"
30 #include "chrome/browser/component_updater/recovery_component_installer.h" 31 #include "chrome/browser/component_updater/recovery_component_installer.h"
31 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
32 #include "chrome/browser/defaults.h" 33 #include "chrome/browser/defaults.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 #include "chrome/browser/chromeos/sms_observer.h" 107 #include "chrome/browser/chromeos/sms_observer.h"
107 #if defined(TOOLKIT_USES_GTK) 108 #if defined(TOOLKIT_USES_GTK)
108 #include "chrome/browser/chromeos/legacy_window_manager/wm_message_listener.h" 109 #include "chrome/browser/chromeos/legacy_window_manager/wm_message_listener.h"
109 #endif 110 #endif
110 #endif 111 #endif
111 112
112 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) 113 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX)
113 #include "ui/base/touch/touch_factory.h" 114 #include "ui/base/touch/touch_factory.h"
114 #endif 115 #endif
115 116
117 #if defined(OS_WIN)
118 #include "chrome/installer/util/auto_launch_util.h"
119 #endif
120
116 using content::BrowserThread; 121 using content::BrowserThread;
117 122
118 namespace { 123 namespace {
119 124
125 static const int kMaxInfobarShown = 5;
126
127 #if defined(OS_WIN)
128 // The delegate for the infobar shown when Chrome was auto-launched.
129 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate {
130 public:
131 AutolaunchInfoBarDelegate(InfoBarTabHelper* infobar_helper,
132 PrefService* prefs);
133 virtual ~AutolaunchInfoBarDelegate();
134
135 private:
136 void AllowExpiry() { should_expire_ = true; }
137
138 // ConfirmInfoBarDelegate:
139 virtual bool ShouldExpire(
140 const content::LoadCommittedDetails& details) const OVERRIDE;
141 virtual gfx::Image* GetIcon() const OVERRIDE;
142 virtual string16 GetMessageText() const OVERRIDE;
143 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
144 virtual bool Accept() OVERRIDE;
145 virtual bool Cancel() OVERRIDE;
146
147 // The prefs to use.
148 PrefService* prefs_;
149
150 // Whether the user clicked one of the buttons.
151 bool action_taken_;
152
153 // Whether the info-bar should be dismissed on the next navigation.
154 bool should_expire_;
155
156 // Used to delay the expiration of the info-bar.
157 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_;
158
159 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate);
160 };
161
162 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate(
163 InfoBarTabHelper* infobar_helper,
164 PrefService* prefs)
165 : ConfirmInfoBarDelegate(infobar_helper),
166 prefs_(prefs),
167 action_taken_(false),
168 should_expire_(false),
169 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
170 auto_launch_trial::UpdateInfobarShownMetric();
171
172 int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar);
173 prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1);
174
175 // We want the info-bar to stick-around for a few seconds and then be hidden
176 // on the next navigation after that.
177 MessageLoop::current()->PostDelayedTask(
178 FROM_HERE,
179 base::Bind(&AutolaunchInfoBarDelegate::AllowExpiry,
180 weak_factory_.GetWeakPtr()),
181 8000); // 8 seconds.
182 }
183
184 AutolaunchInfoBarDelegate::~AutolaunchInfoBarDelegate() {
185 if (!action_taken_) {
186 auto_launch_trial::UpdateInfobarResponseMetric(
187 auto_launch_trial::INFOBAR_IGNORE);
188 }
189 }
190
191 bool AutolaunchInfoBarDelegate::ShouldExpire(
192 const content::LoadCommittedDetails& details) const {
193 return details.is_navigation_to_different_page() && should_expire_;
194 }
195
196 gfx::Image* AutolaunchInfoBarDelegate::GetIcon() const {
197 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
198 IDR_PRODUCT_LOGO_32);
199 }
200
201 string16 AutolaunchInfoBarDelegate::GetMessageText() const {
202 return l10n_util::GetStringFUTF16(IDS_AUTO_LAUNCH_INFOBAR_TEXT,
203 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
204 }
205
206 string16 AutolaunchInfoBarDelegate::GetButtonLabel(
207 InfoBarButton button) const {
208 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
209 IDS_AUTO_LAUNCH_OK : IDS_AUTO_LAUNCH_REVERT);
210 }
211
212 bool AutolaunchInfoBarDelegate::Accept() {
213 action_taken_ = true;
214 auto_launch_trial::UpdateInfobarResponseMetric(
215 auto_launch_trial::INFOBAR_OK);
216 return true;
217 }
218
219 bool AutolaunchInfoBarDelegate::Cancel() {
220 action_taken_ = true;
221
222 // Track infobar reponse.
223 auto_launch_trial::UpdateInfobarResponseMetric(
224 auto_launch_trial::INFOBAR_CUT_IT_OUT);
225 // Also make sure we keep track of how many disable and how many enable.
226 const bool auto_launch = false;
227 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch);
228
229 content::BrowserThread::PostTask(
230 content::BrowserThread::FILE, FROM_HERE,
231 base::Bind(&auto_launch_util::SetWillLaunchAtLogin,
232 auto_launch, FilePath()));
233 return true;
234 }
235
236 #endif // OS_WIN
237
120 // DefaultBrowserInfoBarDelegate ---------------------------------------------- 238 // DefaultBrowserInfoBarDelegate ----------------------------------------------
121 239
122 // The delegate for the infobar shown when Chrome is not the default browser. 240 // The delegate for the infobar shown when Chrome is not the default browser.
123 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { 241 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
124 public: 242 public:
125 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, 243 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper,
126 PrefService* prefs); 244 PrefService* prefs);
127 245
128 private: 246 private:
129 virtual ~DefaultBrowserInfoBarDelegate(); 247 virtual ~DefaultBrowserInfoBarDelegate();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 330 }
213 331
214 bool DefaultBrowserInfoBarDelegate::Cancel() { 332 bool DefaultBrowserInfoBarDelegate::Cancel() {
215 action_taken_ = true; 333 action_taken_ = true;
216 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); 334 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1);
217 // User clicked "Don't ask me again", remember that. 335 // User clicked "Don't ask me again", remember that.
218 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); 336 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false);
219 return true; 337 return true;
220 } 338 }
221 339
340 #if defined(OS_WIN)
341 void CheckAutoLaunchCallback() {
342 if (!auto_launch_trial::IsInAutoLaunchGroup())
343 return;
344
345 Browser* browser = BrowserList::GetLastActive();
346 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
347
348 int infobar_shown =
349 tab->profile()->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar);
350 if (infobar_shown >= kMaxInfobarShown)
351 return;
352
353 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
354 infobar_helper->AddInfoBar(
355 new AutolaunchInfoBarDelegate(infobar_helper,
356 tab->profile()->GetPrefs()));
357 }
358 #endif
359
222 void NotifyNotDefaultBrowserCallback() { 360 void NotifyNotDefaultBrowserCallback() {
223 Browser* browser = BrowserList::GetLastActive(); 361 Browser* browser = BrowserList::GetLastActive();
224 if (!browser) 362 if (!browser)
225 return; // Reached during ui tests. 363 return; // Reached during ui tests.
226 364
227 // In ChromeBot tests, there might be a race. This line appears to get 365 // In ChromeBot tests, there might be a race. This line appears to get
228 // called during shutdown and |tab| can be NULL. 366 // called during shutdown and |tab| can be NULL.
229 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); 367 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
230 if (!tab) 368 if (!tab)
231 return; 369 return;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 640
503 void BrowserInit::AddFirstRunTab(const GURL& url) { 641 void BrowserInit::AddFirstRunTab(const GURL& url) {
504 first_run_tabs_.push_back(url); 642 first_run_tabs_.push_back(url);
505 } 643 }
506 644
507 // static 645 // static
508 bool BrowserInit::InProcessStartup() { 646 bool BrowserInit::InProcessStartup() {
509 return in_startup; 647 return in_startup;
510 } 648 }
511 649
650 // static
651 void BrowserInit::RegisterUserPrefs(PrefService* prefs) {
652 prefs->RegisterIntegerPref(
653 prefs::kShownAutoLaunchInfobar, 0, PrefService::UNSYNCABLE_PREF);
654 }
655
512 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, 656 bool BrowserInit::LaunchBrowser(const CommandLine& command_line,
513 Profile* profile, 657 Profile* profile,
514 const FilePath& cur_dir, 658 const FilePath& cur_dir,
515 IsProcessStartup process_startup, 659 IsProcessStartup process_startup,
516 IsFirstRun is_first_run, 660 IsFirstRun is_first_run,
517 int* return_code) { 661 int* return_code) {
518 in_startup = process_startup == IS_PROCESS_STARTUP; 662 in_startup = process_startup == IS_PROCESS_STARTUP;
519 DCHECK(profile); 663 DCHECK(profile);
520 664
521 // Continue with the incognito profile from here on if Incognito mode 665 // Continue with the incognito profile from here on if Incognito mode
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 LM_TO_BE_DECIDED : LM_WITH_URLS); 811 LM_TO_BE_DECIDED : LM_WITH_URLS);
668 ProcessLaunchURLs(process_startup, urls_to_open); 812 ProcessLaunchURLs(process_startup, urls_to_open);
669 813
670 // If this is an app launch, but we didn't open an app window, it may 814 // If this is an app launch, but we didn't open an app window, it may
671 // be an app tab. 815 // be an app tab.
672 OpenApplicationTab(profile); 816 OpenApplicationTab(profile);
673 817
674 if (process_startup) { 818 if (process_startup) {
675 if (browser_defaults::kOSSupportsOtherBrowsers && 819 if (browser_defaults::kOSSupportsOtherBrowsers &&
676 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { 820 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) {
821 CheckIfAutoLaunched(profile);
822
677 // Check whether we are the default browser. 823 // Check whether we are the default browser.
678 CheckDefaultBrowser(profile); 824 CheckDefaultBrowser(profile);
679 } 825 }
680 #if defined(OS_MACOSX) 826 #if defined(OS_MACOSX)
681 // Check whether the auto-update system needs to be promoted from user 827 // Check whether the auto-update system needs to be promoted from user
682 // to system. 828 // to system.
683 KeystoneInfoBar::PromotionInfoBar(profile); 829 KeystoneInfoBar::PromotionInfoBar(profile);
684 #endif 830 #endif
685 } 831 }
686 } 832 }
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 } else { 1423 } else {
1278 // TODO(pastarmovj): We can't really do anything meaningful here yet but 1424 // TODO(pastarmovj): We can't really do anything meaningful here yet but
1279 // just prevent showing the infobar. 1425 // just prevent showing the infobar.
1280 } 1426 }
1281 return; 1427 return;
1282 } 1428 }
1283 BrowserThread::PostTask( 1429 BrowserThread::PostTask(
1284 BrowserThread::FILE, FROM_HERE, base::Bind(&CheckDefaultBrowserCallback)); 1430 BrowserThread::FILE, FROM_HERE, base::Bind(&CheckDefaultBrowserCallback));
1285 } 1431 }
1286 1432
1433 void BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) {
1434 #if defined(OS_WIN)
1435 if (!auto_launch_trial::IsInAutoLaunchGroup())
1436 return;
1437
1438 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1439 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup)) {
1440 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1441 base::Bind(&CheckAutoLaunchCallback));
1442 }
1443 #endif
1444 }
1445
1287 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( 1446 std::vector<GURL> BrowserInit::GetURLsFromCommandLine(
1288 const CommandLine& command_line, 1447 const CommandLine& command_line,
1289 const FilePath& cur_dir, 1448 const FilePath& cur_dir,
1290 Profile* profile) { 1449 Profile* profile) {
1291 std::vector<GURL> urls; 1450 std::vector<GURL> urls;
1292 const CommandLine::StringVector& params = command_line.GetArgs(); 1451 const CommandLine::StringVector& params = command_line.GetArgs();
1293 1452
1294 for (size_t i = 0; i < params.size(); ++i) { 1453 for (size_t i = 0; i < params.size(); ++i) {
1295 FilePath param = FilePath(params[i]); 1454 FilePath param = FilePath(params[i]);
1296 // Handle Vista way of searching - "? <search-term>" 1455 // Handle Vista way of searching - "? <search-term>"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 if (!automation->InitializeChannel(channel_id)) 1648 if (!automation->InitializeChannel(channel_id))
1490 return false; 1649 return false;
1491 automation->SetExpectedTabCount(expected_tabs); 1650 automation->SetExpectedTabCount(expected_tabs);
1492 1651
1493 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); 1652 AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
1494 DCHECK(list); 1653 DCHECK(list);
1495 list->AddProvider(automation); 1654 list->AddProvider(automation);
1496 1655
1497 return true; 1656 return true;
1498 } 1657 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698