1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#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/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "chrome/common/media_galleries/picasa_types.h"
#include "components/storage_monitor/storage_info.h"
#include "content/public/browser/browser_thread.h"
#if defined(OS_WIN)
#include "base/win/registry.h"
#endif
namespace picasa {
#if defined(OS_WIN)
const wchar_t kPicasaRegistryPath[] =
L"Software\\Google\\Picasa\\Picasa2\\Preferences";
const wchar_t kPicasaRegistryAppDataPathKey[] = L"AppLocalDataPath";
#endif
namespace {
#if defined(OS_WIN)
base::FilePath GetCustomPicasaAppDataPathFromWinRegistry() {
base::win::RegKey key;
if (key.Open(HKEY_CURRENT_USER, kPicasaRegistryPath, KEY_READ) !=
ERROR_SUCCESS || !key.Valid()) {
return base::FilePath();
}
base::string16 value;
if (key.ReadValue(kPicasaRegistryAppDataPathKey, &value) != ERROR_SUCCESS)
return base::FilePath();
if (value.empty())
return base::FilePath();
return base::FilePath(value);
}
base::FilePath GetPicasaDatabasePath() {
base::FilePath path = GetCustomPicasaAppDataPathFromWinRegistry();
if (path.empty() && !PathService::Get(base::DIR_LOCAL_APP_DATA, &path))
return base::FilePath();
return MakePicasaDatabasePath(path);
}
#endif // OS_WIN
#if defined(OS_MACOSX)
base::FilePath GetPicasaDatabasePath() {
base::FilePath path = GetCustomPicasaAppDataPathFromMacPreferences();
if (path.empty() && !PathService::Get(base::DIR_APP_DATA, &path))
return base::FilePath();
return MakePicasaDatabasePath(path);
}
#endif // OS_MACOSX
// 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_CURRENTLY_ON(content::BrowserThread::FILE);
#if defined(OS_WIN) || defined(OS_MACOSX)
base::FilePath path = GetPicasaDatabasePath();
// Verify actual existence
if (!base::DirectoryExists(path))
path.clear();
return path;
#else
return base::FilePath();
#endif
}
void FinishOnOriginalThread(const DeviceIDCallback& callback,
const base::FilePath& database_path) {
std::string device_id;
if (!database_path.empty()) {
device_id = storage_monitor::StorageInfo::MakeDeviceId(
storage_monitor::StorageInfo::PICASA, database_path.AsUTF8Unsafe());
}
callback.Run(device_id);
}
} // namespace
void FindPicasaDatabase(const DeviceIDCallback& callback) {
content::BrowserThread::PostTaskAndReplyWithResult(
content::BrowserThread::FILE,
FROM_HERE,
base::Bind(&FindPicasaDatabaseOnFileThread),
base::Bind(&FinishOnOriginalThread, callback));
}
base::FilePath MakePicasaDatabasePath(
const base::FilePath& picasa_app_data_path) {
#if defined(OS_WIN)
return picasa_app_data_path.AppendASCII("Google").AppendASCII("Picasa2")
.AppendASCII(kPicasaDatabaseDirName);
#elif defined(OS_MACOSX)
return picasa_app_data_path.AppendASCII("Google").AppendASCII("Picasa3")
.AppendASCII(kPicasaDatabaseDirName);
#else
return base::FilePath();
#endif
}
} // namespace picasa
|