| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/chrome_render_thread_observer.h" | 5 #include "chrome/renderer/chrome_render_thread_observer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 163 } |
| 164 | 164 |
| 165 void SendResults() { | 165 void SendResults() { |
| 166 if (!callback_.is_null()) | 166 if (!callback_.is_null()) |
| 167 callback_.Run(std::move(usage_data_)); | 167 callback_.Run(std::move(usage_data_)); |
| 168 callback_.Reset(); | 168 callback_.Reset(); |
| 169 weak_factory_.InvalidateWeakPtrs(); | 169 weak_factory_.InvalidateWeakPtrs(); |
| 170 workers_to_go_ = 0; | 170 workers_to_go_ = 0; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void GetUsageData(const GetUsageDataCallback& callback) override { | 173 void GetUsageData(const mojo::Callback<void(mojom::ResourceUsageDataPtr)>& |
| 174 callback) override { |
| 174 DCHECK(callback_.is_null()); | 175 DCHECK(callback_.is_null()); |
| 175 weak_factory_.InvalidateWeakPtrs(); | 176 weak_factory_.InvalidateWeakPtrs(); |
| 176 usage_data_ = mojom::ResourceUsageData::New(); | 177 usage_data_ = mojom::ResourceUsageData::New(); |
| 177 usage_data_->reports_v8_stats = true; | 178 usage_data_->reports_v8_stats = true; |
| 178 callback_ = callback; | 179 callback_ = callback; |
| 179 | 180 |
| 180 // Since it is not safe to call any Blink or V8 functions until Blink has | 181 // Since it is not safe to call any Blink or V8 functions until Blink has |
| 181 // been initialized (which also initializes V8), early out and send 0 back | 182 // been initialized (which also initializes V8), early out and send 0 back |
| 182 // for all resources. | 183 // for all resources. |
| 183 if (!observer_) { | 184 if (!observer_) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 207 FROM_HERE, base::Bind(&ResourceUsageReporterImpl::SendResults, | 208 FROM_HERE, base::Bind(&ResourceUsageReporterImpl::SendResults, |
| 208 weak_factory_.GetWeakPtr()), | 209 weak_factory_.GetWeakPtr()), |
| 209 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS)); | 210 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS)); |
| 210 } else { | 211 } else { |
| 211 // No worker threads so just send out the main thread data right away. | 212 // No worker threads so just send out the main thread data right away. |
| 212 SendResults(); | 213 SendResults(); |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 mojom::ResourceUsageDataPtr usage_data_; | 217 mojom::ResourceUsageDataPtr usage_data_; |
| 217 GetUsageDataCallback callback_; | 218 mojo::Callback<void(mojom::ResourceUsageDataPtr)> callback_; |
| 218 int workers_to_go_; | 219 int workers_to_go_; |
| 219 mojo::StrongBinding<mojom::ResourceUsageReporter> binding_; | 220 mojo::StrongBinding<mojom::ResourceUsageReporter> binding_; |
| 220 base::WeakPtr<ChromeRenderThreadObserver> observer_; | 221 base::WeakPtr<ChromeRenderThreadObserver> observer_; |
| 221 | 222 |
| 222 base::WeakPtrFactory<ResourceUsageReporterImpl> weak_factory_; | 223 base::WeakPtrFactory<ResourceUsageReporterImpl> weak_factory_; |
| 223 | 224 |
| 224 DISALLOW_COPY_AND_ASSIGN(ResourceUsageReporterImpl); | 225 DISALLOW_COPY_AND_ASSIGN(ResourceUsageReporterImpl); |
| 225 }; | 226 }; |
| 226 | 227 |
| 227 void CreateResourceUsageReporter( | 228 void CreateResourceUsageReporter( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 void ChromeRenderThreadObserver::OnSetFieldTrialGroup( | 304 void ChromeRenderThreadObserver::OnSetFieldTrialGroup( |
| 304 const std::string& trial_name, | 305 const std::string& trial_name, |
| 305 const std::string& group_name) { | 306 const std::string& group_name) { |
| 306 field_trial_syncer_.OnSetFieldTrialGroup(trial_name, group_name); | 307 field_trial_syncer_.OnSetFieldTrialGroup(trial_name, group_name); |
| 307 } | 308 } |
| 308 | 309 |
| 309 const RendererContentSettingRules* | 310 const RendererContentSettingRules* |
| 310 ChromeRenderThreadObserver::content_setting_rules() const { | 311 ChromeRenderThreadObserver::content_setting_rules() const { |
| 311 return &content_setting_rules_; | 312 return &content_setting_rules_; |
| 312 } | 313 } |
| OLD | NEW |