Remove a static initializer from rlz.
BUG=chromium:120335
Review URL: https://codereview.appspot.com/5918044
git-svn-id: http://rlz.googlecode.com/svn/trunk@119 10bc0f33-e4bf-9a86-80cf-af638054f0c4
diff --git a/lib/rlz_lib.cc b/lib/rlz_lib.cc
index 233f52d..67168e5 100644
--- a/lib/rlz_lib.cc
+++ b/lib/rlz_lib.cc
@@ -7,6 +7,7 @@
#include "rlz/lib/rlz_lib.h"
+#include "base/lazy_instance.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "rlz/lib/assert.h"
@@ -682,12 +683,14 @@
return true;
}
+static base::LazyInstance<std::string>::Leaky g_supplemental_branding;
+
SupplementaryBranding::SupplementaryBranding(const char* brand)
: lock_(new ScopedRlzValueStoreLock) {
if (!lock_->GetStore())
return;
- if (!brand_.empty()) {
+ if (!g_supplemental_branding.Get().empty()) {
ASSERT_STRING("ProductBranding: existing brand is not empty");
return;
}
@@ -697,15 +700,18 @@
return;
}
- brand_ = brand;
+ g_supplemental_branding.Get() = brand;
}
SupplementaryBranding::~SupplementaryBranding() {
if (lock_->GetStore())
- brand_.clear();
+ g_supplemental_branding.Get().clear();
delete lock_;
}
-std::string SupplementaryBranding::brand_;
+// static
+const std::string& SupplementaryBranding::GetBrand() {
+ return g_supplemental_branding.Get();
+}
} // namespace rlz_lib
diff --git a/lib/rlz_lib.h b/lib/rlz_lib.h
index 0a8f511..129f35a 100644
--- a/lib/rlz_lib.h
+++ b/lib/rlz_lib.h
@@ -324,12 +324,10 @@
SupplementaryBranding(const char* brand);
~SupplementaryBranding();
- static const std::string& GetBrand() { return brand_; }
+ static const std::string& GetBrand();
private:
ScopedRlzValueStoreLock* lock_;
-
- static std::string brand_;
};
} // namespace rlz_lib