OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_intern
als_ui.h" | 5 #include "chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_intern
als_ui.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/histogram_base.h" | 11 #include "base/metrics/histogram_base.h" |
12 #include "base/metrics/histogram_samples.h" | 12 #include "base/metrics/histogram_samples.h" |
| 13 #include "base/numerics/safe_conversions.h" |
13 #include "base/task_scheduler/task_scheduler.h" | 14 #include "base/task_scheduler/task_scheduler.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "chrome/grit/task_scheduler_internals_resources.h" | 18 #include "chrome/grit/task_scheduler_internals_resources.h" |
18 #include "content/public/browser/web_ui_data_source.h" | 19 #include "content/public/browser/web_ui_data_source.h" |
19 #include "content/public/browser/web_ui_message_handler.h" | 20 #include "content/public/browser/web_ui_message_handler.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 std::unique_ptr<base::Value> SnapshotHistogramToValue( | 24 std::unique_ptr<base::Value> SnapshotHistogramToValue( |
24 const base::HistogramBase* histogram) { | 25 const base::HistogramBase* histogram) { |
25 std::unique_ptr<base::ListValue> values = | 26 std::unique_ptr<base::ListValue> values = |
26 base::MakeUnique<base::ListValue>(); | 27 base::MakeUnique<base::ListValue>(); |
27 | 28 |
28 std::unique_ptr<base::HistogramSamples> samples = | 29 std::unique_ptr<base::HistogramSamples> samples = |
29 histogram->SnapshotSamples(); | 30 histogram->SnapshotSamples(); |
30 std::unique_ptr<base::SampleCountIterator> iterator = samples->Iterator(); | 31 std::unique_ptr<base::SampleCountIterator> iterator = samples->Iterator(); |
31 while (!iterator->Done()) { | 32 while (!iterator->Done()) { |
32 base::HistogramBase::Sample min; | 33 base::HistogramBase::Sample min; |
33 base::HistogramBase::Sample max; | 34 int64_t max; |
34 base::HistogramBase::Count count; | 35 base::HistogramBase::Count count; |
35 iterator->Get(&min, &max, &count); | 36 iterator->Get(&min, &max, &count); |
36 | 37 |
37 std::unique_ptr<base::DictionaryValue> bucket = | 38 std::unique_ptr<base::DictionaryValue> bucket = |
38 base::MakeUnique<base::DictionaryValue>(); | 39 base::MakeUnique<base::DictionaryValue>(); |
39 bucket->SetInteger("min", min); | 40 bucket->SetInteger("min", min); |
40 bucket->SetInteger("max", max); | 41 // Note: DictionaryValue does not support 64-bit integer values. The checked |
| 42 // cast below is OK in this case because none of the histograms passed to |
| 43 // this function should be logging MaxInt32 as a sparse histogram bucket, |
| 44 // which is the only case max will exceed 32-bit range. |
| 45 bucket->SetInteger("max", base::checked_cast<int>(max)); |
41 bucket->SetInteger("count", count); | 46 bucket->SetInteger("count", count); |
42 | 47 |
43 values->Append(std::move(bucket)); | 48 values->Append(std::move(bucket)); |
44 iterator->Next(); | 49 iterator->Next(); |
45 } | 50 } |
46 return std::move(values); | 51 return std::move(values); |
47 } | 52 } |
48 | 53 |
49 class TaskSchedulerDataHandler : public content::WebUIMessageHandler { | 54 class TaskSchedulerDataHandler : public content::WebUIMessageHandler { |
50 public: | 55 public: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 "index.css", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_CSS); | 108 "index.css", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_CSS); |
104 html_source->AddResourcePath( | 109 html_source->AddResourcePath( |
105 "index.js", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_JS); | 110 "index.js", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_JS); |
106 html_source->SetDefaultResource( | 111 html_source->SetDefaultResource( |
107 IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_HTML); | 112 IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_HTML); |
108 | 113 |
109 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 114 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
110 } | 115 } |
111 | 116 |
112 TaskSchedulerInternalsUI::~TaskSchedulerInternalsUI() = default; | 117 TaskSchedulerInternalsUI::~TaskSchedulerInternalsUI() = default; |
OLD | NEW |