Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" | 5 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | |
| 8 #include <windows.h> | |
| 9 #endif | |
| 10 | |
| 7 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
| 8 #include "base/bind.h" | 12 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 11 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/strings/string16.h" | |
| 12 #include "chrome/browser/storage_monitor/storage_info.h" | 17 #include "chrome/browser/storage_monitor/storage_info.h" |
| 13 #include "chrome/common/media_galleries/picasa_types.h" | 18 #include "chrome/common/media_galleries/picasa_types.h" |
| 14 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 15 | 20 |
| 21 #if defined(OS_WIN) | |
| 22 #include "base/win/registry.h" | |
| 23 #endif | |
| 24 | |
| 16 namespace picasa { | 25 namespace picasa { |
| 17 | 26 |
| 27 #if defined(OS_WIN) | |
| 28 const wchar_t kPicasaRegistryPath[] = | |
| 29 L"Software\\Google\\Picasa\\Picasa2\\Preferences"; | |
| 30 const wchar_t kPicasaRegistryAppDataKey[] = L"AppLocalDataPath"; | |
| 31 #endif | |
| 32 | |
| 18 namespace { | 33 namespace { |
| 19 | 34 |
| 35 #if defined(OS_WIN) | |
| 36 base::FilePath GetCustomPicasaRoot() { | |
| 37 base::win::RegKey key; | |
| 38 if (key.Open(HKEY_CURRENT_USER, kPicasaRegistryPath, KEY_READ) != | |
| 39 ERROR_SUCCESS || | |
| 40 !key.Valid()) { | |
|
vandebo (ex-Chrome)
2013/10/02 15:32:46
nit: previous line
tommycli
2013/10/02 16:44:39
Done.
| |
| 41 return base::FilePath(); | |
| 42 } | |
| 43 | |
| 44 string16 value; | |
| 45 if (key.ReadValue(kPicasaRegistryAppDataKey, &value) != ERROR_SUCCESS) | |
| 46 return base::FilePath(); | |
| 47 if (value.empty()) | |
| 48 return base::FilePath(); | |
| 49 | |
| 50 return base::FilePath(value); | |
| 51 } | |
| 52 | |
| 53 base::FilePath GetPicasaDatabasePathWin() { | |
| 54 base::FilePath path = GetCustomPicasaRoot(); | |
| 55 if (path.empty() && !PathService::Get(base::DIR_LOCAL_APP_DATA, &path)) | |
| 56 return base::FilePath(); | |
| 57 | |
| 58 return path.AppendASCII("Google").AppendASCII("Picasa2").AppendASCII( | |
| 59 kPicasaDatabaseDirName); | |
| 60 } | |
| 61 #endif | |
| 62 | |
| 63 #if defined (OS_MACOSX) | |
| 64 base::FilePath GetPicasaDatabasePathMac() { | |
| 65 // TODO(tommycli): Support Picasa Mac's custom path. | |
| 66 base::FilePath path; | |
| 67 if (!PathService::Get(base::DIR_APP_DATA, &path)) | |
| 68 return base::FilePath(); | |
| 69 | |
| 70 // On Mac, the database is in "Picasa3", not "Picasa2". | |
| 71 return path.AppendASCII("Google").AppendASCII("Picasa3").AppendASCII( | |
| 72 kPicasaDatabaseDirName); | |
| 73 } | |
| 74 #endif | |
| 75 | |
| 20 // Returns path of Picasa's DB3 database directory. May only be called on | 76 // Returns path of Picasa's DB3 database directory. May only be called on |
| 21 // threads that allow for disk IO, like the FILE thread or MediaTaskRunner. | 77 // threads that allow for disk IO, like the FILE thread or MediaTaskRunner. |
| 22 base::FilePath FindPicasaDatabaseOnFileThread() { | 78 base::FilePath FindPicasaDatabaseOnFileThread() { |
| 23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 79 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 24 base::FilePath path; | 80 base::FilePath path; |
| 25 | 81 #if defined(OS_WIN) |
| 26 #if defined(OS_WIN) | 82 path = GetPicasaDatabasePathWin(); |
| 27 // TODO(tommycli): Check registry for alternative path. | 83 #elif defined(OS_MACOSX) |
| 28 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, &path)) | 84 path = GetPicasaDatabasePathMac(); |
| 29 return base::FilePath(); | 85 #endif |
| 30 #elif defined(OS_MACOSX) | |
| 31 // TODO(tommycli): Check Mac Preferences for alternative path. | |
| 32 if (!PathService::Get(base::DIR_APP_DATA, &path)) | |
| 33 return base::FilePath(); | |
| 34 #else | |
| 35 return base::FilePath(); | |
| 36 #endif | |
| 37 | |
| 38 path = path.AppendASCII("Google").AppendASCII("Picasa2").AppendASCII( | |
| 39 kPicasaDatabaseDirName); | |
| 40 | 86 |
| 41 // Verify actual existence | 87 // Verify actual existence |
| 42 if (!base::DirectoryExists(path)) | 88 if (!base::DirectoryExists(path)) |
| 43 path.clear(); | 89 path.clear(); |
| 44 | 90 |
| 45 return path; | 91 return path; |
| 46 } | 92 } |
| 47 | 93 |
| 48 void FinishOnOriginalThread(const DeviceIDCallback& callback, | 94 void FinishOnOriginalThread(const DeviceIDCallback& callback, |
| 49 const base::FilePath& database_path) { | 95 const base::FilePath& database_path) { |
| 50 std::string device_id; | 96 std::string device_id; |
| 51 if (!database_path.empty()) { | 97 if (!database_path.empty()) { |
| 52 device_id = StorageInfo::MakeDeviceId(StorageInfo::PICASA, | 98 device_id = StorageInfo::MakeDeviceId(StorageInfo::PICASA, |
| 53 database_path.AsUTF8Unsafe()); | 99 database_path.AsUTF8Unsafe()); |
| 54 } | 100 } |
| 55 callback.Run(device_id); | 101 callback.Run(device_id); |
| 56 } | 102 } |
| 57 | 103 |
| 58 } // namespace | 104 } // namespace |
| 59 | 105 |
| 60 void FindPicasaDatabase(const DeviceIDCallback& callback) { | 106 void FindPicasaDatabase(const DeviceIDCallback& callback) { |
| 61 content::BrowserThread::PostTaskAndReplyWithResult( | 107 content::BrowserThread::PostTaskAndReplyWithResult( |
| 62 content::BrowserThread::FILE, | 108 content::BrowserThread::FILE, |
| 63 FROM_HERE, | 109 FROM_HERE, |
| 64 base::Bind(&FindPicasaDatabaseOnFileThread), | 110 base::Bind(&FindPicasaDatabaseOnFileThread), |
| 65 base::Bind(&FinishOnOriginalThread, callback)); | 111 base::Bind(&FinishOnOriginalThread, callback)); |
| 66 } | 112 } |
| 67 | 113 |
| 68 } // namespace picasa | 114 } // namespace picasa |
| OLD | NEW |