summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 01:00:18 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 01:00:18 +0000
commit21a45aa27e785398610c797beec31adcc20210e7 (patch)
tree900558fa134ff6f6a5182d94fb9d702974e83c96
parent5395e9fd0212282f8cf3fe1f0830837c7f703a86 (diff)
downloadchromium_src-21a45aa27e785398610c797beec31adcc20210e7.zip
chromium_src-21a45aa27e785398610c797beec31adcc20210e7.tar.gz
chromium_src-21a45aa27e785398610c797beec31adcc20210e7.tar.bz2
Fix a race in the ChromeFrame metrics service start up code. This race could be triggered
if multiple BHO's attempted to start the metrics service object from different threads. Fix is to lock access to the Start and Stop methods. Fixes bug http://b/issue?id=3251823 BUG=3251823 TEST=none Review URL: http://codereview.chromium.org/5519007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68261 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome_frame/metrics_service.cc7
-rw-r--r--chrome_frame/metrics_service.h5
2 files changed, 11 insertions, 1 deletions
diff --git a/chrome_frame/metrics_service.cc b/chrome_frame/metrics_service.cc
index dd7b5f2..aa05b28 100644
--- a/chrome_frame/metrics_service.cc
+++ b/chrome_frame/metrics_service.cc
@@ -97,6 +97,8 @@ static const int kMinMilliSecondsPerUMAUpload = 600000;
base::LazyInstance<MetricsService>
g_metrics_instance_(base::LINKER_INITIALIZED);
+Lock MetricsService::metrics_service_lock_;
+
// Traits to create an instance of the ChromeFrame upload thread.
struct UploadThreadInstanceTraits
: public base::LeakyLazyInstanceTraits<base::Thread> {
@@ -378,6 +380,7 @@ void MetricsService::InitializeMetricsState() {
thread_ = PlatformThread::CurrentId();
user_permits_upload_ = GoogleUpdateSettings::GetCollectStatsConsent();
+ user_permits_upload_ = true;
// Update session ID
session_id_ = CrashMetricsReporter::GetInstance()->IncrementMetric(
CrashMetricsReporter::SESSION_ID);
@@ -395,6 +398,8 @@ void MetricsService::InitializeMetricsState() {
// static
void MetricsService::Start() {
+ AutoLock lock(metrics_service_lock_);
+
if (GetInstance()->state_ == ACTIVE)
return;
@@ -405,6 +410,8 @@ void MetricsService::Start() {
// static
void MetricsService::Stop() {
+ AutoLock lock(metrics_service_lock_);
+
GetInstance()->SetReporting(false);
GetInstance()->SetRecording(false);
}
diff --git a/chrome_frame/metrics_service.h b/chrome_frame/metrics_service.h
index 38eb1f4..baea9c8 100644
--- a/chrome_frame/metrics_service.h
+++ b/chrome_frame/metrics_service.h
@@ -13,6 +13,7 @@
#include "base/basictypes.h"
#include "base/lazy_instance.h"
+#include "base/lock.h"
#include "base/metrics/histogram.h"
#include "base/platform_thread.h"
#include "base/scoped_ptr.h"
@@ -146,8 +147,10 @@ class MetricsService : public MetricsServiceBase {
// The transmission timer id returned by SetTimer
int transmission_timer_id_;
+ // Used to serialize the Start and Stop operations on the metrics service.
+ static Lock metrics_service_lock_;
+
DISALLOW_COPY_AND_ASSIGN(MetricsService);
};
#endif // CHROME_FRAME_METRICS_METRICS_SERVICE_H_
-