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

Unified Diff: rlz/chromeos/lib/rlz_value_store_chromeos.cc

Issue 2800153002: Fix static initializers in RlzValueStoreChromeOS. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « rlz/chromeos/lib/rlz_value_store_chromeos.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rlz/chromeos/lib/rlz_value_store_chromeos.cc
diff --git a/rlz/chromeos/lib/rlz_value_store_chromeos.cc b/rlz/chromeos/lib/rlz_value_store_chromeos.cc
index 6c72bff7cb2c8ea2ce9ab4a84a078747d0456062..347f7e5b7226e87979cb14aac05db63b63cdc1f4 100644
--- a/rlz/chromeos/lib/rlz_value_store_chromeos.cc
+++ b/rlz/chromeos/lib/rlz_value_store_chromeos.cc
@@ -9,6 +9,7 @@
#include "base/files/important_file_writer.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_string_value_serializer.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/path_service.h"
@@ -41,24 +42,25 @@ const base::FilePath::CharType kRLZLockFileName[] =
FILE_PATH_LITERAL("RLZ Data.lock");
// RLZ store path for testing.
-base::FilePath g_testing_rlz_store_path_;
+base::LazyInstance<base::FilePath>::Leaky g_testing_rlz_store_path =
+ LAZY_INSTANCE_INITIALIZER;
-// Returns file path of the RLZ storage.
-base::FilePath GetRlzStorePath() {
+base::FilePath GetRlzStorePathCommon() {
base::FilePath homedir;
PathService::Get(base::DIR_HOME, &homedir);
- return g_testing_rlz_store_path_.empty() ?
- homedir.Append(kRLZDataFileName) :
- g_testing_rlz_store_path_.Append(kRLZDataFileName);
+ return g_testing_rlz_store_path.Get().empty()
+ ? homedir
+ : g_testing_rlz_store_path.Get();
+}
+
+// Returns file path of the RLZ storage.
+base::FilePath GetRlzStorePath() {
+ return GetRlzStorePathCommon().Append(kRLZDataFileName);
}
// Returns file path of the RLZ storage lock file.
base::FilePath GetRlzStoreLockPath() {
- base::FilePath homedir;
- PathService::Get(base::DIR_HOME, &homedir);
- return g_testing_rlz_store_path_.empty() ?
- homedir.Append(kRLZLockFileName) :
- g_testing_rlz_store_path_.Append(kRLZLockFileName);
+ return GetRlzStorePathCommon().Append(kRLZLockFileName);
}
// Returns the dictionary key for storing access point-related prefs.
@@ -155,7 +157,7 @@ bool RlzValueStoreChromeOS::ReadProductEvents(
Product product,
std::vector<std::string>* events) {
DCHECK(CalledOnValidThread());
- base::ListValue* events_list = NULL; ;
+ base::ListValue* events_list = nullptr;
if (!rlz_store_->GetList(GetKeyName(kProductEventKey, product), &events_list))
return false;
events->clear();
@@ -311,7 +313,7 @@ ScopedRlzValueStoreLock::ScopedRlzValueStoreLock() {
ScopedRlzValueStoreLock::~ScopedRlzValueStoreLock() {
--g_lock_depth;
- DCHECK(g_lock_depth >= 0);
+ DCHECK_GE(g_lock_depth, 0);
if (g_lock_depth > 0) {
// Other locks are still using store_, so don't free it yet.
@@ -331,7 +333,7 @@ RlzValueStore* ScopedRlzValueStoreLock::GetStore() {
namespace testing {
void SetRlzStoreDirectory(const base::FilePath& directory) {
- g_testing_rlz_store_path_ = directory;
+ g_testing_rlz_store_path.Get() = directory;
}
std::string RlzStoreFilenameStr() {
« no previous file with comments | « rlz/chromeos/lib/rlz_value_store_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698