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

Side by Side Diff: chrome/browser/ui/webui/options/browser_options_handler.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/webui/options/browser_options_handler.h" 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/path_service.h"
11 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/auto_launch_trial.h"
14 #include "chrome/browser/autocomplete/autocomplete.h" 16 #include "chrome/browser/autocomplete/autocomplete.h"
15 #include "chrome/browser/autocomplete/autocomplete_match.h" 17 #include "chrome/browser/autocomplete/autocomplete_match.h"
16 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/custom_home_pages_table_model.h" 19 #include "chrome/browser/custom_home_pages_table_model.h"
18 #include "chrome/browser/instant/instant_confirm_dialog.h" 20 #include "chrome/browser/instant/instant_confirm_dialog.h"
19 #include "chrome/browser/instant/instant_controller.h" 21 #include "chrome/browser/instant/instant_controller.h"
20 #include "chrome/browser/instant/instant_field_trial.h" 22 #include "chrome/browser/instant/instant_field_trial.h"
21 #include "chrome/browser/net/url_fixer_upper.h" 23 #include "chrome/browser/net/url_fixer_upper.h"
22 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/browser/prefs/session_startup_pref.h" 25 #include "chrome/browser/prefs/session_startup_pref.h"
24 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/search_engines/template_url.h" 27 #include "chrome/browser/search_engines/template_url.h"
26 #include "chrome/browser/search_engines/template_url_service.h" 28 #include "chrome/browser/search_engines/template_url_service.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 29 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/browser/ui/webui/favicon_source.h" 30 #include "chrome/browser/ui/webui/favicon_source.h"
29 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
32 #include "content/browser/user_metrics.h" 34 #include "content/browser/user_metrics.h"
33 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/notification_details.h" 36 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
36 #include "grit/chromium_strings.h" 38 #include "grit/chromium_strings.h"
37 #include "grit/generated_resources.h" 39 #include "grit/generated_resources.h"
38 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
39 41
42 #if defined(OS_WIN)
43 #include "chrome/installer/util/auto_launch_util.h"
44 #endif
45
46 using content::BrowserThread;
47
40 BrowserOptionsHandler::BrowserOptionsHandler() 48 BrowserOptionsHandler::BrowserOptionsHandler()
41 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { 49 : template_url_service_(NULL),
50 startup_custom_pages_table_model_(NULL),
51 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_file_(this)),
52 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_ui_(this)) {
42 #if !defined(OS_MACOSX) 53 #if !defined(OS_MACOSX)
43 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); 54 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
44 #endif 55 #endif
45 } 56 }
46 57
47 BrowserOptionsHandler::~BrowserOptionsHandler() { 58 BrowserOptionsHandler::~BrowserOptionsHandler() {
48 if (default_browser_worker_.get()) 59 if (default_browser_worker_.get())
49 default_browser_worker_->ObserverDestroyed(); 60 default_browser_worker_->ObserverDestroyed();
50 if (template_url_service_) 61 if (template_url_service_)
51 template_url_service_->RemoveObserver(this); 62 template_url_service_->RemoveObserver(this);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 IDS_OPTIONS_GENERAL_TAB_LABEL); 94 IDS_OPTIONS_GENERAL_TAB_LABEL);
84 95
85 localized_strings->SetString("instantLearnMoreLink", 96 localized_strings->SetString("instantLearnMoreLink",
86 ASCIIToUTF16(browser::InstantLearnMoreURL().spec())); 97 ASCIIToUTF16(browser::InstantLearnMoreURL().spec()));
87 localized_strings->SetString("defaultBrowserUnknown", 98 localized_strings->SetString("defaultBrowserUnknown",
88 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, 99 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
89 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 100 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
90 localized_strings->SetString("defaultBrowserUseAsDefault", 101 localized_strings->SetString("defaultBrowserUseAsDefault",
91 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, 102 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT,
92 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 103 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
104 localized_strings->SetString("autoLaunchText",
105 l10n_util::GetStringFUTF16(IDS_AUTOLAUNCH_TEXT,
106 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
93 } 107 }
94 108
95 void BrowserOptionsHandler::RegisterMessages() { 109 void BrowserOptionsHandler::RegisterMessages() {
96 web_ui_->RegisterMessageCallback("becomeDefaultBrowser", 110 web_ui_->RegisterMessageCallback("becomeDefaultBrowser",
97 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, 111 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser,
98 base::Unretained(this))); 112 base::Unretained(this)));
99 web_ui_->RegisterMessageCallback("setDefaultSearchEngine", 113 web_ui_->RegisterMessageCallback("setDefaultSearchEngine",
100 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, 114 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine,
101 base::Unretained(this))); 115 base::Unretained(this)));
102 web_ui_->RegisterMessageCallback("removeStartupPages", 116 web_ui_->RegisterMessageCallback("removeStartupPages",
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 new CustomHomePagesTableModel(profile)); 159 new CustomHomePagesTableModel(profile));
146 startup_custom_pages_table_model_->SetObserver(this); 160 startup_custom_pages_table_model_->SetObserver(this);
147 UpdateStartupPages(); 161 UpdateStartupPages();
148 162
149 pref_change_registrar_.Init(profile->GetPrefs()); 163 pref_change_registrar_.Init(profile->GetPrefs());
150 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this); 164 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this);
151 165
152 UpdateSearchEngines(); 166 UpdateSearchEngines();
153 167
154 autocomplete_controller_.reset(new AutocompleteController(profile, this)); 168 autocomplete_controller_.reset(new AutocompleteController(profile, this));
169
170 #if defined(OS_WIN)
171 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
172 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
173 weak_ptr_factory_for_ui_.GetWeakPtr(),
174 weak_ptr_factory_for_file_.GetWeakPtr()));
175 weak_ptr_factory_for_ui_.DetachFromThread();
176 #endif
177 }
178
179 void BrowserOptionsHandler::CheckAutoLaunch(
180 base::WeakPtr<BrowserOptionsHandler> weak_this) {
Jói 2011/12/14 16:44:13 Add this: DCHECK(BrowserThread::CurrentlyOn(Brows
181 #if defined(OS_WIN)
182 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
183 // deleted.
184 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
185 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
186 weak_this,
187 auto_launch_trial::IsInAutoLaunchGroup(),
188 auto_launch_util::WillLaunchAtLogin(FilePath())));
189 #endif
190 }
191
192 void BrowserOptionsHandler::CheckAutoLaunchCallback(
193 bool is_in_auto_launch_group,
194 bool will_launch_at_login) {
195 #if defined(OS_WIN)
Jói 2011/12/14 16:44:13 Add: DCHECK(BrowserThread::CurrentlyOn(BrowserThre
196 if (is_in_auto_launch_group) {
197 web_ui_->RegisterMessageCallback("toggleAutoLaunch",
198 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
199 base::Unretained(this)));
200
201 base::FundamentalValue enabled(will_launch_at_login);
202 web_ui_->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
203 enabled);
204 }
205 #endif
155 } 206 }
156 207
157 void BrowserOptionsHandler::UpdateDefaultBrowserState() { 208 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
158 // Check for side-by-side first. 209 // Check for side-by-side first.
159 if (!ShellIntegration::CanSetAsDefaultBrowser()) { 210 if (!ShellIntegration::CanSetAsDefaultBrowser()) {
160 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); 211 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS);
161 return; 212 return;
162 } 213 }
163 214
164 #if defined(OS_MACOSX) 215 #if defined(OS_MACOSX)
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 } 505 }
455 506
456 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { 507 void BrowserOptionsHandler::EnableInstant(const ListValue* args) {
457 InstantController::Enable(Profile::FromWebUI(web_ui_)); 508 InstantController::Enable(Profile::FromWebUI(web_ui_));
458 } 509 }
459 510
460 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { 511 void BrowserOptionsHandler::DisableInstant(const ListValue* args) {
461 InstantController::Disable(Profile::FromWebUI(web_ui_)); 512 InstantController::Disable(Profile::FromWebUI(web_ui_));
462 } 513 }
463 514
515 void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) {
516 #if defined(OS_WIN)
517 if (!auto_launch_trial::IsInAutoLaunchGroup())
518 return;
519
520 bool enable;
521 CHECK_EQ(args->GetSize(), 1U);
522 CHECK(args->GetBoolean(0, &enable));
523
524 // Make sure we keep track of how many disable and how many enable.
525 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable);
526 content::BrowserThread::PostTask(
527 content::BrowserThread::FILE, FROM_HERE,
528 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, FilePath()));
529 #endif // OS_WIN
530 }
531
464 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { 532 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) {
465 Profile* profile = Profile::FromWebUI(web_ui_); 533 Profile* profile = Profile::FromWebUI(web_ui_);
466 base::FundamentalValue enabled( 534 base::FundamentalValue enabled(
467 InstantFieldTrial::IsInstantExperiment(profile) && 535 InstantFieldTrial::IsInstantExperiment(profile) &&
468 !InstantFieldTrial::IsHiddenExperiment(profile)); 536 !InstantFieldTrial::IsHiddenExperiment(profile));
469 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", 537 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus",
470 enabled); 538 enabled);
471 } 539 }
472 540
473 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { 541 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) {
(...skipping 11 matching lines...) Expand all
485 DictionaryValue* entry = new DictionaryValue(); 553 DictionaryValue* entry = new DictionaryValue();
486 entry->SetString("title", match.description); 554 entry->SetString("title", match.description);
487 entry->SetString("displayURL", match.contents); 555 entry->SetString("displayURL", match.contents);
488 entry->SetString("url", match.destination_url.spec()); 556 entry->SetString("url", match.destination_url.spec());
489 suggestions.Append(entry); 557 suggestions.Append(entry);
490 } 558 }
491 559
492 web_ui_->CallJavascriptFunction( 560 web_ui_->CallJavascriptFunction(
493 "BrowserOptions.updateAutocompleteSuggestions", suggestions); 561 "BrowserOptions.updateAutocompleteSuggestions", suggestions);
494 } 562 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698