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

Side by Side Diff: chromecast/base/metrics/cast_metrics_helper.cc

Issue 1142513004: Chromecast: MessageLoopProxy cleanup --> SingleThreadTaskRunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromecast/base/metrics/cast_metrics_helper.h" 5 #include "chromecast/base/metrics/cast_metrics_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
12 #include "base/metrics/user_metrics.h" 11 #include "base/metrics/user_metrics.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "chromecast/base/metrics/cast_histograms.h" 15 #include "chromecast/base/metrics/cast_histograms.h"
16 #include "chromecast/base/metrics/grouped_histogram.h" 16 #include "chromecast/base/metrics/grouped_histogram.h"
17 17
18 namespace chromecast { 18 namespace chromecast {
19 namespace metrics { 19 namespace metrics {
20 20
21 // A useful macro to make sure current member function runs on the valid thread. 21 // A useful macro to make sure current member function runs on the valid thread.
22 #define MAKE_SURE_THREAD(callback, ...) \ 22 #define MAKE_SURE_THREAD(callback, ...) \
23 if (!message_loop_proxy_->BelongsToCurrentThread()) { \ 23 if (!task_runner_->BelongsToCurrentThread()) { \
24 message_loop_proxy_->PostTask(FROM_HERE, base::Bind( \ 24 task_runner_->PostTask(FROM_HERE, \
25 &CastMetricsHelper::callback, \ 25 base::Bind(&CastMetricsHelper::callback, \
26 base::Unretained(this), ##__VA_ARGS__)); \ 26 base::Unretained(this), ##__VA_ARGS__)); \
27 return; \ 27 return; \
28 } 28 }
29 29
30 namespace { 30 namespace {
31 31
32 CastMetricsHelper* g_instance = NULL; 32 CastMetricsHelper* g_instance = NULL;
33 33
34 // Displayed frames are logged in frames per second (but sampling can be over 34 // Displayed frames are logged in frames per second (but sampling can be over
35 // a longer period of time, e.g. 5 seconds). 35 // a longer period of time, e.g. 5 seconds).
36 const int kDisplayedFramesPerSecondPeriod = 1000000; 36 const int kDisplayedFramesPerSecondPeriod = 1000000;
37 37
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return JoinString(parts, kMetricsNameAppInfoDelimiter); 86 return JoinString(parts, kMetricsNameAppInfoDelimiter);
87 } 87 }
88 88
89 // static 89 // static
90 CastMetricsHelper* CastMetricsHelper::GetInstance() { 90 CastMetricsHelper* CastMetricsHelper::GetInstance() {
91 DCHECK(g_instance); 91 DCHECK(g_instance);
92 return g_instance; 92 return g_instance;
93 } 93 }
94 94
95 CastMetricsHelper::CastMetricsHelper( 95 CastMetricsHelper::CastMetricsHelper(
96 scoped_refptr<base::MessageLoopProxy> message_loop_proxy) 96 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
97 : message_loop_proxy_(message_loop_proxy), 97 : task_runner_(task_runner),
98 metrics_sink_(NULL), 98 metrics_sink_(NULL),
99 record_action_callback_(base::Bind(&base::RecordComputedAction)) { 99 record_action_callback_(base::Bind(&base::RecordComputedAction)) {
100 DCHECK(message_loop_proxy_.get()); 100 DCHECK(task_runner_.get());
101 DCHECK(!g_instance); 101 DCHECK(!g_instance);
102 g_instance = this; 102 g_instance = this;
103 } 103 }
104 104
105 CastMetricsHelper::CastMetricsHelper() 105 CastMetricsHelper::CastMetricsHelper()
106 : metrics_sink_(NULL) { 106 : metrics_sink_(NULL) {
107 DCHECK(!g_instance); 107 DCHECK(!g_instance);
108 g_instance = this; 108 g_instance = this;
109 } 109 }
110 110
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 value, 50); 244 value, 50);
245 } 245 }
246 } 246 }
247 247
248 previous_video_stat_sample_time_ = sample_time; 248 previous_video_stat_sample_time_ = sample_time;
249 } 249 }
250 250
251 std::string CastMetricsHelper::GetMetricsNameWithAppName( 251 std::string CastMetricsHelper::GetMetricsNameWithAppName(
252 const std::string& prefix, 252 const std::string& prefix,
253 const std::string& suffix) const { 253 const std::string& suffix) const {
254 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 254 DCHECK(task_runner_->BelongsToCurrentThread());
255 std::string metrics_name(prefix); 255 std::string metrics_name(prefix);
256 if (!app_id_.empty()) { 256 if (!app_id_.empty()) {
257 if (!metrics_name.empty()) 257 if (!metrics_name.empty())
258 metrics_name.push_back('.'); 258 metrics_name.push_back('.');
259 metrics_name.append(app_id_); 259 metrics_name.append(app_id_);
260 } 260 }
261 if (!suffix.empty()) { 261 if (!suffix.empty()) {
262 if (!metrics_name.empty()) 262 if (!metrics_name.empty())
263 metrics_name.push_back('.'); 263 metrics_name.push_back('.');
264 metrics_name.append(suffix); 264 metrics_name.append(suffix);
265 } 265 }
266 return metrics_name; 266 return metrics_name;
267 } 267 }
268 268
269 void CastMetricsHelper::SetMetricsSink(MetricsSink* delegate) { 269 void CastMetricsHelper::SetMetricsSink(MetricsSink* delegate) {
270 MAKE_SURE_THREAD(SetMetricsSink, delegate); 270 MAKE_SURE_THREAD(SetMetricsSink, delegate);
271 metrics_sink_ = delegate; 271 metrics_sink_ = delegate;
272 } 272 }
273 273
274 void CastMetricsHelper::SetRecordActionCallback( 274 void CastMetricsHelper::SetRecordActionCallback(
275 const RecordActionCallback& callback) { 275 const RecordActionCallback& callback) {
276 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 276 DCHECK(task_runner_->BelongsToCurrentThread());
277 record_action_callback_ = callback; 277 record_action_callback_ = callback;
278 } 278 }
279 279
280 void CastMetricsHelper::RecordSimpleAction(const std::string& action) { 280 void CastMetricsHelper::RecordSimpleAction(const std::string& action) {
281 MAKE_SURE_THREAD(RecordSimpleAction, action); 281 MAKE_SURE_THREAD(RecordSimpleAction, action);
282 282
283 if (metrics_sink_) { 283 if (metrics_sink_) {
284 metrics_sink_->OnAction(action); 284 metrics_sink_->OnAction(action);
285 } else { 285 } else {
286 record_action_callback_.Run(action); 286 record_action_callback_.Run(action);
(...skipping 30 matching lines...) Expand all
317 const base::TimeDelta& value) { 317 const base::TimeDelta& value) {
318 // Follow UMA_HISTOGRAM_MEDIUM_TIMES definition. 318 // Follow UMA_HISTOGRAM_MEDIUM_TIMES definition.
319 LogTimeHistogramEvent(name, value, 319 LogTimeHistogramEvent(name, value,
320 base::TimeDelta::FromMilliseconds(10), 320 base::TimeDelta::FromMilliseconds(10),
321 base::TimeDelta::FromMinutes(3), 321 base::TimeDelta::FromMinutes(3),
322 50); 322 50);
323 } 323 }
324 324
325 } // namespace metrics 325 } // namespace metrics
326 } // namespace chromecast 326 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/base/metrics/cast_metrics_helper.h ('k') | chromecast/browser/android/cast_window_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698