| 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 <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 | 562 |
| 563 values->SetString("username", username); | 563 values->SetString("username", username); |
| 564 #endif | 564 #endif |
| 565 // Pass along sync status early so it will be available during page init. | 565 // Pass along sync status early so it will be available during page init. |
| 566 values->Set("syncData", GetSyncStateDictionary().release()); | 566 values->Set("syncData", GetSyncStateDictionary().release()); |
| 567 | 567 |
| 568 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); | 568 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); |
| 569 | 569 |
| 570 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); | 570 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); |
| 571 | 571 |
| 572 #if !defined(OS_CHROMEOS) | |
| 573 values->SetBoolean( | 572 values->SetBoolean( |
| 574 "metricsReportingEnabledAtStart", | 573 "metricsReportingEnabledAtStart", |
| 575 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 574 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
| 576 #endif | |
| 577 | 575 |
| 578 #if defined(OS_CHROMEOS) | 576 #if defined(OS_CHROMEOS) |
| 579 // TODO(pastarmovj): replace this with a call to the CrosSettings list | 577 // TODO(pastarmovj): replace this with a call to the CrosSettings list |
| 580 // handling functionality to come. | 578 // handling functionality to come. |
| 581 values->Set("timezoneList", chromeos::system::GetTimezoneList().release()); | 579 values->Set("timezoneList", chromeos::system::GetTimezoneList().release()); |
| 582 | 580 |
| 583 values->SetString("accessibilityLearnMoreURL", | 581 values->SetString("accessibilityLearnMoreURL", |
| 584 chrome::kChromeAccessibilityHelpURL); | 582 chrome::kChromeAccessibilityHelpURL); |
| 585 | 583 |
| 586 std::string settings_url = std::string("chrome-extension://") + | 584 std::string settings_url = std::string("chrome-extension://") + |
| (...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 extension = extensions::GetExtensionOverridingProxy( | 2065 extension = extensions::GetExtensionOverridingProxy( |
| 2068 Profile::FromWebUI(web_ui())); | 2066 Profile::FromWebUI(web_ui())); |
| 2069 AppendExtensionData("proxy", extension, &extension_controlled); | 2067 AppendExtensionData("proxy", extension, &extension_controlled); |
| 2070 | 2068 |
| 2071 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators", | 2069 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators", |
| 2072 extension_controlled); | 2070 extension_controlled); |
| 2073 #endif // defined(OS_WIN) | 2071 #endif // defined(OS_WIN) |
| 2074 } | 2072 } |
| 2075 | 2073 |
| 2076 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() { | 2074 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() { |
| 2077 // This function does not work for ChromeOS and non-official builds. | 2075 // As the metrics and crash reporting checkbox only exists for official builds |
| 2078 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) | 2076 // it doesn't need to be set up for non-official builds. |
| 2077 #if defined(GOOGLE_CHROME_BUILD) |
| 2079 bool checked = | 2078 bool checked = |
| 2080 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 2079 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
| 2081 bool disabled = !IsMetricsReportingUserChangable(); | 2080 bool policy_managed = IsMetricsReportingPolicyManaged(); |
| 2082 | 2081 bool owner_managed = false; |
| 2083 SetMetricsReportingCheckbox(checked, disabled); | 2082 #if defined(OS_CHROMEOS) |
| 2084 #endif | 2083 owner_managed = !IsDeviceOwnerProfile(); |
| 2084 #endif // defined(OS_CHROMEOS) |
| 2085 SetMetricsReportingCheckbox(checked, policy_managed, owner_managed); |
| 2086 #endif // defined(GOOGLE_CHROME_BUILD) |
| 2085 } | 2087 } |
| 2086 | 2088 |
| 2087 void BrowserOptionsHandler::HandleMetricsReportingChange( | 2089 void BrowserOptionsHandler::HandleMetricsReportingChange( |
| 2088 const base::ListValue* args) { | 2090 const base::ListValue* args) { |
| 2089 bool enable; | 2091 bool enable; |
| 2090 if (!args->GetBoolean(0, &enable)) | 2092 if (!args->GetBoolean(0, &enable)) |
| 2091 return; | 2093 return; |
| 2094 // Decline the change if current user shouldn't be able to change metrics |
| 2095 // reporting. |
| 2096 if (!IsDeviceOwnerProfile() || IsMetricsReportingPolicyManaged()) { |
| 2097 NotifyUIOfMetricsReportingChange( |
| 2098 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
| 2099 return; |
| 2100 } |
| 2092 | 2101 |
| 2102 // For Chrome OS updating device settings will notify an observer to update |
| 2103 // metrics pref, however we still need to call |InitiateMetricsReportingChange| |
| 2104 // with a proper callback so that UI gets updated in case of failure to update |
| 2105 // the metrics pref. |
| 2106 // TODO(gayane): Don't call |InitiateMetricsReportingChange| twice so that |
| 2107 // metrics service pref changes only as a result of device settings change for |
| 2108 // Chrome OS .crbug.com/552550. |
| 2109 #if defined(OS_CHROMEOS) |
| 2110 chromeos::CrosSettings::Get()->SetBoolean(chromeos::kStatsReportingPref, |
| 2111 enable); |
| 2112 #endif // defined(OS_CHROMEOS) |
| 2093 InitiateMetricsReportingChange( | 2113 InitiateMetricsReportingChange( |
| 2094 enable, | 2114 enable, |
| 2095 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback, | 2115 base::Bind(&BrowserOptionsHandler::NotifyUIOfMetricsReportingChange, |
| 2096 base::Unretained(this))); | 2116 base::Unretained(this))); |
| 2097 } | 2117 } |
| 2098 | 2118 |
| 2099 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) { | 2119 void BrowserOptionsHandler::NotifyUIOfMetricsReportingChange(bool enabled) { |
| 2100 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable()); | 2120 SetMetricsReportingCheckbox(enabled, IsMetricsReportingPolicyManaged(), |
| 2121 !IsDeviceOwnerProfile()); |
| 2101 } | 2122 } |
| 2102 | 2123 |
| 2103 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked, | 2124 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked, |
| 2104 bool disabled) { | 2125 bool policy_managed, |
| 2126 bool owner_managed) { |
| 2105 web_ui()->CallJavascriptFunction( | 2127 web_ui()->CallJavascriptFunction( |
| 2106 "BrowserOptions.setMetricsReportingCheckboxState", | 2128 "BrowserOptions.setMetricsReportingCheckboxState", |
| 2107 base::FundamentalValue(checked), | 2129 base::FundamentalValue(checked), base::FundamentalValue(policy_managed), |
| 2108 base::FundamentalValue(disabled)); | 2130 base::FundamentalValue(owner_managed)); |
| 2109 } | 2131 } |
| 2110 | 2132 |
| 2111 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, | 2133 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 2112 const policy::PolicyMap& previous, | 2134 const policy::PolicyMap& previous, |
| 2113 const policy::PolicyMap& current) { | 2135 const policy::PolicyMap& current) { |
| 2114 std::set<std::string> different_keys; | 2136 std::set<std::string> different_keys; |
| 2115 current.GetDifferingKeys(previous, &different_keys); | 2137 current.GetDifferingKeys(previous, &different_keys); |
| 2116 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) | 2138 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) |
| 2117 SetupMetricsReportingCheckbox(); | 2139 SetupMetricsReportingCheckbox(); |
| 2118 } | 2140 } |
| 2119 | 2141 |
| 2142 bool BrowserOptionsHandler::IsDeviceOwnerProfile() { |
| 2143 #if defined(OS_CHROMEOS) |
| 2144 return chromeos::ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui())); |
| 2145 #else |
| 2146 return true; |
| 2147 #endif |
| 2148 } |
| 2149 |
| 2120 } // namespace options | 2150 } // namespace options |
| OLD | NEW |