Chromium Code Reviews| 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" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 std::unique_ptr<base::Value> SnapshotHistogramToValue( | 23 std::unique_ptr<base::Value> SnapshotHistogramToValue( |
| 24 const base::HistogramBase* histogram) { | 24 const base::HistogramBase* histogram) { |
| 25 std::unique_ptr<base::ListValue> values = | 25 std::unique_ptr<base::ListValue> values = |
| 26 base::MakeUnique<base::ListValue>(); | 26 base::MakeUnique<base::ListValue>(); |
| 27 | 27 |
| 28 std::unique_ptr<base::HistogramSamples> samples = | 28 std::unique_ptr<base::HistogramSamples> samples = |
| 29 histogram->SnapshotSamples(); | 29 histogram->SnapshotSamples(); |
| 30 std::unique_ptr<base::SampleCountIterator> iterator = samples->Iterator(); | 30 std::unique_ptr<base::SampleCountIterator> iterator = samples->Iterator(); |
| 31 while (!iterator->Done()) { | 31 while (!iterator->Done()) { |
| 32 base::HistogramBase::Sample min; | 32 base::HistogramBase::Sample min; |
| 33 base::HistogramBase::Sample max; | 33 int64_t max; |
| 34 base::HistogramBase::Count count; | 34 base::HistogramBase::Count count; |
| 35 iterator->Get(&min, &max, &count); | 35 iterator->Get(&min, &max, &count); |
| 36 | 36 |
| 37 std::unique_ptr<base::DictionaryValue> bucket = | 37 std::unique_ptr<base::DictionaryValue> bucket = |
| 38 base::MakeUnique<base::DictionaryValue>(); | 38 base::MakeUnique<base::DictionaryValue>(); |
| 39 bucket->SetInteger("min", min); | 39 bucket->SetInteger("min", min); |
| 40 bucket->SetInteger("max", max); | 40 // Note: DictionaryValue does not support 64-bit integer values. The static |
| 41 // cast below is OK in this case because none of the histograms passed to | |
| 42 // this function should be logging MaxInt32 as a sparse histogram bucket, | |
| 43 // which is the only case max will exceed 32-bit range. | |
| 44 bucket->SetInteger("max", static_cast<int>(max)); | |
|
Ilya Sherman
2017/05/02 21:37:49
nit: Could this be a checked_cast?
Alexei Svitkine (slow)
2017/05/03 15:21:53
Done.
| |
| 41 bucket->SetInteger("count", count); | 45 bucket->SetInteger("count", count); |
| 42 | 46 |
| 43 values->Append(std::move(bucket)); | 47 values->Append(std::move(bucket)); |
| 44 iterator->Next(); | 48 iterator->Next(); |
| 45 } | 49 } |
| 46 return std::move(values); | 50 return std::move(values); |
| 47 } | 51 } |
| 48 | 52 |
| 49 class TaskSchedulerDataHandler : public content::WebUIMessageHandler { | 53 class TaskSchedulerDataHandler : public content::WebUIMessageHandler { |
| 50 public: | 54 public: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 "index.css", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_CSS); | 107 "index.css", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_CSS); |
| 104 html_source->AddResourcePath( | 108 html_source->AddResourcePath( |
| 105 "index.js", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_JS); | 109 "index.js", IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_JS); |
| 106 html_source->SetDefaultResource( | 110 html_source->SetDefaultResource( |
| 107 IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_HTML); | 111 IDR_TASK_SCHEDULER_INTERNALS_RESOURCES_INDEX_HTML); |
| 108 | 112 |
| 109 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 113 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 110 } | 114 } |
| 111 | 115 |
| 112 TaskSchedulerInternalsUI::~TaskSchedulerInternalsUI() = default; | 116 TaskSchedulerInternalsUI::~TaskSchedulerInternalsUI() = default; |
| OLD | NEW |