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

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

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 months 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
« no previous file with comments | « chrome/gpu/gpu_arc_video_service.cc ('k') | chrome/utility/chrome_content_utility_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 120
121 base::WeakPtrFactory<RendererResourceDelegate> weak_factory_; 121 base::WeakPtrFactory<RendererResourceDelegate> weak_factory_;
122 122
123 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate); 123 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate);
124 }; 124 };
125 125
126 static const int kWaitForWorkersStatsTimeoutMS = 20; 126 static const int kWaitForWorkersStatsTimeoutMS = 20;
127 127
128 class ResourceUsageReporterImpl : public mojom::ResourceUsageReporter { 128 class ResourceUsageReporterImpl : public mojom::ResourceUsageReporter {
129 public: 129 public:
130 ResourceUsageReporterImpl( 130 explicit ResourceUsageReporterImpl(
131 base::WeakPtr<ChromeRenderThreadObserver> observer, 131 base::WeakPtr<ChromeRenderThreadObserver> observer)
132 mojo::InterfaceRequest<mojom::ResourceUsageReporter> req) 132 : workers_to_go_(0), observer_(observer), weak_factory_(this) {}
133 : workers_to_go_(0),
134 binding_(this, std::move(req)),
135 observer_(observer),
136 weak_factory_(this) {}
137 ~ResourceUsageReporterImpl() override {} 133 ~ResourceUsageReporterImpl() override {}
138 134
139 private: 135 private:
140 static void CollectOnWorkerThread( 136 static void CollectOnWorkerThread(
141 const scoped_refptr<base::TaskRunner>& master, 137 const scoped_refptr<base::TaskRunner>& master,
142 base::WeakPtr<ResourceUsageReporterImpl> impl) { 138 base::WeakPtr<ResourceUsageReporterImpl> impl) {
143 size_t total_bytes = 0; 139 size_t total_bytes = 0;
144 size_t used_bytes = 0; 140 size_t used_bytes = 0;
145 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 141 v8::Isolate* isolate = v8::Isolate::GetCurrent();
146 if (isolate) { 142 if (isolate) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS)); 205 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS));
210 } else { 206 } else {
211 // No worker threads so just send out the main thread data right away. 207 // No worker threads so just send out the main thread data right away.
212 SendResults(); 208 SendResults();
213 } 209 }
214 } 210 }
215 211
216 mojom::ResourceUsageDataPtr usage_data_; 212 mojom::ResourceUsageDataPtr usage_data_;
217 GetUsageDataCallback callback_; 213 GetUsageDataCallback callback_;
218 int workers_to_go_; 214 int workers_to_go_;
219 mojo::StrongBinding<mojom::ResourceUsageReporter> binding_;
220 base::WeakPtr<ChromeRenderThreadObserver> observer_; 215 base::WeakPtr<ChromeRenderThreadObserver> observer_;
221 216
222 base::WeakPtrFactory<ResourceUsageReporterImpl> weak_factory_; 217 base::WeakPtrFactory<ResourceUsageReporterImpl> weak_factory_;
223 218
224 DISALLOW_COPY_AND_ASSIGN(ResourceUsageReporterImpl); 219 DISALLOW_COPY_AND_ASSIGN(ResourceUsageReporterImpl);
225 }; 220 };
226 221
227 void CreateResourceUsageReporter( 222 void CreateResourceUsageReporter(
228 base::WeakPtr<ChromeRenderThreadObserver> observer, 223 base::WeakPtr<ChromeRenderThreadObserver> observer,
229 mojo::InterfaceRequest<mojom::ResourceUsageReporter> request) { 224 mojo::InterfaceRequest<mojom::ResourceUsageReporter> request) {
230 new ResourceUsageReporterImpl(observer, std::move(request)); 225 mojo::MakeStrongBinding(base::MakeUnique<ResourceUsageReporterImpl>(observer),
226 std::move(request));
231 } 227 }
232 228
233 } // namespace 229 } // namespace
234 230
235 bool ChromeRenderThreadObserver::is_incognito_process_ = false; 231 bool ChromeRenderThreadObserver::is_incognito_process_ = false;
236 232
237 ChromeRenderThreadObserver::ChromeRenderThreadObserver() 233 ChromeRenderThreadObserver::ChromeRenderThreadObserver()
238 : field_trial_syncer_(this), weak_factory_(this) { 234 : field_trial_syncer_(this), weak_factory_(this) {
239 const base::CommandLine& command_line = 235 const base::CommandLine& command_line =
240 *base::CommandLine::ForCurrentProcess(); 236 *base::CommandLine::ForCurrentProcess();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 void ChromeRenderThreadObserver::OnSetFieldTrialGroup( 299 void ChromeRenderThreadObserver::OnSetFieldTrialGroup(
304 const std::string& trial_name, 300 const std::string& trial_name,
305 const std::string& group_name) { 301 const std::string& group_name) {
306 field_trial_syncer_.OnSetFieldTrialGroup(trial_name, group_name); 302 field_trial_syncer_.OnSetFieldTrialGroup(trial_name, group_name);
307 } 303 }
308 304
309 const RendererContentSettingRules* 305 const RendererContentSettingRules*
310 ChromeRenderThreadObserver::content_setting_rules() const { 306 ChromeRenderThreadObserver::content_setting_rules() const {
311 return &content_setting_rules_; 307 return &content_setting_rules_;
312 } 308 }
OLDNEW
« no previous file with comments | « chrome/gpu/gpu_arc_video_service.cc ('k') | chrome/utility/chrome_content_utility_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698