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

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: fix callback 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 #if defined(OS_CHROMEOS)
2176 chromeos::CrosSettings::Get()->SetBoolean(chromeos::kStatsReportingPref,
2177 enable);
2178 #endif // defined(OS_CHROMEOS)
2166 InitiateMetricsReportingChange( 2179 InitiateMetricsReportingChange(
Alexei Svitkine (slow) 2015/11/03 23:18:23 So now, how this works is that this will be called
gayane -on leave until 09-2017 2015/11/05 18:53:32 You are right InitiateMetricsReportingChange will
2167 enable, 2180 enable,
2168 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback, 2181 base::Bind(&BrowserOptionsHandler::NotifyUIOfMetricsReportingChange,
2169 base::Unretained(this))); 2182 base::Unretained(this)));
2170 } 2183 }
2171 2184
2172 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) { 2185 void BrowserOptionsHandler::NotifyUIOfMetricsReportingChange(bool enabled) {
2173 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable()); 2186 SetMetricsReportingCheckbox(enabled, IsMetricsReportingPolicyManaged(),
2187 !IsDeviceOwnerProfile());
2174 } 2188 }
2175 2189
2176 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked, 2190 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
2177 bool disabled) { 2191 bool policy_managed,
2192 bool owner_managed) {
2178 web_ui()->CallJavascriptFunction( 2193 web_ui()->CallJavascriptFunction(
2179 "BrowserOptions.setMetricsReportingCheckboxState", 2194 "BrowserOptions.setMetricsReportingCheckboxState",
2180 base::FundamentalValue(checked), 2195 base::FundamentalValue(checked), base::FundamentalValue(policy_managed),
2181 base::FundamentalValue(disabled)); 2196 base::FundamentalValue(owner_managed));
2182 } 2197 }
2183 2198
2184 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, 2199 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
2185 const policy::PolicyMap& previous, 2200 const policy::PolicyMap& previous,
2186 const policy::PolicyMap& current) { 2201 const policy::PolicyMap& current) {
2187 std::set<std::string> different_keys; 2202 std::set<std::string> different_keys;
2188 current.GetDifferingKeys(previous, &different_keys); 2203 current.GetDifferingKeys(previous, &different_keys);
2189 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) 2204 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled))
2190 SetupMetricsReportingCheckbox(); 2205 SetupMetricsReportingCheckbox();
2191 } 2206 }
2192 2207
2208 bool BrowserOptionsHandler::IsDeviceOwnerProfile() {
2209 #if defined(OS_CHROMEOS)
2210 return chromeos::ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui()));
2211 #else
2212 return true;
2213 #endif
2214 }
2215
2193 } // namespace options 2216 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698