OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/itunes_finder_mac.h" | 5 #include "chrome/browser/media_galleries/fileapi/itunes_finder_mac.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #import "base/memory/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 | 14 |
15 using base::mac::CFCast; | 15 using base::mac::CFCast; |
16 using base::mac::CFToNSCast; | 16 using base::mac::CFToNSCast; |
17 | 17 |
18 namespace itunes { | 18 namespace itunes { |
19 | 19 |
20 ITunesFinderMac::ITunesFinderMac(const ITunesFinderCallback& callback) | 20 ITunesFinderMac::ITunesFinderMac(const ITunesFinderCallback& callback) |
21 : ITunesFinder(callback) { | 21 : ITunesFinder(callback) { |
22 } | 22 } |
23 | 23 |
24 ITunesFinderMac::~ITunesFinderMac() {} | 24 ITunesFinderMac::~ITunesFinderMac() {} |
25 | 25 |
26 void ITunesFinderMac::FindITunesLibraryOnFileThread() { | 26 void ITunesFinderMac::FindITunesLibraryOnFileThread() { |
27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
28 | 28 |
29 CFStringRef iapp_id = CFSTR("com.apple.iApps"); | 29 CFStringRef iapp_id = CFSTR("com.apple.iApps"); |
30 CFStringRef itunes_db_key = CFSTR("iTunesRecentDatabasePaths"); | 30 CFStringRef itunes_db_key = CFSTR("iTunesRecentDatabasePaths"); |
31 scoped_nsobject<NSArray> plist(CFToNSCast(CFCast<CFArrayRef>( | 31 base::scoped_nsobject<NSArray> plist(CFToNSCast( |
32 CFPreferencesCopyAppValue(itunes_db_key, iapp_id)))); | 32 CFCast<CFArrayRef>(CFPreferencesCopyAppValue(itunes_db_key, iapp_id)))); |
33 if (!plist) { | 33 if (!plist) { |
34 PostResultToUIThread(std::string()); | 34 PostResultToUIThread(std::string()); |
35 return; | 35 return; |
36 } | 36 } |
37 | 37 |
38 // Find the most recently used iTunes XML database from the list of database | 38 // Find the most recently used iTunes XML database from the list of database |
39 // paths. Most of the time |plist| has a size of 1. | 39 // paths. Most of the time |plist| has a size of 1. |
40 base::Time most_recent_db_time; | 40 base::Time most_recent_db_time; |
41 base::FilePath most_recent_db_path; | 41 base::FilePath most_recent_db_path; |
42 for (NSString* path_ns in plist.get()) { | 42 for (NSString* path_ns in plist.get()) { |
43 NSString* expanded_path_ns = [path_ns stringByExpandingTildeInPath]; | 43 NSString* expanded_path_ns = [path_ns stringByExpandingTildeInPath]; |
44 base::FilePath db_path(base::mac::NSStringToFilePath(expanded_path_ns)); | 44 base::FilePath db_path(base::mac::NSStringToFilePath(expanded_path_ns)); |
45 | 45 |
46 base::PlatformFileInfo file_info; | 46 base::PlatformFileInfo file_info; |
47 if (!file_util::GetFileInfo(db_path, &file_info)) | 47 if (!file_util::GetFileInfo(db_path, &file_info)) |
48 continue; | 48 continue; |
49 | 49 |
50 // In case of two databases with the same modified time, tie breaker goes | 50 // In case of two databases with the same modified time, tie breaker goes |
51 // to the first one on the list. | 51 // to the first one on the list. |
52 if (file_info.last_modified <= most_recent_db_time) | 52 if (file_info.last_modified <= most_recent_db_time) |
53 continue; | 53 continue; |
54 | 54 |
55 most_recent_db_time = file_info.last_modified; | 55 most_recent_db_time = file_info.last_modified; |
56 most_recent_db_path = db_path; | 56 most_recent_db_path = db_path; |
57 } | 57 } |
58 PostResultToUIThread(most_recent_db_path.value()); | 58 PostResultToUIThread(most_recent_db_path.value()); |
59 } | 59 } |
60 | 60 |
61 } // namespace itunes | 61 } // namespace itunes |
OLD | NEW |