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

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

Issue 1411863002: Use kMetricsReportingEnabled instead of kStatsReporingPref on metrics side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits comments TODOs Created 5 years, 1 month 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
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 <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
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 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 extension = extensions::GetExtensionOverridingProxy( 2138 extension = extensions::GetExtensionOverridingProxy(
2141 Profile::FromWebUI(web_ui())); 2139 Profile::FromWebUI(web_ui()));
2142 AppendExtensionData("proxy", extension, &extension_controlled); 2140 AppendExtensionData("proxy", extension, &extension_controlled);
2143 2141
2144 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators", 2142 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
2145 extension_controlled); 2143 extension_controlled);
2146 #endif // defined(OS_WIN) 2144 #endif // defined(OS_WIN)
2147 } 2145 }
2148 2146
2149 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() { 2147 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
2150 // This function does not work for ChromeOS and non-official builds. 2148 // As the metrics and crash reporting checkbox only exists for official builds
2151 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) 2149 // it doesn't need to be set up for non-official builds.
2150 #if defined(GOOGLE_CHROME_BUILD)
2152 bool checked = 2151 bool checked =
2153 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); 2152 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
2154 bool disabled = !IsMetricsReportingUserChangable(); 2153 bool policy_managed = IsMetricsReportingPolicyManaged();
2155 2154 bool owner_managed = false;
2156 SetMetricsReportingCheckbox(checked, disabled); 2155 #if defined(OS_CHROMEOS)
2157 #endif 2156 owner_managed = !IsDeviceOwnerProfile();
2157 #endif // defined(OS_CHROMEOS)
2158 SetMetricsReportingCheckbox(checked, policy_managed, owner_managed);
2159 #endif // defined(GOOGLE_CHROME_BUILD)
2158 } 2160 }
2159 2161
2160 void BrowserOptionsHandler::HandleMetricsReportingChange( 2162 void BrowserOptionsHandler::HandleMetricsReportingChange(
2161 const base::ListValue* args) { 2163 const base::ListValue* args) {
2162 bool enable; 2164 bool enable;
2163 if (!args->GetBoolean(0, &enable)) 2165 if (!args->GetBoolean(0, &enable))
2164 return; 2166 return;
2167 // Decline the change if current user shouldn't be able to change metrics
2168 // reporting.
2169 if (!IsDeviceOwnerProfile() || IsMetricsReportingPolicyManaged()) {
2170 NotifyUIOfMetricsReportingChange(
2171 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
2172 return;
2173 }
2165 2174
2175 // For Chrome OS updating device settings will notify an observer to update
2176 // metrics pref, however we still need to call |InitiateMetricsReportingChange|
2177 // with a proper callback so that UI gets updated in case of failure to update
2178 // the metrics pref.
2179 // TODO(gayane): Don't call |InitiateMetricsReportingChange| twice for Chrome
2180 // OS.
Mattias Nissler (ping if slow) 2015/11/06 13:05:09 Sorry, but this is not just a cosmetic issue about
gayane -on leave until 09-2017 2015/11/06 21:41:13 Done.
2181 #if defined(OS_CHROMEOS)
2182 chromeos::CrosSettings::Get()->SetBoolean(chromeos::kStatsReportingPref,
2183 enable);
2184 #endif // defined(OS_CHROMEOS)
2166 InitiateMetricsReportingChange( 2185 InitiateMetricsReportingChange(
2167 enable, 2186 enable,
2168 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback, 2187 base::Bind(&BrowserOptionsHandler::NotifyUIOfMetricsReportingChange,
2169 base::Unretained(this))); 2188 base::Unretained(this)));
2170 } 2189 }
2171 2190
2172 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) { 2191 void BrowserOptionsHandler::NotifyUIOfMetricsReportingChange(bool enabled) {
2173 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable()); 2192 SetMetricsReportingCheckbox(enabled, IsMetricsReportingPolicyManaged(),
2193 !IsDeviceOwnerProfile());
2174 } 2194 }
2175 2195
2176 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked, 2196 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
2177 bool disabled) { 2197 bool policy_managed,
2198 bool owner_managed) {
2178 web_ui()->CallJavascriptFunction( 2199 web_ui()->CallJavascriptFunction(
2179 "BrowserOptions.setMetricsReportingCheckboxState", 2200 "BrowserOptions.setMetricsReportingCheckboxState",
2180 base::FundamentalValue(checked), 2201 base::FundamentalValue(checked), base::FundamentalValue(policy_managed),
2181 base::FundamentalValue(disabled)); 2202 base::FundamentalValue(owner_managed));
2182 } 2203 }
2183 2204
2184 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, 2205 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
2185 const policy::PolicyMap& previous, 2206 const policy::PolicyMap& previous,
2186 const policy::PolicyMap& current) { 2207 const policy::PolicyMap& current) {
2187 std::set<std::string> different_keys; 2208 std::set<std::string> different_keys;
2188 current.GetDifferingKeys(previous, &different_keys); 2209 current.GetDifferingKeys(previous, &different_keys);
2189 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) 2210 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled))
2190 SetupMetricsReportingCheckbox(); 2211 SetupMetricsReportingCheckbox();
2191 } 2212 }
2192 2213
2214 bool BrowserOptionsHandler::IsDeviceOwnerProfile() {
2215 #if defined(OS_CHROMEOS)
2216 return chromeos::ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui()));
2217 #else
2218 return true;
2219 #endif
2220 }
2221
2193 } // namespace options 2222 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698