Set an initial checked value of cookie controls toggle from setting

This to a great extent prevents the knob animation on every opening of
an incognito ntp.

Bug: 967668
Change-Id: Ib99ba020b419d8c9aed2c910049d2662a3850d4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1855962
Commit-Queue: Huanzhong Huang <[email protected]>
Reviewed-by: Dan Beam <[email protected]>
Reviewed-by: Christian Dullweber <[email protected]>
Cr-Commit-Position: refs/heads/master@{#706340}
diff --git a/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc b/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc
index f0442439..d280354 100644
--- a/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc
+++ b/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc
@@ -73,12 +73,13 @@
 
 void CookieControlsHandler::OnCookieControlsChanged() {
   Profile* profile = Profile::FromWebUI(web_ui());
+  FireWebUIListener("cookie-controls-changed",
+                    base::Value(GetToggleCheckedValue(profile)));
+}
+
+bool CookieControlsHandler::GetToggleCheckedValue(const Profile* profile) {
   int mode = profile->GetPrefs()->GetInteger(prefs::kCookieControlsMode);
-  base::Value checked(
-      mode == static_cast<int>(content_settings::CookieControlsMode::kOff)
-          ? false
-          : true);
-  FireWebUIListener("cookie-controls-changed", checked);
+  return mode != static_cast<int>(content_settings::CookieControlsMode::kOff);
 }
 
 void CookieControlsHandler::OnThirdPartyCookieBlockingChanged() {