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

Side by Side Diff: chrome/browser/ui/webui/options/browser_options_handler.cc

Issue 9317002: Make the auto-launch experiment profile-aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressed Miranda's comments, for realz this time 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/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/command_line.h"
10 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
11 #include "base/path_service.h" 12 #include "base/path_service.h"
12 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/auto_launch_trial.h" 16 #include "chrome/browser/auto_launch_trial.h"
16 #include "chrome/browser/autocomplete/autocomplete.h" 17 #include "chrome/browser/autocomplete/autocomplete.h"
17 #include "chrome/browser/autocomplete/autocomplete_match.h" 18 #include "chrome/browser/autocomplete/autocomplete_match.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/custom_home_pages_table_model.h" 20 #include "chrome/browser/custom_home_pages_table_model.h"
20 #include "chrome/browser/instant/instant_confirm_dialog.h" 21 #include "chrome/browser/instant/instant_confirm_dialog.h"
21 #include "chrome/browser/instant/instant_controller.h" 22 #include "chrome/browser/instant/instant_controller.h"
22 #include "chrome/browser/instant/instant_field_trial.h" 23 #include "chrome/browser/instant/instant_field_trial.h"
23 #include "chrome/browser/net/url_fixer_upper.h" 24 #include "chrome/browser/net/url_fixer_upper.h"
24 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/prefs/session_startup_pref.h" 26 #include "chrome/browser/prefs/session_startup_pref.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/search_engines/template_url.h" 28 #include "chrome/browser/search_engines/template_url.h"
28 #include "chrome/browser/search_engines/template_url_service.h" 29 #include "chrome/browser/search_engines/template_url_service.h"
29 #include "chrome/browser/search_engines/template_url_service_factory.h" 30 #include "chrome/browser/search_engines/template_url_service_factory.h"
30 #include "chrome/browser/ui/webui/favicon_source.h" 31 #include "chrome/browser/ui/webui/favicon_source.h"
32 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_notification_types.h" 33 #include "chrome/common/chrome_notification_types.h"
34 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
33 #include "chrome/common/url_constants.h" 36 #include "chrome/common/url_constants.h"
34 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/notification_details.h" 38 #include "content/public/browser/notification_details.h"
36 #include "content/public/browser/notification_source.h" 39 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/user_metrics.h" 40 #include "content/public/browser/user_metrics.h"
38 #include "content/public/browser/web_ui.h" 41 #include "content/public/browser/web_ui.h"
39 #include "grit/chromium_strings.h" 42 #include "grit/chromium_strings.h"
40 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
41 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 UpdateStartupPages(); 166 UpdateStartupPages();
164 167
165 pref_change_registrar_.Init(profile->GetPrefs()); 168 pref_change_registrar_.Init(profile->GetPrefs());
166 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this); 169 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this);
167 170
168 UpdateSearchEngines(); 171 UpdateSearchEngines();
169 172
170 autocomplete_controller_.reset(new AutocompleteController(profile, this)); 173 autocomplete_controller_.reset(new AutocompleteController(profile, this));
171 174
172 #if defined(OS_WIN) 175 #if defined(OS_WIN)
173 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 176 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
174 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, 177 if (!command_line.HasSwitch(switches::kChromeFrame) &&
175 weak_ptr_factory_for_ui_.GetWeakPtr(), 178 !command_line.HasSwitch(switches::kUserDataDir)) {
176 weak_ptr_factory_for_file_.GetWeakPtr())); 179 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
177 weak_ptr_factory_for_ui_.DetachFromThread(); 180 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
181 weak_ptr_factory_for_ui_.GetWeakPtr(),
182 weak_ptr_factory_for_file_.GetWeakPtr(),
183 profile->GetPath()));
184 weak_ptr_factory_for_ui_.DetachFromThread();
185 }
178 #endif 186 #endif
179 } 187 }
180 188
181 void BrowserOptionsHandler::CheckAutoLaunch( 189 void BrowserOptionsHandler::CheckAutoLaunch(
182 base::WeakPtr<BrowserOptionsHandler> weak_this) { 190 base::WeakPtr<BrowserOptionsHandler> weak_this,
191 const FilePath& profile_path) {
183 #if defined(OS_WIN) 192 #if defined(OS_WIN)
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
185 194
195 // Auto-launch is not supported for secondary profiles yet.
196 if (profile_path.BaseName().value() != ASCIIToUTF16(chrome::kInitialProfile))
197 return;
198
186 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is 199 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
187 // deleted. 200 // deleted.
188 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 201 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
189 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, 202 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
190 weak_this, 203 weak_this,
191 auto_launch_trial::IsInAutoLaunchGroup(), 204 auto_launch_trial::IsInAutoLaunchGroup(),
192 auto_launch_util::WillLaunchAtLogin(FilePath()))); 205 auto_launch_util::WillLaunchAtLogin(
206 FilePath(),
207 profile_path.BaseName().value())));
193 #endif 208 #endif
194 } 209 }
195 210
196 void BrowserOptionsHandler::CheckAutoLaunchCallback( 211 void BrowserOptionsHandler::CheckAutoLaunchCallback(
197 bool is_in_auto_launch_group, 212 bool is_in_auto_launch_group,
198 bool will_launch_at_login) { 213 bool will_launch_at_login) {
199 #if defined(OS_WIN) 214 #if defined(OS_WIN)
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
201 216
202 if (is_in_auto_launch_group) { 217 if (is_in_auto_launch_group) {
203 web_ui()->RegisterMessageCallback("toggleAutoLaunch", 218 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
204 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, 219 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
205 base::Unretained(this))); 220 base::Unretained(this)));
206 221
207 base::FundamentalValue enabled(will_launch_at_login); 222 base::FundamentalValue enabled(will_launch_at_login);
208 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", 223 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
209 enabled); 224 enabled);
210 } 225 }
211 #endif 226 #endif
212 } 227 }
213 228
214 void BrowserOptionsHandler::UpdateDefaultBrowserState() { 229 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
215 // Check for side-by-side first. 230 // Check for side-by-side first.
216 if (!ShellIntegration::CanSetAsDefaultBrowser()) { 231 if (!ShellIntegration::CanSetAsDefaultBrowser()) {
217 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); 232 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS);
218 return; 233 return;
219 } 234 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 #if defined(OS_WIN) 538 #if defined(OS_WIN)
524 if (!auto_launch_trial::IsInAutoLaunchGroup()) 539 if (!auto_launch_trial::IsInAutoLaunchGroup())
525 return; 540 return;
526 541
527 bool enable; 542 bool enable;
528 CHECK_EQ(args->GetSize(), 1U); 543 CHECK_EQ(args->GetSize(), 1U);
529 CHECK(args->GetBoolean(0, &enable)); 544 CHECK(args->GetBoolean(0, &enable));
530 545
531 // Make sure we keep track of how many disable and how many enable. 546 // Make sure we keep track of how many disable and how many enable.
532 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); 547 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable);
548 Profile* profile = Profile::FromWebUI(web_ui());
533 content::BrowserThread::PostTask( 549 content::BrowserThread::PostTask(
534 content::BrowserThread::FILE, FROM_HERE, 550 content::BrowserThread::FILE, FROM_HERE,
535 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, FilePath())); 551 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable,
552 FilePath(), profile->GetPath().BaseName().value()));
536 #endif // OS_WIN 553 #endif // OS_WIN
537 } 554 }
538 555
539 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { 556 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) {
540 Profile* profile = Profile::FromWebUI(web_ui()); 557 Profile* profile = Profile::FromWebUI(web_ui());
541 base::FundamentalValue enabled( 558 base::FundamentalValue enabled(
542 InstantFieldTrial::IsInstantExperiment(profile) && 559 InstantFieldTrial::IsInstantExperiment(profile) &&
543 !InstantFieldTrial::IsHiddenExperiment(profile)); 560 !InstantFieldTrial::IsHiddenExperiment(profile));
544 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", 561 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus",
545 enabled); 562 enabled);
(...skipping 14 matching lines...) Expand all
560 DictionaryValue* entry = new DictionaryValue(); 577 DictionaryValue* entry = new DictionaryValue();
561 entry->SetString("title", match.description); 578 entry->SetString("title", match.description);
562 entry->SetString("displayURL", match.contents); 579 entry->SetString("displayURL", match.contents);
563 entry->SetString("url", match.destination_url.spec()); 580 entry->SetString("url", match.destination_url.spec());
564 suggestions.Append(entry); 581 suggestions.Append(entry);
565 } 582 }
566 583
567 web_ui()->CallJavascriptFunction( 584 web_ui()->CallJavascriptFunction(
568 "BrowserOptions.updateAutocompleteSuggestions", suggestions); 585 "BrowserOptions.updateAutocompleteSuggestions", suggestions);
569 } 586 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/browser_options_handler.h ('k') | chrome/browser/ui/webui/options2/browser_options_handler2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698