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