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