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