Use char version functions in base/stringprintf.h.

A chromium change in base/ is going to remove wchar/wstring version of
StringPrintf. So change to use char version of functions in
win/lib/rlz_value_store_registry.cc .

http://codereview.chromium.org/10449042/
Patch from Hao Zheng <zhenghao@chromium.org>!



git-svn-id: http://rlz.googlecode.com/svn/trunk@129 10bc0f33-e4bf-9a86-80cf-af638054f0c4
diff --git a/win/lib/machine_deal.cc b/win/lib/machine_deal.cc
index 93a2fbb..20941a9 100644
--- a/win/lib/machine_deal.cc
+++ b/win/lib/machine_deal.cc
@@ -135,7 +135,8 @@
     return false;
   }
 
-  base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, kLibKeyName,
+  base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE,
+                             RlzValueStoreRegistry::GetWideLibKeyName().c_str(),
                              KEY_READ | KEY_WRITE | KEY_WOW64_32KEY);
   if (!hklm_key.Valid()) {
     ASSERT_STRING("MachineDealCode::Set: Unable to create / open machine key."
@@ -260,7 +261,8 @@
 
   dcc[0] = 0;
 
-  base::win::RegKey dcc_key(HKEY_LOCAL_MACHINE, kLibKeyName,
+  base::win::RegKey dcc_key(HKEY_LOCAL_MACHINE,
+                            RlzValueStoreRegistry::GetWideLibKeyName().c_str(),
                             KEY_READ | KEY_WOW64_32KEY);
   if (!dcc_key.Valid())
     return false;  // no DCC key.
@@ -276,7 +278,8 @@
 }
 
 bool MachineDealCode::Clear() {
-  base::win::RegKey dcc_key(HKEY_LOCAL_MACHINE, kLibKeyName,
+  base::win::RegKey dcc_key(HKEY_LOCAL_MACHINE,
+                            RlzValueStoreRegistry::GetWideLibKeyName().c_str(),
                             KEY_READ | KEY_WRITE | KEY_WOW64_32KEY);
   if (!dcc_key.Valid())
     return false;  // no DCC key.
diff --git a/win/lib/rlz_value_store_registry.cc b/win/lib/rlz_value_store_registry.cc
index dcc0e9c..0c503cf 100644
--- a/win/lib/rlz_value_store_registry.cc
+++ b/win/lib/rlz_value_store_registry.cc
@@ -15,8 +15,6 @@
 
 namespace rlz_lib {
 
-const wchar_t kLibKeyName[]               = L"Software\\Google\\Common\\Rlz";
-
 namespace {
 
 //
@@ -38,34 +36,37 @@
 //
 // The server does not care about any of these constants.
 //
-const wchar_t kGoogleKeyName[]            = L"Software\\Google";
-const wchar_t kGoogleCommonKeyName[]      = L"Software\\Google\\Common";
-const wchar_t kRlzsSubkeyName[]           = L"RLZs";
-const wchar_t kEventsSubkeyName[]         = L"Events";
-const wchar_t kStatefulEventsSubkeyName[] = L"StatefulEvents";
-const wchar_t kPingTimesSubkeyName[]      = L"PTimes";
+const char kLibKeyName[]               = "Software\\Google\\Common\\Rlz";
+const wchar_t kGoogleKeyName[]         = L"Software\\Google";
+const wchar_t kGoogleCommonKeyName[]   = L"Software\\Google\\Common";
+const char kRlzsSubkeyName[]           = "RLZs";
+const char kEventsSubkeyName[]         = "Events";
+const char kStatefulEventsSubkeyName[] = "StatefulEvents";
+const char kPingTimesSubkeyName[]      = "PTimes";
 
 std::wstring GetWideProductName(Product product) {
   return ASCIIToWide(GetProductName(product));
 }
 
-void AppendBrandToString(std::wstring* str) {
-  std::wstring wide_brand(ASCIIToWide(SupplementaryBranding::GetBrand()));
-  if (!wide_brand.empty())
-    base::StringAppendF(str, L"\\_%ls", wide_brand.c_str());
+void AppendBrandToString(std::string* str) {
+  std::string brand(SupplementaryBranding::GetBrand());
+  if (!brand.empty())
+    base::StringAppendF(str, "\\_%s", brand.c_str());
 }
 
 // Function to get the specific registry keys.
-bool GetRegKey(const wchar_t* name, REGSAM access, base::win::RegKey* key) {
-  std::wstring key_location;
-  base::StringAppendF(&key_location, L"%ls\\%ls", rlz_lib::kLibKeyName, name);
+bool GetRegKey(const char* name, REGSAM access, base::win::RegKey* key) {
+  std::string key_location;
+  base::StringAppendF(&key_location, "%s\\%s", kLibKeyName, name);
   AppendBrandToString(&key_location);
 
   LONG ret = ERROR_SUCCESS;
   if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) {
-    ret = key->Create(HKEY_CURRENT_USER, key_location.c_str(), access);
+    ret = key->Create(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
+                      access);
   } else {
-    ret = key->Open(HKEY_CURRENT_USER, key_location.c_str(), access);
+    ret = key->Open(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
+                    access);
   }
 
   return ret == ERROR_SUCCESS;
@@ -76,27 +77,29 @@
 }
 
 
-bool GetEventsRegKey(const wchar_t* event_type,
+bool GetEventsRegKey(const char* event_type,
                      const rlz_lib::Product* product,
                      REGSAM access, base::win::RegKey* key) {
-  std::wstring key_location;
-  base::StringAppendF(&key_location, L"%ls\\%ls", rlz_lib::kLibKeyName,
+  std::string key_location;
+  base::StringAppendF(&key_location, "%s\\%s", kLibKeyName,
                       event_type);
   AppendBrandToString(&key_location);
 
   if (product != NULL) {
-    std::wstring product_name = GetWideProductName(*product);
+    std::string product_name = GetProductName(*product);
     if (product_name.empty())
       return false;
 
-    base::StringAppendF(&key_location, L"\\%ls", product_name.c_str());
+    base::StringAppendF(&key_location, "\\%s", product_name.c_str());
   }
 
   LONG ret = ERROR_SUCCESS;
   if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) {
-    ret = key->Create(HKEY_CURRENT_USER, key_location.c_str(), access);
+    ret = key->Create(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
+                      access);
   } else {
-    ret = key->Open(HKEY_CURRENT_USER, key_location.c_str(), access);
+    ret = key->Open(HKEY_CURRENT_USER, ASCIIToWide(key_location).c_str(),
+                    access);
   }
 
   return ret == ERROR_SUCCESS;
@@ -106,7 +109,7 @@
   return GetRegKey(kRlzsSubkeyName, access, key);
 }
 
-bool ClearAllProductEventValues(rlz_lib::Product product, const wchar_t* key) {
+bool ClearAllProductEventValues(rlz_lib::Product product, const char* key) {
   std::wstring product_name = GetWideProductName(product);
   if (product_name.empty())
     return false;
@@ -153,6 +156,11 @@
 
 }  // namespace
 
+// static
+std::wstring RlzValueStoreRegistry::GetWideLibKeyName() {
+  return ASCIIToWide(kLibKeyName);
+}
+
 bool RlzValueStoreRegistry::HasAccess(AccessType type) {
   return HasUserKeyAccess(type == kWriteAccess);
 }
@@ -339,7 +347,7 @@
 
 void RlzValueStoreRegistry::CollectGarbage() {
   // Delete each of the known subkeys if empty.
-  const wchar_t* subkeys[] = {
+  const char* subkeys[] = {
     kRlzsSubkeyName,
     kEventsSubkeyName,
     kStatefulEventsSubkeyName,
@@ -347,15 +355,16 @@
   };
 
   for (int i = 0; i < arraysize(subkeys); i++) {
-    std::wstring subkey_name;
-    base::StringAppendF(&subkey_name, L"%ls\\%ls", kLibKeyName, subkeys[i]);
+    std::string subkey_name;
+    base::StringAppendF(&subkey_name, "%s\\%s", kLibKeyName, subkeys[i]);
     AppendBrandToString(&subkey_name);
 
-    VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER, subkey_name.c_str()));
+    VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER,
+                            ASCIIToWide(subkey_name).c_str()));
   }
 
   // Delete the library key and its parents too now if empty.
-  VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER, kLibKeyName));
+  VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER, GetWideLibKeyName().c_str()));
   VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER, kGoogleCommonKeyName));
   VERIFY(DeleteKeyIfEmpty(HKEY_CURRENT_USER, kGoogleKeyName));
 }
diff --git a/win/lib/rlz_value_store_registry.h b/win/lib/rlz_value_store_registry.h
index 30567fc..3ec1969 100644
--- a/win/lib/rlz_value_store_registry.h
+++ b/win/lib/rlz_value_store_registry.h
@@ -10,11 +10,11 @@
 
 namespace rlz_lib {
 
-extern const wchar_t kLibKeyName[];
-
 // Implements RlzValueStore by storing values in the windows registry.
 class RlzValueStoreRegistry : public RlzValueStore {
  public:
+  static std::wstring GetWideLibKeyName();
+
   virtual bool HasAccess(AccessType type) OVERRIDE;
 
   virtual bool WritePingTime(Product product, int64 time) OVERRIDE;