Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / webui / signin_internals_ui.cc
blob322f1ec38d7ff55941e1a2babd4daf9937dd98c6
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/signin_internals_ui.h"
7 #include "base/hash.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/about_signin_internals_factory.h"
10 #include "chrome/common/url_constants.h"
11 #include "components/signin/core/browser/about_signin_internals.h"
12 #include "content/public/browser/web_ui.h"
13 #include "content/public/browser/web_ui_data_source.h"
14 #include "grit/signin_internals_resources.h"
16 namespace {
18 content::WebUIDataSource* CreateSignInInternalsHTMLSource() {
19 content::WebUIDataSource* source =
20 content::WebUIDataSource::Create(chrome::kChromeUISignInInternalsHost);
22 source->SetJsonPath("strings.js");
23 source->AddResourcePath("signin_internals.js", IDR_SIGNIN_INTERNALS_INDEX_JS);
24 source->SetDefaultResource(IDR_SIGNIN_INTERNALS_INDEX_HTML);
25 return source;
28 } // namespace
30 SignInInternalsUI::SignInInternalsUI(content::WebUI* web_ui)
31 : WebUIController(web_ui) {
32 Profile* profile = Profile::FromWebUI(web_ui);
33 content::WebUIDataSource::Add(profile, CreateSignInInternalsHTMLSource());
34 if (profile) {
35 AboutSigninInternals* about_signin_internals =
36 AboutSigninInternalsFactory::GetForProfile(profile);
37 if (about_signin_internals)
38 about_signin_internals->AddSigninObserver(this);
42 SignInInternalsUI::~SignInInternalsUI() {
43 Profile* profile = Profile::FromWebUI(web_ui());
44 if (profile) {
45 AboutSigninInternals* about_signin_internals =
46 AboutSigninInternalsFactory::GetForProfile(profile);
47 if (about_signin_internals) {
48 about_signin_internals->RemoveSigninObserver(this);
53 bool SignInInternalsUI::OverrideHandleWebUIMessage(
54 const GURL& source_url,
55 const std::string& name,
56 const base::ListValue& content) {
57 if (name == "getSigninInfo") {
58 Profile* profile = Profile::FromWebUI(web_ui());
59 if (!profile)
60 return false;
62 AboutSigninInternals* about_signin_internals =
63 AboutSigninInternalsFactory::GetForProfile(profile);
64 // TODO(vishwath): The UI would look better if we passed in a dict with some
65 // reasonable defaults, so the about:signin-internals page doesn't look
66 // empty in incognito mode. Alternatively, we could force about:signin to
67 // open in non-incognito mode always (like about:settings for ex.).
68 if (about_signin_internals) {
69 web_ui()->CallJavascriptFunction(
70 "chrome.signin.getSigninInfo.handleReply",
71 *about_signin_internals->GetSigninStatus());
72 about_signin_internals->GetCookieAccountsAsync();
74 return true;
77 return false;
80 void SignInInternalsUI::OnSigninStateChanged(
81 const base::DictionaryValue* info) {
82 web_ui()->CallJavascriptFunction(
83 "chrome.signin.onSigninInfoChanged.fire", *info);
86 void SignInInternalsUI::OnCookieAccountsFetched(
87 const base::DictionaryValue* info) {
88 web_ui()->CallJavascriptFunction(
89 "chrome.signin.onCookieAccountsFetched.fire", *info);