Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa_finder.cc

Issue 23456035: Media Galleries API Picasa: Windows Custom Database Locations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 #include "chrome/browser/storage_monitor/storage_info.h" 16 #include "chrome/browser/storage_monitor/storage_info.h"
13 #include "chrome/common/media_galleries/picasa_types.h" 17 #include "chrome/common/media_galleries/picasa_types.h"
14 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
15 19
20 #if defined(OS_WIN)
21 #include "base/win/registry.h"
22 #endif
23
16 namespace picasa { 24 namespace picasa {
17 25
26 #if defined(OS_WIN)
27 const wchar_t kPicasaRegistryPath[] =
Greg Billock 2013/10/01 20:50:35 Can you just move this to a local const inside the
tommycli 2013/10/01 22:07:22 Tests use this.
28 L"Software\\Google\\Picasa\\Picasa2\\Preferences";
29 const wchar_t kPicasaRegistryAppDataKey[] = L"AppLocalDataPath";
30 #endif
31
18 namespace { 32 namespace {
19 33
34 #if defined(OS_WIN)
35 base::FilePath GetCustomPicasaRoot() {
36 base::win::RegKey key;
37 if (key.Open(HKEY_CURRENT_USER, kPicasaRegistryPath, KEY_READ) !=
38 ERROR_SUCCESS ||
39 !key.Valid()) {
40 return base::FilePath();
41 }
42
43 std::wstring value;
Greg Billock 2013/10/01 20:50:35 Can we use string16 here?
tommycli 2013/10/01 22:07:22 Done. Yes, that's better !
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 GetPicasaDatabasePath() {
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(
58 kPicasaDatabaseDirName);
59 }
60 #elif defined (OS_MACOSX)
61 base::FilePath GetPicasaDatabasePath() {
62 // TODO(tommycli): Support Picasa Mac's custom path.
63 base::FilePath path;
64 if (!PathService::Get(base::DIR_APP_DATA, &path))
65 return base::FilePath();
66
67 // On Mac, the database is in "Picasa3", not "Picasa2".
68 return path.AppendASCII("Google").AppendASCII("Picasa3").AppendASCII(
69 kPicasaDatabaseDirName);
70 }
71 #else
72 base::FilePath GetPicasaDatabasePath() {
73 return base::FilePath();
74 }
75 #endif
76
20 // Returns path of Picasa's DB3 database directory. May only be called on 77 // 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. 78 // threads that allow for disk IO, like the FILE thread or MediaTaskRunner.
22 base::FilePath FindPicasaDatabaseOnFileThread() { 79 base::FilePath FindPicasaDatabaseOnFileThread() {
23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 80 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
24 base::FilePath path; 81 base::FilePath path = GetPicasaDatabasePath();
Greg Billock 2013/10/01 20:50:35 Can we split the platforms here, so like base::Fi
tommycli 2013/10/01 22:07:22 Done.
25
26 #if defined(OS_WIN)
27 // TODO(tommycli): Check registry for alternative path.
28 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, &path))
29 return base::FilePath();
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 82
41 // Verify actual existence 83 // Verify actual existence
42 if (!base::DirectoryExists(path)) 84 if (!base::DirectoryExists(path))
43 path.clear(); 85 path.clear();
44 86
45 return path; 87 return path;
46 } 88 }
47 89
48 void FinishOnOriginalThread(const DeviceIDCallback& callback, 90 void FinishOnOriginalThread(const DeviceIDCallback& callback,
49 const base::FilePath& database_path) { 91 const base::FilePath& database_path) {
50 std::string device_id; 92 std::string device_id;
51 if (!database_path.empty()) { 93 if (!database_path.empty()) {
52 device_id = StorageInfo::MakeDeviceId(StorageInfo::PICASA, 94 device_id = StorageInfo::MakeDeviceId(StorageInfo::PICASA,
53 database_path.AsUTF8Unsafe()); 95 database_path.AsUTF8Unsafe());
54 } 96 }
55 callback.Run(device_id); 97 callback.Run(device_id);
56 } 98 }
57 99
58 } // namespace 100 } // namespace
59 101
60 void FindPicasaDatabase(const DeviceIDCallback& callback) { 102 void FindPicasaDatabase(const DeviceIDCallback& callback) {
61 content::BrowserThread::PostTaskAndReplyWithResult( 103 content::BrowserThread::PostTaskAndReplyWithResult(
62 content::BrowserThread::FILE, 104 content::BrowserThread::FILE,
63 FROM_HERE, 105 FROM_HERE,
64 base::Bind(&FindPicasaDatabaseOnFileThread), 106 base::Bind(&FindPicasaDatabaseOnFileThread),
65 base::Bind(&FinishOnOriginalThread, callback)); 107 base::Bind(&FinishOnOriginalThread, callback));
66 } 108 }
67 109
68 } // namespace picasa 110 } // namespace picasa
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/fileapi/picasa_finder.h ('k') | chrome/browser/media_galleries/media_galleries_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698