Implemented consumer management unenrollment.
[chromium-blink-merge.git] / chrome / browser / ui / webui / domain_reliability_internals_ui.cc
blob28f91643df4476e1e2c973f5adce9b48aee4ebcc
1 // Copyright 2014 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/domain_reliability_internals_ui.h"
7 #include "chrome/browser/domain_reliability/service_factory.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/url_constants.h"
10 #include "components/domain_reliability/service.h"
11 #include "content/public/browser/web_ui.h"
12 #include "content/public/browser/web_ui_data_source.h"
13 #include "grit/browser_resources.h"
15 using domain_reliability::DomainReliabilityService;
16 using domain_reliability::DomainReliabilityServiceFactory;
18 DomainReliabilityInternalsUI::DomainReliabilityInternalsUI(
19 content::WebUI* web_ui)
20 : content::WebUIController(web_ui) {
21 content::WebUIDataSource* html_source = content::WebUIDataSource::Create(
22 chrome::kChromeUIDomainReliabilityInternalsHost);
23 html_source->SetJsonPath("strings.js");
24 html_source->AddResourcePath("domain_reliability_internals.css",
25 IDR_DOMAIN_RELIABILITY_INTERNALS_CSS);
26 html_source->AddResourcePath("domain_reliability_internals.js",
27 IDR_DOMAIN_RELIABILITY_INTERNALS_JS);
28 html_source->SetDefaultResource(IDR_DOMAIN_RELIABILITY_INTERNALS_HTML);
30 web_ui->RegisterMessageCallback("updateData",
31 base::Bind(&DomainReliabilityInternalsUI::UpdateData,
32 base::Unretained(this)));
34 Profile* profile = Profile::FromWebUI(web_ui);
35 content::WebUIDataSource::Add(profile, html_source);
38 DomainReliabilityInternalsUI::~DomainReliabilityInternalsUI() {}
40 void DomainReliabilityInternalsUI::UpdateData(
41 const base::ListValue* args) const {
42 Profile* profile = Profile::FromWebUI(web_ui());
43 DomainReliabilityServiceFactory* factory =
44 DomainReliabilityServiceFactory::GetInstance();
45 DCHECK(profile);
46 DCHECK(factory);
48 DomainReliabilityService* service = factory->GetForBrowserContext(profile);
49 if (!service) {
50 base::DictionaryValue* data = new base::DictionaryValue();
51 data->SetString("error", "no_service");
52 OnDataUpdated(scoped_ptr<base::Value>(data));
53 return;
56 service->GetWebUIData(base::Bind(
57 &DomainReliabilityInternalsUI::OnDataUpdated,
58 base::Unretained(this)));
61 void DomainReliabilityInternalsUI::OnDataUpdated(
62 scoped_ptr<base::Value> data) const {
63 web_ui()->CallJavascriptFunction(
64 "DomainReliabilityInternals.onDataUpdated", *data);