Move registry functions from lib_values into rlz_value_store_registry.

Almost all of them are now used only there.
Review URL: https://codereview.appspot.com/5863043

git-svn-id: http://rlz.googlecode.com/svn/trunk@102 10bc0f33-e4bf-9a86-80cf-af638054f0c4
diff --git a/lib/lib_values.cc b/lib/lib_values.cc
index 69f5749..d2b18c1 100644
--- a/lib/lib_values.cc
+++ b/lib/lib_values.cc
@@ -9,76 +9,8 @@
 #include "base/stringprintf.h"
 #include "rlz/lib/assert.h"
 
-#if defined(OS_WIN)
-#include "base/utf_string_conversions.h"
-#include "base/win/registry.h"
-#include "rlz/lib/rlz_value_store.h"
-#endif
-
-// TODO(thakis): Move registry stuff somewhere else.
-#if defined(OS_WIN)
-namespace {
-
-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);
-  rlz_lib::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);
-  } else {
-    ret = key->Open(HKEY_CURRENT_USER, key_location.c_str(), access);
-  }
-
-  return ret == ERROR_SUCCESS;
-}
-
-}  // anonymous
-#endif  // defined(OS_WIN)
-
 namespace rlz_lib {
 
-// TODO(thakis): Move registry stuff somewhere else.
-#if defined(OS_WIN)
-//
-// Registry information.
-//
-
-const wchar_t kGoogleKeyName[]            = L"Software\\Google";
-const wchar_t kGoogleCommonKeyName[]      = L"Software\\Google\\Common";
-const wchar_t kLibKeyName[]               = L"Software\\Google\\Common\\Rlz";
-const wchar_t kRlzsSubkeyName[]           = L"RLZs";
-const wchar_t kEventsSubkeyName[]         = L"Events";
-const wchar_t kStatefulEventsSubkeyName[] = L"StatefulEvents";
-const wchar_t kDccValueName[]             = L"DCC";
-const wchar_t kPingTimesSubkeyName[]      = L"PTimes";
-
-const wchar_t* GetProductName(Product product) {
-  switch (product) {
-  case IE_TOOLBAR:       return L"T";
-  case TOOLBAR_NOTIFIER: return L"P";
-  case PACK:             return L"U";
-  case DESKTOP:          return L"D";
-  case CHROME:           return L"C";
-  case FF_TOOLBAR:       return L"B";
-  case QSB_WIN:          return L"K";
-  case WEBAPPS:          return L"W";
-  case PINYIN_IME:       return L"N";
-  case PARTNER:          return L"V";
-  }
-
-  ASSERT_STRING("GetProductSubkeyName: Unknown Product");
-  return NULL;
-}
-
-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());
-}
-#endif  // defined(OS_WIN)
-
 //
 // Ping information.
 //
@@ -257,44 +189,4 @@
   return false;
 }
 
-
-// TODO(thakis): Move registry stuff somewhere else.
-#if defined(OS_WIN)
-bool GetPingTimesRegKey(REGSAM access, base::win::RegKey* key) {
-  return GetRegKey(kPingTimesSubkeyName, access, key);
-}
-
-
-bool GetEventsRegKey(const wchar_t* 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,
-                      event_type);
-  AppendBrandToString(&key_location);
-
-  if (product != NULL) {
-    const wchar_t* product_name = rlz_lib::GetProductName(*product);
-    if (!product_name)
-      return false;
-
-    base::StringAppendF(&key_location, L"\\%ls", product_name);
-  }
-
-  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);
-  } else {
-    ret = key->Open(HKEY_CURRENT_USER, key_location.c_str(), access);
-  }
-
-  return ret == ERROR_SUCCESS;
-}
-
-
-bool GetAccessPointRlzsRegKey(REGSAM access, base::win::RegKey* key) {
-  return GetRegKey(kRlzsSubkeyName, access, key);
-}
-#endif  // defined(OS_WIN)
-
 }  // namespace rlz_lib
diff --git a/lib/lib_values.h b/lib/lib_values.h
index e20fba8..ce7384b 100644
--- a/lib/lib_values.h
+++ b/lib/lib_values.h
@@ -10,63 +10,8 @@
 #include "base/basictypes.h"
 #include "rlz/win/lib/rlz_lib.h"
 
-#if defined(OS_WIN)
-#include "base/win/registry.h"
-#endif
-
 namespace rlz_lib {
 
-// TODO(thakis): Move registry stuff somewhere else.
-#if defined(OS_WIN)
-//
-// Registry keys:
-//
-//   RLZ's are stored as:
-//   <AccessPointName>  = <RLZ value> @ kRootKey\kLibKeyName\kRlzsSubkeyName.
-//
-//   Events are stored as:
-//   <AccessPointName><EventName> = 1 @
-//   HKCU\kLibKeyName\kEventsSubkeyName\GetProductName(product).
-//
-//   The OEM Deal Confirmation Code (DCC) is stored as
-//   kDccValueName = <DCC value> @ HKLM\kLibKeyName
-//
-//   The last ping time, per product is stored as:
-//   GetProductName(product) = <last ping time> @
-//   HKCU\kLibKeyName\kPingTimesSubkeyName.
-//
-// The server does not care about any of these constants.
-//
-extern const wchar_t kLibKeyName[];
-extern const wchar_t kRlzsSubkeyName[];
-extern const wchar_t kEventsSubkeyName[];
-extern const wchar_t kStatefulEventsSubkeyName[];
-extern const wchar_t kDccValueName[];
-extern const wchar_t kPingTimesSubkeyName[];
-
-const wchar_t* GetProductName(Product product);
-
-// These are the parent keys of kLibKeyName. These can be deleted safely
-// if completely empty.
-extern const wchar_t kGoogleKeyName[];
-extern const wchar_t kGoogleCommonKeyName[];
-
-// Function to get the specific registry keys.
-bool GetPingTimesRegKey(REGSAM access,
-                        base::win::RegKey* key);
-
-bool GetEventsRegKey(const wchar_t* event_type,
-                     const rlz_lib::Product* product,
-                     REGSAM access,
-                     base::win::RegKey* key);
-
-bool GetAccessPointRlzsRegKey(REGSAM access,
-                              base::win::RegKey* key);
-
-void AppendBrandToString(std::wstring* str);
-#endif  // defined(OS_WIN)
-
-
 //
 // Ping CGI arguments:
 //
diff --git a/win/lib/machine_deal.cc b/win/lib/machine_deal.cc
index 810424e..a69fcf0 100644
--- a/win/lib/machine_deal.cc
+++ b/win/lib/machine_deal.cc
@@ -22,8 +22,11 @@
 #include "rlz/lib/lib_values.h"
 #include "rlz/lib/string_utils.h"
 #include "rlz/win/lib/lib_mutex.h"
+#include "rlz/win/lib/rlz_value_store_registry.h"
 #include "rlz/win/lib/user_key.h"
 
+const wchar_t kDccValueName[]             = L"DCC";
+
 namespace {
 
 // Current DCC can only uses [a-zA-Z0-9_-!@$*();.<>,:]
diff --git a/win/lib/rlz_lib.cc b/win/lib/rlz_lib.cc
index 81c3770..07e5eb7 100644
--- a/win/lib/rlz_lib.cc
+++ b/win/lib/rlz_lib.cc
@@ -9,25 +9,15 @@
 
 #include <windows.h>
 #include <aclapi.h>
-#include <winbase.h>
 #include <winerror.h>
-#include <vector>
 
 #include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/string_util.h"
-#include "base/stringprintf.h"
-#include "base/utf_string_conversions.h"
 #include "base/win/registry.h"
 #include "base/win/windows_version.h"
 #include "rlz/lib/assert.h"
-#include "rlz/lib/financial_ping.h"
-#include "rlz/lib/lib_values.h"
 #include "rlz/lib/rlz_value_store.h"
-#include "rlz/lib/string_utils.h"
-#include "rlz/win/lib/lib_mutex.h"
 #include "rlz/win/lib/machine_deal.h"
-#include "rlz/win/lib/user_key.h"
+#include "rlz/win/lib/rlz_value_store_registry.h"
 
 namespace {
 
@@ -127,7 +117,7 @@
     return false;
 
   base::win::RegKey hklm_key;
-  if (hklm_key.Create(HKEY_LOCAL_MACHINE, kLibKeyName,
+  if (hklm_key.Create(HKEY_LOCAL_MACHINE, rlz_lib::kLibKeyName,
                       KEY_ALL_ACCESS | KEY_WOW64_32KEY) != ERROR_SUCCESS) {
     ASSERT_STRING("rlz_lib::CreateMachineState: "
                   "Unable to create / open machine key.");
diff --git a/win/lib/rlz_value_store_registry.cc b/win/lib/rlz_value_store_registry.cc
index d3d6197..0a32bc1 100644
--- a/win/lib/rlz_value_store_registry.cc
+++ b/win/lib/rlz_value_store_registry.cc
@@ -13,15 +13,118 @@
 
 namespace rlz_lib {
 
+const wchar_t kLibKeyName[]               = L"Software\\Google\\Common\\Rlz";
+
 namespace {
 
+//
+// Registry keys:
+//
+//   RLZ's are stored as:
+//   <AccessPointName>  = <RLZ value> @ kRootKey\kLibKeyName\kRlzsSubkeyName.
+//
+//   Events are stored as:
+//   <AccessPointName><EventName> = 1 @
+//   HKCU\kLibKeyName\kEventsSubkeyName\GetProductName(product).
+//
+//   The OEM Deal Confirmation Code (DCC) is stored as
+//   kDccValueName = <DCC value> @ HKLM\kLibKeyName
+//
+//   The last ping time, per product is stored as:
+//   GetProductName(product) = <last ping time> @
+//   HKCU\kLibKeyName\kPingTimesSubkeyName.
+//
+// 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 wchar_t* GetProductName(Product product) {
+  switch (product) {
+  case IE_TOOLBAR:       return L"T";
+  case TOOLBAR_NOTIFIER: return L"P";
+  case PACK:             return L"U";
+  case DESKTOP:          return L"D";
+  case CHROME:           return L"C";
+  case FF_TOOLBAR:       return L"B";
+  case QSB_WIN:          return L"K";
+  case WEBAPPS:          return L"W";
+  case PINYIN_IME:       return L"N";
+  case PARTNER:          return L"V";
+  }
+
+  ASSERT_STRING("GetProductSubkeyName: Unknown Product");
+  return NULL;
+}
+
+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());
+}
+
+// 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);
+  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);
+  } else {
+    ret = key->Open(HKEY_CURRENT_USER, key_location.c_str(), access);
+  }
+
+  return ret == ERROR_SUCCESS;
+}
+
+bool GetPingTimesRegKey(REGSAM access, base::win::RegKey* key) {
+  return GetRegKey(kPingTimesSubkeyName, access, key);
+}
+
+
+bool GetEventsRegKey(const wchar_t* 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,
+                      event_type);
+  AppendBrandToString(&key_location);
+
+  if (product != NULL) {
+    const wchar_t* product_name = GetProductName(*product);
+    if (!product_name)
+      return false;
+
+    base::StringAppendF(&key_location, L"\\%ls", product_name);
+  }
+
+  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);
+  } else {
+    ret = key->Open(HKEY_CURRENT_USER, key_location.c_str(), access);
+  }
+
+  return ret == ERROR_SUCCESS;
+}
+
+bool GetAccessPointRlzsRegKey(REGSAM access, base::win::RegKey* key) {
+  return GetRegKey(kRlzsSubkeyName, access, key);
+}
+
 bool ClearAllProductEventValues(rlz_lib::Product product, const wchar_t* key) {
-  const wchar_t* product_name = rlz_lib::GetProductName(product);
+  const wchar_t* product_name = GetProductName(product);
   if (!product_name)
     return false;
 
   base::win::RegKey reg_key;
-  rlz_lib::GetEventsRegKey(key, NULL, KEY_WRITE, &reg_key);
+  GetEventsRegKey(key, NULL, KEY_WRITE, &reg_key);
   reg_key.DeleteKey(product_name);
 
   // Verify that the value no longer exists.
diff --git a/win/lib/rlz_value_store_registry.h b/win/lib/rlz_value_store_registry.h
index eed356a..30567fc 100644
--- a/win/lib/rlz_value_store_registry.h
+++ b/win/lib/rlz_value_store_registry.h
@@ -10,6 +10,8 @@
 
 namespace rlz_lib {
 
+extern const wchar_t kLibKeyName[];
+
 // Implements RlzValueStore by storing values in the windows registry.
 class RlzValueStoreRegistry : public RlzValueStore {
  public: