Index: chrome/browser/media_galleries/fileapi/picasa_finder.cc |
diff --git a/chrome/browser/media_galleries/fileapi/picasa_finder.cc b/chrome/browser/media_galleries/fileapi/picasa_finder.cc |
index b3b4b2525c7c4a95c66899f2c8ee9f6de6052347..c110aaa81040f65e983d8697d50825f862795e8f 100644 |
--- a/chrome/browser/media_galleries/fileapi/picasa_finder.cc |
+++ b/chrome/browser/media_galleries/fileapi/picasa_finder.cc |
@@ -4,39 +4,85 @@ |
#include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
+#if defined(OS_WIN) |
+#include <windows.h> |
+#endif |
+ |
#include "base/base_paths.h" |
#include "base/bind.h" |
#include "base/file_util.h" |
#include "base/files/file_path.h" |
#include "base/path_service.h" |
+#include "base/strings/string16.h" |
#include "chrome/browser/storage_monitor/storage_info.h" |
#include "chrome/common/media_galleries/picasa_types.h" |
#include "content/public/browser/browser_thread.h" |
+#if defined(OS_WIN) |
+#include "base/win/registry.h" |
+#endif |
+ |
namespace picasa { |
-namespace { |
+#if defined(OS_WIN) |
+const wchar_t kPicasaRegistryPath[] = |
+ L"Software\\Google\\Picasa\\Picasa2\\Preferences"; |
+const wchar_t kPicasaRegistryAppDataKey[] = L"AppLocalDataPath"; |
+#endif |
-// Returns path of Picasa's DB3 database directory. May only be called on |
-// threads that allow for disk IO, like the FILE thread or MediaTaskRunner. |
-base::FilePath FindPicasaDatabaseOnFileThread() { |
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
- base::FilePath path; |
+namespace { |
#if defined(OS_WIN) |
- // TODO(tommycli): Check registry for alternative path. |
- if (!PathService::Get(base::DIR_LOCAL_APP_DATA, &path)) |
+base::FilePath GetCustomPicasaRoot() { |
+ base::win::RegKey key; |
+ if (key.Open(HKEY_CURRENT_USER, kPicasaRegistryPath, KEY_READ) != |
+ ERROR_SUCCESS || |
+ !key.Valid()) { |
vandebo (ex-Chrome)
2013/10/02 15:32:46
nit: previous line
tommycli
2013/10/02 16:44:39
Done.
|
+ return base::FilePath(); |
+ } |
+ |
+ string16 value; |
+ if (key.ReadValue(kPicasaRegistryAppDataKey, &value) != ERROR_SUCCESS) |
return base::FilePath(); |
-#elif defined(OS_MACOSX) |
- // TODO(tommycli): Check Mac Preferences for alternative path. |
+ if (value.empty()) |
+ return base::FilePath(); |
+ |
+ return base::FilePath(value); |
+} |
+ |
+base::FilePath GetPicasaDatabasePathWin() { |
+ base::FilePath path = GetCustomPicasaRoot(); |
+ if (path.empty() && !PathService::Get(base::DIR_LOCAL_APP_DATA, &path)) |
+ return base::FilePath(); |
+ |
+ return path.AppendASCII("Google").AppendASCII("Picasa2").AppendASCII( |
+ kPicasaDatabaseDirName); |
+} |
+#endif |
+ |
+#if defined (OS_MACOSX) |
+base::FilePath GetPicasaDatabasePathMac() { |
+ // TODO(tommycli): Support Picasa Mac's custom path. |
+ base::FilePath path; |
if (!PathService::Get(base::DIR_APP_DATA, &path)) |
return base::FilePath(); |
-#else |
- return base::FilePath(); |
+ |
+ // On Mac, the database is in "Picasa3", not "Picasa2". |
+ return path.AppendASCII("Google").AppendASCII("Picasa3").AppendASCII( |
+ kPicasaDatabaseDirName); |
+} |
#endif |
- path = path.AppendASCII("Google").AppendASCII("Picasa2").AppendASCII( |
- kPicasaDatabaseDirName); |
+// Returns path of Picasa's DB3 database directory. May only be called on |
+// threads that allow for disk IO, like the FILE thread or MediaTaskRunner. |
+base::FilePath FindPicasaDatabaseOnFileThread() { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
+ base::FilePath path; |
+ #if defined(OS_WIN) |
+ path = GetPicasaDatabasePathWin(); |
+ #elif defined(OS_MACOSX) |
+ path = GetPicasaDatabasePathMac(); |
+ #endif |
// Verify actual existence |
if (!base::DirectoryExists(path)) |