OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_finder.h" | |
6 | |
7 #include "base/base_paths.h" | |
8 #include "base/bind.h" | |
9 #include "base/file_util.h" | |
10 #include "base/path_service.h" | |
11 #include "chrome/browser/storage_monitor/storage_info.h" | |
12 #include "chrome/common/media_galleries/picasa_types.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 | |
15 namespace picasa { | |
16 | |
17 namespace { | |
18 | |
19 // Returns path of Picasa's DB3 database directory. May only be called on | |
20 // threads that allow for disk IO, like the FILE thread or MediaTaskRunner. | |
21 base::FilePath FindPicasaDatabaseOnFileThread() { | |
22 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
23 base::FilePath path; | |
24 | |
25 #if defined(OS_WIN) | |
26 // TODO(tommycli): Check registry for alternative path. | |
27 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, &path)) | |
28 return base::FilePath(); | |
29 #elif defined(OS_MACOSX) | |
30 // TODO(tommycli): Check Mac Preferences for alternative path. | |
31 if (!PathService::Get(base::DIR_APP_DATA, &path)) | |
32 return base::FilePath(); | |
33 #else | |
34 return base::FilePath(); | |
35 #endif | |
36 | |
37 path = path.AppendASCII("Google").AppendASCII("Picasa2") | |
38 .AppendASCII(kPicasaDatabaseDirName); | |
39 | |
40 // Verify actual existence | |
41 if (!base::DirectoryExists(path)) | |
42 path.clear(); | |
43 | |
44 return path; | |
45 } | |
46 | |
47 void FinishOnOriginalThread(const PicasaFinder::DeviceIDCallback& callback, | |
48 const base::FilePath& database_path) { | |
49 if (!database_path.empty()) | |
50 callback.Run(chrome::StorageInfo::MakeDeviceId( | |
51 chrome::StorageInfo::PICASA, | |
52 database_path.AsUTF8Unsafe())); | |
53 } | |
54 | |
55 } // namespace | |
56 | |
57 void PicasaFinder::FindPicasaDatabase( | |
58 const PicasaFinder::DeviceIDCallback& callback) { | |
59 content::BrowserThread::PostTaskAndReplyWithResult( | |
60 content::BrowserThread::FILE, | |
61 FROM_HERE, | |
62 base::Bind(&FindPicasaDatabaseOnFileThread), | |
63 base::Bind(&FinishOnOriginalThread, callback)); | |
64 } | |
65 | |
66 } // namespace picasa | |
OLD | NEW |