Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/renderer/chrome_render_thread_observer.cc

Issue 2476493002: Add chrome namespace to chrome/common/resource_usage_reporter.mojom (Closed)
Patch Set: Add chrome namespace to chrome/common/resource_usage_reporter.mojom Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 static_cast<uint64_t>(stats.deadSize))); 120 static_cast<uint64_t>(stats.deadSize)));
121 } 121 }
122 122
123 base::WeakPtrFactory<RendererResourceDelegate> weak_factory_; 123 base::WeakPtrFactory<RendererResourceDelegate> weak_factory_;
124 124
125 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate); 125 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate);
126 }; 126 };
127 127
128 static const int kWaitForWorkersStatsTimeoutMS = 20; 128 static const int kWaitForWorkersStatsTimeoutMS = 20;
129 129
130 class ResourceUsageReporterImpl : public mojom::ResourceUsageReporter { 130 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter {
131 public: 131 public:
132 explicit ResourceUsageReporterImpl( 132 explicit ResourceUsageReporterImpl(
133 base::WeakPtr<ChromeRenderThreadObserver> observer) 133 base::WeakPtr<ChromeRenderThreadObserver> observer)
134 : workers_to_go_(0), observer_(observer), weak_factory_(this) {} 134 : workers_to_go_(0), observer_(observer), weak_factory_(this) {}
135 ~ResourceUsageReporterImpl() override {} 135 ~ResourceUsageReporterImpl() override {}
136 136
137 private: 137 private:
138 static void CollectOnWorkerThread( 138 static void CollectOnWorkerThread(
139 const scoped_refptr<base::TaskRunner>& master, 139 const scoped_refptr<base::TaskRunner>& master,
140 base::WeakPtr<ResourceUsageReporterImpl> impl) { 140 base::WeakPtr<ResourceUsageReporterImpl> impl) {
(...skipping 23 matching lines...) Expand all
164 if (!callback_.is_null()) 164 if (!callback_.is_null())
165 callback_.Run(std::move(usage_data_)); 165 callback_.Run(std::move(usage_data_));
166 callback_.Reset(); 166 callback_.Reset();
167 weak_factory_.InvalidateWeakPtrs(); 167 weak_factory_.InvalidateWeakPtrs();
168 workers_to_go_ = 0; 168 workers_to_go_ = 0;
169 } 169 }
170 170
171 void GetUsageData(const GetUsageDataCallback& callback) override { 171 void GetUsageData(const GetUsageDataCallback& callback) override {
172 DCHECK(callback_.is_null()); 172 DCHECK(callback_.is_null());
173 weak_factory_.InvalidateWeakPtrs(); 173 weak_factory_.InvalidateWeakPtrs();
174 usage_data_ = mojom::ResourceUsageData::New(); 174 usage_data_ = chrome::mojom::ResourceUsageData::New();
175 usage_data_->reports_v8_stats = true; 175 usage_data_->reports_v8_stats = true;
176 callback_ = callback; 176 callback_ = callback;
177 177
178 // Since it is not safe to call any Blink or V8 functions until Blink has 178 // Since it is not safe to call any Blink or V8 functions until Blink has
179 // been initialized (which also initializes V8), early out and send 0 back 179 // been initialized (which also initializes V8), early out and send 0 back
180 // for all resources. 180 // for all resources.
181 if (!observer_) { 181 if (!observer_) {
182 SendResults(); 182 SendResults();
183 return; 183 return;
184 } 184 }
185 185
186 WebCache::ResourceTypeStats stats; 186 WebCache::ResourceTypeStats stats;
187 WebCache::getResourceTypeStats(&stats); 187 WebCache::getResourceTypeStats(&stats);
188 usage_data_->web_cache_stats = mojom::ResourceTypeStats::From(stats); 188 usage_data_->web_cache_stats =
189 chrome::mojom::ResourceTypeStats::From(stats);
189 190
190 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 191 v8::Isolate* isolate = v8::Isolate::GetCurrent();
191 if (isolate) { 192 if (isolate) {
192 v8::HeapStatistics heap_stats; 193 v8::HeapStatistics heap_stats;
193 isolate->GetHeapStatistics(&heap_stats); 194 isolate->GetHeapStatistics(&heap_stats);
194 usage_data_->v8_bytes_allocated = heap_stats.total_heap_size(); 195 usage_data_->v8_bytes_allocated = heap_stats.total_heap_size();
195 usage_data_->v8_bytes_used = heap_stats.used_heap_size(); 196 usage_data_->v8_bytes_used = heap_stats.used_heap_size();
196 } 197 }
197 base::Closure collect = base::Bind( 198 base::Closure collect = base::Bind(
198 &ResourceUsageReporterImpl::CollectOnWorkerThread, 199 &ResourceUsageReporterImpl::CollectOnWorkerThread,
199 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); 200 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr());
200 workers_to_go_ = RenderThread::Get()->PostTaskToAllWebWorkers(collect); 201 workers_to_go_ = RenderThread::Get()->PostTaskToAllWebWorkers(collect);
201 if (workers_to_go_) { 202 if (workers_to_go_) {
202 // The guard task to send out partial stats 203 // The guard task to send out partial stats
203 // in case some workers are not responsive. 204 // in case some workers are not responsive.
204 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 205 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
205 FROM_HERE, base::Bind(&ResourceUsageReporterImpl::SendResults, 206 FROM_HERE, base::Bind(&ResourceUsageReporterImpl::SendResults,
206 weak_factory_.GetWeakPtr()), 207 weak_factory_.GetWeakPtr()),
207 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS)); 208 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS));
208 } else { 209 } else {
209 // No worker threads so just send out the main thread data right away. 210 // No worker threads so just send out the main thread data right away.
210 SendResults(); 211 SendResults();
211 } 212 }
212 } 213 }
213 214
214 mojom::ResourceUsageDataPtr usage_data_; 215 chrome::mojom::ResourceUsageDataPtr usage_data_;
215 GetUsageDataCallback callback_; 216 GetUsageDataCallback callback_;
216 int workers_to_go_; 217 int workers_to_go_;
217 base::WeakPtr<ChromeRenderThreadObserver> observer_; 218 base::WeakPtr<ChromeRenderThreadObserver> observer_;
218 219
219 base::WeakPtrFactory<ResourceUsageReporterImpl> weak_factory_; 220 base::WeakPtrFactory<ResourceUsageReporterImpl> weak_factory_;
220 221
221 DISALLOW_COPY_AND_ASSIGN(ResourceUsageReporterImpl); 222 DISALLOW_COPY_AND_ASSIGN(ResourceUsageReporterImpl);
222 }; 223 };
223 224
224 void CreateResourceUsageReporter( 225 void CreateResourceUsageReporter(
225 base::WeakPtr<ChromeRenderThreadObserver> observer, 226 base::WeakPtr<ChromeRenderThreadObserver> observer,
226 mojo::InterfaceRequest<mojom::ResourceUsageReporter> request) { 227 mojo::InterfaceRequest<chrome::mojom::ResourceUsageReporter> request) {
227 mojo::MakeStrongBinding(base::MakeUnique<ResourceUsageReporterImpl>(observer), 228 mojo::MakeStrongBinding(base::MakeUnique<ResourceUsageReporterImpl>(observer),
228 std::move(request)); 229 std::move(request));
229 } 230 }
230 231
231 } // namespace 232 } // namespace
232 233
233 bool ChromeRenderThreadObserver::is_incognito_process_ = false; 234 bool ChromeRenderThreadObserver::is_incognito_process_ = false;
234 235
235 ChromeRenderThreadObserver::ChromeRenderThreadObserver() 236 ChromeRenderThreadObserver::ChromeRenderThreadObserver()
236 : field_trial_syncer_(this), 237 : field_trial_syncer_(this),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void ChromeRenderThreadObserver::OnSetFieldTrialGroup( 311 void ChromeRenderThreadObserver::OnSetFieldTrialGroup(
311 const std::string& trial_name, 312 const std::string& trial_name,
312 const std::string& group_name) { 313 const std::string& group_name) {
313 field_trial_syncer_.OnSetFieldTrialGroup(trial_name, group_name); 314 field_trial_syncer_.OnSetFieldTrialGroup(trial_name, group_name);
314 } 315 }
315 316
316 const RendererContentSettingRules* 317 const RendererContentSettingRules*
317 ChromeRenderThreadObserver::content_setting_rules() const { 318 ChromeRenderThreadObserver::content_setting_rules() const {
318 return &content_setting_rules_; 319 return &content_setting_rules_;
319 } 320 }
OLDNEW
« no previous file with comments | « chrome/common/resource_usage_reporter_type_converters.cc ('k') | chrome/utility/chrome_content_utility_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698