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 || !key.Valid()) { | |
40 return base::FilePath(); | |
41 } | |
42 | |
43 string16 value; | |
44 if (key.ReadValue(kPicasaRegistryAppDataKey, &value) != ERROR_SUCCESS) | |
45 return base::FilePath(); | |
46 if (value.empty()) | |
47 return base::FilePath(); | |
48 | |
49 return base::FilePath(value); | |
50 } | |
51 | |
52 base::FilePath GetPicasaDatabasePathWin() { | |
53 base::FilePath path = GetCustomPicasaRoot(); | |
54 if (path.empty() && !PathService::Get(base::DIR_LOCAL_APP_DATA, &path)) | |
55 return base::FilePath(); | |
56 | |
57 return path.AppendASCII("Google").AppendASCII("Picasa2").AppendASCII( | |
Greg Billock
2013/10/04 23:52:50
Would it be worth checking this first before looki
tommycli
2013/10/05 00:18:44
I believe the desired logic is to check the regist
| |
58 kPicasaDatabaseDirName); | |
59 } | |
60 #endif | |
61 | |
62 #if defined (OS_MACOSX) | |
63 base::FilePath GetPicasaDatabasePathMac() { | |
64 // TODO(tommycli): Support Picasa Mac's custom path. | |
65 base::FilePath path; | |
66 if (!PathService::Get(base::DIR_APP_DATA, &path)) | |
67 return base::FilePath(); | |
68 | |
69 // On Mac, the database is in "Picasa3", not "Picasa2". | |
70 return path.AppendASCII("Google").AppendASCII("Picasa3").AppendASCII( | |
71 kPicasaDatabaseDirName); | |
72 } | |
73 #endif | |
74 | |
20 // Returns path of Picasa's DB3 database directory. May only be called on | 75 // 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. | 76 // threads that allow for disk IO, like the FILE thread or MediaTaskRunner. |
22 base::FilePath FindPicasaDatabaseOnFileThread() { | 77 base::FilePath FindPicasaDatabaseOnFileThread() { |
23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
24 base::FilePath path; | 79 base::FilePath path; |
25 | 80 #if defined(OS_WIN) |
26 #if defined(OS_WIN) | 81 path = GetPicasaDatabasePathWin(); |
27 // TODO(tommycli): Check registry for alternative path. | 82 #elif defined(OS_MACOSX) |
28 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, &path)) | 83 path = GetPicasaDatabasePathMac(); |
29 return base::FilePath(); | 84 #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 | 85 |
41 // Verify actual existence | 86 // Verify actual existence |
42 if (!base::DirectoryExists(path)) | 87 if (!base::DirectoryExists(path)) |
43 path.clear(); | 88 path.clear(); |
44 | 89 |
45 return path; | 90 return path; |
46 } | 91 } |
47 | 92 |
48 void FinishOnOriginalThread(const DeviceIDCallback& callback, | 93 void FinishOnOriginalThread(const DeviceIDCallback& callback, |
49 const base::FilePath& database_path) { | 94 const base::FilePath& database_path) { |
50 std::string device_id; | 95 std::string device_id; |
51 if (!database_path.empty()) { | 96 if (!database_path.empty()) { |
52 device_id = StorageInfo::MakeDeviceId(StorageInfo::PICASA, | 97 device_id = StorageInfo::MakeDeviceId(StorageInfo::PICASA, |
53 database_path.AsUTF8Unsafe()); | 98 database_path.AsUTF8Unsafe()); |
54 } | 99 } |
55 callback.Run(device_id); | 100 callback.Run(device_id); |
56 } | 101 } |
57 | 102 |
58 } // namespace | 103 } // namespace |
59 | 104 |
60 void FindPicasaDatabase(const DeviceIDCallback& callback) { | 105 void FindPicasaDatabase(const DeviceIDCallback& callback) { |
61 content::BrowserThread::PostTaskAndReplyWithResult( | 106 content::BrowserThread::PostTaskAndReplyWithResult( |
62 content::BrowserThread::FILE, | 107 content::BrowserThread::FILE, |
63 FROM_HERE, | 108 FROM_HERE, |
64 base::Bind(&FindPicasaDatabaseOnFileThread), | 109 base::Bind(&FindPicasaDatabaseOnFileThread), |
65 base::Bind(&FinishOnOriginalThread, callback)); | 110 base::Bind(&FinishOnOriginalThread, callback)); |
66 } | 111 } |
67 | 112 |
68 } // namespace picasa | 113 } // namespace picasa |
OLD | NEW |