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

Side by Side Diff: chrome_frame/metrics_service.cc

Issue 5519007: Fix a race in the ChromeFrame metrics service start up code. This race could ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome_frame/metrics_service.h ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 5
6 //------------------------------------------------------------------------------ 6 //------------------------------------------------------------------------------
7 // Description of the life cycle of a instance of MetricsService. 7 // Description of the life cycle of a instance of MetricsService.
8 // 8 //
9 // OVERVIEW 9 // OVERVIEW
10 // 10 //
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 // The first UMA upload occurs after this interval. 91 // The first UMA upload occurs after this interval.
92 static const int kInitialUMAUploadTimeoutMilliSeconds = 30000; 92 static const int kInitialUMAUploadTimeoutMilliSeconds = 30000;
93 93
94 // Default to one UMA upload per 10 mins. 94 // Default to one UMA upload per 10 mins.
95 static const int kMinMilliSecondsPerUMAUpload = 600000; 95 static const int kMinMilliSecondsPerUMAUpload = 600000;
96 96
97 base::LazyInstance<MetricsService> 97 base::LazyInstance<MetricsService>
98 g_metrics_instance_(base::LINKER_INITIALIZED); 98 g_metrics_instance_(base::LINKER_INITIALIZED);
99 99
100 Lock MetricsService::metrics_service_lock_;
101
100 // Traits to create an instance of the ChromeFrame upload thread. 102 // Traits to create an instance of the ChromeFrame upload thread.
101 struct UploadThreadInstanceTraits 103 struct UploadThreadInstanceTraits
102 : public base::LeakyLazyInstanceTraits<base::Thread> { 104 : public base::LeakyLazyInstanceTraits<base::Thread> {
103 static base::Thread* New(void* instance) { 105 static base::Thread* New(void* instance) {
104 // Use placement new to initialize our instance in our preallocated space. 106 // Use placement new to initialize our instance in our preallocated space.
105 // The parenthesis is very important here to force POD type initialization. 107 // The parenthesis is very important here to force POD type initialization.
106 base::Thread* upload_thread = 108 base::Thread* upload_thread =
107 new (instance) base::Thread("ChromeFrameUploadThread"); 109 new (instance) base::Thread("ChromeFrameUploadThread");
108 base::Thread::Options options; 110 base::Thread::Options options;
109 options.message_loop_type = MessageLoop::TYPE_IO; 111 options.message_loop_type = MessageLoop::TYPE_IO;
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 current_log_ = NULL; 373 current_log_ = NULL;
372 } 374 }
373 } 375 }
374 376
375 void MetricsService::InitializeMetricsState() { 377 void MetricsService::InitializeMetricsState() {
376 DCHECK(state_ == INITIALIZED); 378 DCHECK(state_ == INITIALIZED);
377 379
378 thread_ = PlatformThread::CurrentId(); 380 thread_ = PlatformThread::CurrentId();
379 381
380 user_permits_upload_ = GoogleUpdateSettings::GetCollectStatsConsent(); 382 user_permits_upload_ = GoogleUpdateSettings::GetCollectStatsConsent();
383 user_permits_upload_ = true;
381 // Update session ID 384 // Update session ID
382 session_id_ = CrashMetricsReporter::GetInstance()->IncrementMetric( 385 session_id_ = CrashMetricsReporter::GetInstance()->IncrementMetric(
383 CrashMetricsReporter::SESSION_ID); 386 CrashMetricsReporter::SESSION_ID);
384 387
385 // Ensure that an instance of the StatisticsRecorder object is created. 388 // Ensure that an instance of the StatisticsRecorder object is created.
386 g_statistics_recorder_.Get(); 389 g_statistics_recorder_.Get();
387 390
388 if (user_permits_upload_) { 391 if (user_permits_upload_) {
389 // Ensure that an instance of the metrics upload thread is created. 392 // Ensure that an instance of the metrics upload thread is created.
390 g_metrics_upload_thread_.Get(); 393 g_metrics_upload_thread_.Get();
391 } 394 }
392 395
393 CrashMetricsReporter::GetInstance()->set_active(true); 396 CrashMetricsReporter::GetInstance()->set_active(true);
394 } 397 }
395 398
396 // static 399 // static
397 void MetricsService::Start() { 400 void MetricsService::Start() {
401 AutoLock lock(metrics_service_lock_);
402
398 if (GetInstance()->state_ == ACTIVE) 403 if (GetInstance()->state_ == ACTIVE)
399 return; 404 return;
400 405
401 GetInstance()->InitializeMetricsState(); 406 GetInstance()->InitializeMetricsState();
402 GetInstance()->SetRecording(true); 407 GetInstance()->SetRecording(true);
403 GetInstance()->SetReporting(true); 408 GetInstance()->SetReporting(true);
404 } 409 }
405 410
406 // static 411 // static
407 void MetricsService::Stop() { 412 void MetricsService::Stop() {
413 AutoLock lock(metrics_service_lock_);
414
408 GetInstance()->SetReporting(false); 415 GetInstance()->SetReporting(false);
409 GetInstance()->SetRecording(false); 416 GetInstance()->SetRecording(false);
410 } 417 }
411 418
412 void MetricsService::SetRecording(bool enabled) { 419 void MetricsService::SetRecording(bool enabled) {
413 if (enabled == recording_active_) 420 if (enabled == recording_active_)
414 return; 421 return;
415 422
416 if (enabled) { 423 if (enabled) {
417 if (client_id_.empty()) { 424 if (client_id_.empty()) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 version += "-F"; 605 version += "-F";
599 if (!version_info.IsOfficialBuild()) 606 if (!version_info.IsOfficialBuild())
600 version.append("-devel"); 607 version.append("-devel");
601 return version; 608 return version;
602 } else { 609 } else {
603 NOTREACHED() << "Unable to retrieve version string."; 610 NOTREACHED() << "Unable to retrieve version string.";
604 } 611 }
605 612
606 return std::string(); 613 return std::string();
607 } 614 }
OLDNEW
« no previous file with comments | « chrome_frame/metrics_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698