ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / device_log_ui.cc
blobcfd47e37d5e295d6d9a657b54142b1ae4a4fe01f
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/chromeos/device_log_ui.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/values.h"
12 #include "chrome/common/url_constants.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "chromeos/device_event_log.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_data_source.h"
18 #include "content/public/browser/web_ui_message_handler.h"
19 #include "grit/browser_resources.h"
21 namespace chromeos {
23 namespace {
25 class DeviceLogMessageHandler : public content::WebUIMessageHandler {
26 public:
27 DeviceLogMessageHandler() {}
28 ~DeviceLogMessageHandler() override {}
30 // WebUIMessageHandler implementation.
31 void RegisterMessages() override {
32 web_ui()->RegisterMessageCallback(
33 "DeviceLog.getLog",
34 base::Bind(&DeviceLogMessageHandler::GetLog,
35 base::Unretained(this)));
38 private:
39 void GetLog(const base::ListValue* value) const {
40 base::StringValue data(chromeos::device_event_log::GetAsString(
41 chromeos::device_event_log::NEWEST_FIRST, "json", "",
42 chromeos::device_event_log::LOG_LEVEL_DEBUG, 0));
43 web_ui()->CallJavascriptFunction("DeviceLogUI.getLogCallback", data);
46 DISALLOW_COPY_AND_ASSIGN(DeviceLogMessageHandler);
49 } // namespace
51 DeviceLogUI::DeviceLogUI(content::WebUI* web_ui)
52 : content::WebUIController(web_ui) {
53 web_ui->AddMessageHandler(new DeviceLogMessageHandler());
55 content::WebUIDataSource* html =
56 content::WebUIDataSource::Create(chrome::kChromeUIDeviceLogHost);
58 html->AddLocalizedString("titleText", IDS_DEVICE_LOG_TITLE);
59 html->AddLocalizedString("autoRefreshText", IDS_DEVICE_AUTO_REFRESH);
60 html->AddLocalizedString("logRefreshText", IDS_DEVICE_LOG_REFRESH);
62 html->AddLocalizedString("logLevelShowText", IDS_DEVICE_LOG_LEVEL_SHOW);
63 html->AddLocalizedString("logLevelErrorText", IDS_DEVICE_LOG_LEVEL_ERROR);
64 html->AddLocalizedString("logLevelUserText", IDS_DEVICE_LOG_LEVEL_USER);
65 html->AddLocalizedString("logLevelEventText", IDS_DEVICE_LOG_LEVEL_EVENT);
66 html->AddLocalizedString("logLevelDebugText", IDS_DEVICE_LOG_LEVEL_DEBUG);
67 html->AddLocalizedString("logLevelFileinfoText", IDS_DEVICE_LOG_FILEINFO);
68 html->AddLocalizedString("logLevelTimeDetailText",
69 IDS_DEVICE_LOG_TIME_DETAIL);
71 html->AddLocalizedString("logTypeLoginText", IDS_DEVICE_LOG_TYPE_LOGIN);
72 html->AddLocalizedString("logTypeNetworkText", IDS_DEVICE_LOG_TYPE_NETWORK);
73 html->AddLocalizedString("logTypePowerText", IDS_DEVICE_LOG_TYPE_POWER);
75 html->AddLocalizedString("logEntryFormat", IDS_DEVICE_LOG_ENTRY);
76 html->SetJsonPath("strings.js");
77 html->AddResourcePath("device_log_ui.css", IDR_DEVICE_LOG_UI_CSS);
78 html->AddResourcePath("device_log_ui.js", IDR_DEVICE_LOG_UI_JS);
79 html->SetDefaultResource(IDR_DEVICE_LOG_UI_HTML);
81 content::WebUIDataSource::Add(
82 web_ui->GetWebContents()->GetBrowserContext(), html);
85 DeviceLogUI::~DeviceLogUI() {
88 } // namespace chromeos