| 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/iapps_finder_impl.h" | 5 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 | 11 |
| 12 namespace iapps { | 12 namespace iapps { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 void PostResultToUIThread(storage_monitor::StorageInfo::Type type, | 16 void PostResultToUIThread(storage_monitor::StorageInfo::Type type, |
| 17 const IAppsFinderCallback& callback, | 17 const IAppsFinderCallback& callback, |
| 18 const std::string& unique_id) { | 18 const std::string& unique_id) { |
| 19 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 19 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 20 | 20 |
| 21 std::string device_id; | 21 std::string device_id; |
| 22 if (!unique_id.empty()) | 22 if (!unique_id.empty()) |
| 23 device_id = storage_monitor::StorageInfo::MakeDeviceId(type, unique_id); | 23 device_id = storage_monitor::StorageInfo::MakeDeviceId(type, unique_id); |
| 24 | 24 |
| 25 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 25 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 26 base::Bind(callback, device_id)); | 26 base::BindOnce(callback, device_id)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 void FindIAppsOnFileThread(storage_monitor::StorageInfo::Type type, | 31 void FindIAppsOnFileThread(storage_monitor::StorageInfo::Type type, |
| 32 const IAppsFinderTask& task, | 32 const IAppsFinderTask& task, |
| 33 const IAppsFinderCallback& callback) { | 33 const IAppsFinderCallback& callback) { |
| 34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 35 DCHECK(!task.is_null()); | 35 DCHECK(!task.is_null()); |
| 36 DCHECK(!callback.is_null()); | 36 DCHECK(!callback.is_null()); |
| 37 | 37 |
| 38 content::BrowserThread::PostTask( | 38 content::BrowserThread::PostTask( |
| 39 content::BrowserThread::FILE, | 39 content::BrowserThread::FILE, FROM_HERE, |
| 40 FROM_HERE, | 40 base::BindOnce(task, base::Bind(PostResultToUIThread, type, callback))); |
| 41 base::Bind(task, base::Bind(PostResultToUIThread, type, callback))); | |
| 42 } | 41 } |
| 43 | 42 |
| 44 // iTunes is only support on OSX and Windows. | 43 // iTunes is only support on OSX and Windows. |
| 45 #if !defined(OS_MACOSX) && !defined(OS_WIN) | 44 #if !defined(OS_MACOSX) && !defined(OS_WIN) |
| 46 void FindITunesLibrary(const IAppsFinderCallback& callback) { | 45 void FindITunesLibrary(const IAppsFinderCallback& callback) { |
| 47 callback.Run(std::string()); | 46 callback.Run(std::string()); |
| 48 } | 47 } |
| 49 #endif | 48 #endif |
| 50 | 49 |
| 51 bool PathIndicatesITunesLibrary(const std::string& device_id, | 50 bool PathIndicatesITunesLibrary(const std::string& device_id, |
| 52 const base::FilePath& path) { | 51 const base::FilePath& path) { |
| 53 storage_monitor::StorageInfo::Type device_type; | 52 storage_monitor::StorageInfo::Type device_type; |
| 54 std::string unique_id; | 53 std::string unique_id; |
| 55 storage_monitor::StorageInfo::CrackDeviceId( | 54 storage_monitor::StorageInfo::CrackDeviceId( |
| 56 device_id, &device_type, &unique_id); | 55 device_id, &device_type, &unique_id); |
| 57 if (device_type != storage_monitor::StorageInfo::ITUNES) | 56 if (device_type != storage_monitor::StorageInfo::ITUNES) |
| 58 return false; | 57 return false; |
| 59 | 58 |
| 60 // |unique_id| is the path to the library XML file at the library root. | 59 // |unique_id| is the path to the library XML file at the library root. |
| 61 base::FilePath library_root = | 60 base::FilePath library_root = |
| 62 base::FilePath::FromUTF8Unsafe(unique_id).DirName(); | 61 base::FilePath::FromUTF8Unsafe(unique_id).DirName(); |
| 63 return (path == library_root) || | 62 return (path == library_root) || |
| 64 (path == library_root.AppendASCII("iTunes Media")) || | 63 (path == library_root.AppendASCII("iTunes Media")) || |
| 65 (path == library_root.AppendASCII("iTunes Media").AppendASCII("Music")); | 64 (path == library_root.AppendASCII("iTunes Media").AppendASCII("Music")); |
| 66 } | 65 } |
| 67 | 66 |
| 68 } // namespace iapps | 67 } // namespace iapps |
| OLD | NEW |