| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/process_resource_usage.h" | 5 #include "chrome/browser/process_resource_usage.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "chrome/common/resource_usage_reporter_type_converters.h" | 14 #include "chrome/common/resource_usage_reporter_type_converters.h" |
| 15 | 15 |
| 16 ProcessResourceUsage::ProcessResourceUsage( | 16 ProcessResourceUsage::ProcessResourceUsage( |
| 17 mojom::ResourceUsageReporterPtr service) | 17 chrome::mojom::ResourceUsageReporterPtr service) |
| 18 : service_(std::move(service)), update_in_progress_(false) { | 18 : service_(std::move(service)), update_in_progress_(false) { |
| 19 service_.set_connection_error_handler( | 19 service_.set_connection_error_handler( |
| 20 base::Bind(&ProcessResourceUsage::RunPendingRefreshCallbacks, | 20 base::Bind(&ProcessResourceUsage::RunPendingRefreshCallbacks, |
| 21 base::Unretained(this))); | 21 base::Unretained(this))); |
| 22 } | 22 } |
| 23 | 23 |
| 24 ProcessResourceUsage::~ProcessResourceUsage() { | 24 ProcessResourceUsage::~ProcessResourceUsage() { |
| 25 DCHECK(thread_checker_.CalledOnValidThread()); | 25 DCHECK(thread_checker_.CalledOnValidThread()); |
| 26 } | 26 } |
| 27 | 27 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 44 if (!callback.is_null()) | 44 if (!callback.is_null()) |
| 45 refresh_callbacks_.push_back(callback); | 45 refresh_callbacks_.push_back(callback); |
| 46 | 46 |
| 47 if (!update_in_progress_) { | 47 if (!update_in_progress_) { |
| 48 update_in_progress_ = true; | 48 update_in_progress_ = true; |
| 49 service_->GetUsageData(base::Bind(&ProcessResourceUsage::OnRefreshDone, | 49 service_->GetUsageData(base::Bind(&ProcessResourceUsage::OnRefreshDone, |
| 50 base::Unretained(this))); | 50 base::Unretained(this))); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ProcessResourceUsage::OnRefreshDone(mojom::ResourceUsageDataPtr data) { | 54 void ProcessResourceUsage::OnRefreshDone( |
| 55 chrome::mojom::ResourceUsageDataPtr data) { |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 update_in_progress_ = false; | 57 update_in_progress_ = false; |
| 57 stats_ = std::move(data); | 58 stats_ = std::move(data); |
| 58 RunPendingRefreshCallbacks(); | 59 RunPendingRefreshCallbacks(); |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool ProcessResourceUsage::ReportsV8MemoryStats() const { | 62 bool ProcessResourceUsage::ReportsV8MemoryStats() const { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 if (stats_) | 64 if (stats_) |
| 64 return stats_->reports_v8_stats; | 65 return stats_->reports_v8_stats; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 return 0; | 80 return 0; |
| 80 } | 81 } |
| 81 | 82 |
| 82 blink::WebCache::ResourceTypeStats ProcessResourceUsage::GetWebCoreCacheStats() | 83 blink::WebCache::ResourceTypeStats ProcessResourceUsage::GetWebCoreCacheStats() |
| 83 const { | 84 const { |
| 84 DCHECK(thread_checker_.CalledOnValidThread()); | 85 DCHECK(thread_checker_.CalledOnValidThread()); |
| 85 if (stats_ && stats_->web_cache_stats) | 86 if (stats_ && stats_->web_cache_stats) |
| 86 return stats_->web_cache_stats->To<blink::WebCache::ResourceTypeStats>(); | 87 return stats_->web_cache_stats->To<blink::WebCache::ResourceTypeStats>(); |
| 87 return {}; | 88 return {}; |
| 88 } | 89 } |
| OLD | NEW |