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

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: sync'ed and addressed gtr's 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/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 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
176 weak_ptr_factory_for_file_.GetWeakPtr())); 179 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
177 weak_ptr_factory_for_ui_.DetachFromThread(); 180 weak_ptr_factory_for_ui_.GetWeakPtr(),
181 weak_ptr_factory_for_file_.GetWeakPtr(),
182 profile->GetPath()));
183 weak_ptr_factory_for_ui_.DetachFromThread();
184 }
178 #endif 185 #endif
179 } 186 }
180 187
181 void BrowserOptionsHandler::CheckAutoLaunch( 188 void BrowserOptionsHandler::CheckAutoLaunch(
182 base::WeakPtr<BrowserOptionsHandler> weak_this) { 189 base::WeakPtr<BrowserOptionsHandler> weak_this,
190 const FilePath& profile_path) {
183 #if defined(OS_WIN) 191 #if defined(OS_WIN)
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
185 193
194 // We don't support this for secondary profiles yet.
195 if (profile_path.BaseName().value() != ASCIIToUTF16(chrome::kInitialProfile))
196 return;
197
186 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is 198 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
187 // deleted. 199 // deleted.
188 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 200 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
189 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, 201 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
190 weak_this, 202 weak_this,
191 auto_launch_trial::IsInAutoLaunchGroup(), 203 auto_launch_trial::IsInAutoLaunchGroup(),
192 auto_launch_util::WillLaunchAtLogin(FilePath()))); 204 auto_launch_util::WillLaunchAtLogin(
205 FilePath(),
206 profile_path.BaseName().value())));
193 #endif 207 #endif
194 } 208 }
195 209
196 void BrowserOptionsHandler::CheckAutoLaunchCallback( 210 void BrowserOptionsHandler::CheckAutoLaunchCallback(
197 bool is_in_auto_launch_group, 211 bool is_in_auto_launch_group,
198 bool will_launch_at_login) { 212 bool will_launch_at_login) {
199 #if defined(OS_WIN) 213 #if defined(OS_WIN)
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
201 215
202 if (is_in_auto_launch_group) { 216 if (is_in_auto_launch_group) {
203 web_ui()->RegisterMessageCallback("toggleAutoLaunch", 217 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
204 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, 218 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
205 base::Unretained(this))); 219 base::Unretained(this)));
206 220
207 base::FundamentalValue enabled(will_launch_at_login); 221 base::FundamentalValue enabled(will_launch_at_login);
208 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", 222 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
209 enabled); 223 enabled);
210 } 224 }
211 #endif 225 #endif
212 } 226 }
213 227
214 void BrowserOptionsHandler::UpdateDefaultBrowserState() { 228 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
215 // Check for side-by-side first. 229 // Check for side-by-side first.
216 if (!ShellIntegration::CanSetAsDefaultBrowser()) { 230 if (!ShellIntegration::CanSetAsDefaultBrowser()) {
217 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); 231 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS);
218 return; 232 return;
219 } 233 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 #if defined(OS_WIN) 537 #if defined(OS_WIN)
524 if (!auto_launch_trial::IsInAutoLaunchGroup()) 538 if (!auto_launch_trial::IsInAutoLaunchGroup())
525 return; 539 return;
526 540
527 bool enable; 541 bool enable;
528 CHECK_EQ(args->GetSize(), 1U); 542 CHECK_EQ(args->GetSize(), 1U);
529 CHECK(args->GetBoolean(0, &enable)); 543 CHECK(args->GetBoolean(0, &enable));
530 544
531 // Make sure we keep track of how many disable and how many enable. 545 // Make sure we keep track of how many disable and how many enable.
532 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); 546 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable);
547 Profile* profile = Profile::FromWebUI(web_ui());
533 content::BrowserThread::PostTask( 548 content::BrowserThread::PostTask(
534 content::BrowserThread::FILE, FROM_HERE, 549 content::BrowserThread::FILE, FROM_HERE,
535 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, FilePath())); 550 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable,
551 FilePath(), profile->GetPath().BaseName().value()));
536 #endif // OS_WIN 552 #endif // OS_WIN
537 } 553 }
538 554
539 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { 555 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) {
540 Profile* profile = Profile::FromWebUI(web_ui()); 556 Profile* profile = Profile::FromWebUI(web_ui());
541 base::FundamentalValue enabled( 557 base::FundamentalValue enabled(
542 InstantFieldTrial::IsInstantExperiment(profile) && 558 InstantFieldTrial::IsInstantExperiment(profile) &&
543 !InstantFieldTrial::IsHiddenExperiment(profile)); 559 !InstantFieldTrial::IsHiddenExperiment(profile));
544 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", 560 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus",
545 enabled); 561 enabled);
(...skipping 14 matching lines...) Expand all
560 DictionaryValue* entry = new DictionaryValue(); 576 DictionaryValue* entry = new DictionaryValue();
561 entry->SetString("title", match.description); 577 entry->SetString("title", match.description);
562 entry->SetString("displayURL", match.contents); 578 entry->SetString("displayURL", match.contents);
563 entry->SetString("url", match.destination_url.spec()); 579 entry->SetString("url", match.destination_url.spec());
564 suggestions.Append(entry); 580 suggestions.Append(entry);
565 } 581 }
566 582
567 web_ui()->CallJavascriptFunction( 583 web_ui()->CallJavascriptFunction(
568 "BrowserOptions.updateAutocompleteSuggestions", suggestions); 584 "BrowserOptions.updateAutocompleteSuggestions", suggestions);
569 } 585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698