OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 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. | |
4 | |
5 #include "components/ukm/debug_page/debug_page.h" | |
6 | |
7 #include "base/memory/ref_counted_memory.h" | |
8 #include "base/strings/stringprintf.h" | |
9 #include "components/ukm/ukm_entry.h" | |
10 #include "components/ukm/ukm_service.h" | |
11 #include "components/ukm/ukm_source.h" | |
12 #include "url/gurl.h" | |
13 | |
14 namespace ukm { | |
15 namespace debug { | |
16 | |
17 DebugPage::DebugPage(ServiceGetter service_getter) | |
18 : service_getter_(service_getter) {} | |
19 | |
20 DebugPage::~DebugPage() {} | |
21 | |
22 std::string DebugPage::GetSource() const { | |
23 DLOG(ERROR) << "DebugPage::GetSource"; | |
24 return "ukm"; | |
25 } | |
26 | |
27 std::string DebugPage::GetMimeType(const std::string& path) const { | |
28 return "text/html"; | |
29 } | |
30 | |
31 void DebugPage::StartDataRequest( | |
Alexei Svitkine (slow)
2017/05/05 16:45:04
Could you add a reviewer who's familiar with this
Steven Holte
2017/05/05 18:16:43
Sure.
| |
32 const std::string& path, | |
33 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | |
34 const content::URLDataSource::GotDataCallback& callback) { | |
35 std::string data; | |
36 data.append(R"""(<!DOCTYPE html> | |
37 <html> | |
38 <head> | |
39 <meta http-equiv="Content-Security-Policy" | |
40 content="object-src 'none'; script-src 'none'"> | |
41 <title>UKM Debug</title> | |
42 </head> | |
43 <body> | |
44 <h1>UKM Debug page</h1> | |
45 )"""); | |
46 UkmService* ukm_service = service_getter_.Run(); | |
47 if (ukm_service) { | |
48 data.append( | |
49 base::StringPrintf("<p>IsEnabled:%s</p>", | |
50 ukm_service->recording_enabled_ ? "True" : "False")); | |
51 data.append( | |
52 base::StringPrintf("<p>ClientId:%lu</p>", ukm_service->client_id_)); | |
53 data.append( | |
54 base::StringPrintf("<p>SessionId:%d</p>", ukm_service->session_id_)); | |
55 | |
56 data.append("<h2>Sources</h2>"); | |
57 for (const auto& kv : ukm_service->sources_) { | |
58 const auto* src = kv.second.get(); | |
59 data.append(base::StringPrintf("<p>Id:%d Url:%s</p>", src->id(), | |
60 src->url().spec().c_str())); | |
61 } | |
62 | |
63 data.append("<h2>Entries</h2>"); | |
64 for (const auto& v : ukm_service->entries_) { | |
65 const auto* entry = v.get(); | |
66 data.append(base::StringPrintf("<h3>Id:%d Hash:%lu</h3>", | |
67 entry->source_id(), entry->event_hash())); | |
68 } | |
69 } | |
70 | |
71 data.append(R"""( | |
72 </body> | |
73 </html> | |
74 )"""); | |
75 | |
76 callback.Run(base::RefCountedString::TakeString(&data)); | |
77 } | |
78 | |
79 bool DebugPage::AllowCaching() const { | |
80 return false; | |
81 } | |
82 | |
83 } // namespace debug | |
84 } // namespace ukm | |
OLD | NEW |