diff options
author | tommycli <tommycli@chromium.org> | 2016-03-18 11:52:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-18 18:53:39 +0000 |
commit | a239a382db30c140c83b8eba6a875718183dc77a (patch) | |
tree | c456daadb4e35ec170011014411ae60861701afe | |
parent | 02158c8c190ae32d55ae64074bd8068bd17a0812 (diff) | |
download | chromium_src-a239a382db30c140c83b8eba6a875718183dc77a.zip chromium_src-a239a382db30c140c83b8eba6a875718183dc77a.tar.gz chromium_src-a239a382db30c140c83b8eba6a875718183dc77a.tar.bz2 |
Media Galleries Partial Deprecation: Remove iPhoto support.
Axes about 2900 SLOC and iPhoto support. Affects Mac OSX only.
BUG=542912
Review URL: https://codereview.chromium.org/1805203002
Cr-Commit-Position: refs/heads/master@{#382034}
51 files changed, 12 insertions, 2922 deletions
diff --git a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc index d6a34a1..52358f3 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc +++ b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc @@ -851,7 +851,7 @@ TEST_F(VolumeManagerTest, MTPPlugAndUnplug) { storage_monitor::StorageInfo non_mtp_info( storage_monitor::StorageInfo::MakeDeviceId( - storage_monitor::StorageInfo::IPHOTO, "dummy-device-id2"), + storage_monitor::StorageInfo::FIXED_MASS_STORAGE, "dummy-device-id2"), FILE_PATH_LITERAL("/dummy/device/location2"), base::UTF8ToUTF16("label2"), base::UTF8ToUTF16("vendor2"), diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc index 9016860..95a96e5 100644 --- a/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc +++ b/chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc @@ -234,106 +234,6 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { } #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - void PopulateIPhotoTestData(const base::FilePath& iphoto_data_root) { - std::string xml_contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" - "<plist version=\"1.0\">" - "<dict>\n" - - " <key>List of Albums</key>" - " <array>\n" - - " <dict>\n" - " <key>AlbumId</key>" - " <integer>1</integer>" - " <key>AlbumName</key>" - " <string>Album1</string>" - " <key>KeyList</key>\n" - " <array>" - " <string>1</string>" - " <string>2</string>" - " </array>\n" - " </dict>\n" - - " <dict>\n" - " <key>AlbumId</key>" - " <integer>2</integer>" - " <key>AlbumName</key>" - " <string>Album2</string>" - " <key>KeyList</key>\n" - " <array>" - " <string>2</string>" - " </array>\n" - " </dict>\n" - - " </array>\n" - - " <key>Master Image List</key>\n" - " <dict>\n" - - " <key>1</key>" - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption</key>" - " <string>caption 1</string>" - " <key>GUID</key>" - " <string>1</string>" - " <key>ModDateAsTimerInterval</key>" - " <string>386221543.0000</string>" - " <key>DateAsTimerInterval</key>" - " <string>386221543.0000</string>" - " <key>DateAsTimerIntervalGMT</key>" - " <string>385123456.00</string>" - " <key>ImagePath</key>" - " <string>$path1</string>" - " <key>ThumbPath</key>" - " <string>/thumb/path</string>\n" - " </dict>\n" - - " <key>2</key>\n" - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption</key>" - " <string>caption 2</string>" - " <key>GUID</key>" - " <string>2</string>" - " <key>ModDateAsTimerInterval</key>" - " <string>386221543.0000</string>" - " <key>DateAsTimerInterval</key>" - " <string>386221543.0000</string>" - " <key>DateAsTimerIntervalGMT</key>" - " <string>385123456.00</string>" - " <key>ImagePath</key>" - " <string>$path2</string>" - " <key>ThumbPath</key>" - " <string>/thumb/path2</string>\n" - " </dict>\n" - - " </dict>\n" // Master Image List - - "</dict>\n" - "</plist>"; - - base::FilePath test_jpg_path = GetCommonDataDir().AppendASCII("test.jpg"); - ASSERT_TRUE(base::CreateDirectory(iphoto_data_root)); - base::FilePath first_only_jpg = - iphoto_data_root.AppendASCII("InFirstAlbumOnly.jpg"); - base::FilePath in_both_jpg = iphoto_data_root.AppendASCII("InBoth.jpg"); - ASSERT_TRUE(base::CopyFile(test_jpg_path, first_only_jpg)); - ASSERT_TRUE(base::CopyFile(test_jpg_path, in_both_jpg)); - base::ReplaceFirstSubstringAfterOffset( - &xml_contents, 0, "$path1", first_only_jpg.value()); - base::ReplaceFirstSubstringAfterOffset( - &xml_contents, 0, "$path2", in_both_jpg.value()); - - base::FilePath album_xml = iphoto_data_root.AppendASCII("AlbumData.xml"); - ASSERT_NE(-1, base::WriteFile(album_xml, - xml_contents.c_str(), xml_contents.size())); - } -#endif // defined(OS_MACOSX) - base::FilePath GetCommonDataDir() const { return test_data_dir_.AppendASCII("api_test") .AppendASCII("media_galleries") @@ -534,20 +434,6 @@ IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, } #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) -IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, - IPhotoTest) { - PopulateIPhotoTestData( - ensure_media_directories_exists()->GetFakeIPhotoRootPath()); - - base::ListValue custom_args; - custom_args.AppendInteger(test_jpg_size()); - ASSERT_TRUE(RunMediaGalleriesTestWithArg("iphoto", custom_args)) << message_; - - iapps::SetMacPreferencesForTesting(NULL); -} -#endif // defined(OS_MACOSX) - IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, ToURL) { RemoveAllGalleries(); MediaGalleryPrefId pref_id; diff --git a/chrome/browser/media_galleries/fileapi/iapps_finder.h b/chrome/browser/media_galleries/fileapi/iapps_finder.h index 4184cc3..1002d81 100644 --- a/chrome/browser/media_galleries/fileapi/iapps_finder.h +++ b/chrome/browser/media_galleries/fileapi/iapps_finder.h @@ -13,22 +13,17 @@ namespace iapps { typedef base::Callback<void(const std::string&)> IAppsFinderCallback; -// These methods look for the iTunes/iPhoto library in in an asynchronous +// These methods look for the iTunes library in in an asynchronous // manner and call |callback| on the UI thread as soon as the result is known. // If a library exists, |callback| gets the device id for the library. If a -// library does not exist, or the OS does not support iTunes/iPhoto, then -// |callback| gets an empty string. - -void FindIPhotoLibrary(const IAppsFinderCallback& callback); +// library does not exist, or the OS does not support iTunes, then |callback| +// gets an empty string. void FindITunesLibrary(const IAppsFinderCallback& callback); // These methods returns true if |path| should be interpreted as the device // indicated by |device_id|. -bool PathIndicatesIPhotoLibrary(const std::string& device_id, - const base::FilePath& path); - bool PathIndicatesITunesLibrary(const std::string& device_id, const base::FilePath& path); diff --git a/chrome/browser/media_galleries/fileapi/iapps_finder_impl.cc b/chrome/browser/media_galleries/fileapi/iapps_finder_impl.cc index e9c1f0fa..ac8357f 100644 --- a/chrome/browser/media_galleries/fileapi/iapps_finder_impl.cc +++ b/chrome/browser/media_galleries/fileapi/iapps_finder_impl.cc @@ -41,13 +41,6 @@ void FindIAppsOnFileThread(storage_monitor::StorageInfo::Type type, base::Bind(task, base::Bind(PostResultToUIThread, type, callback))); } -// iPhoto is only supported on OSX. -#if !defined(OS_MACOSX) -void FindIPhotoLibrary(const IAppsFinderCallback& callback) { - callback.Run(std::string()); -} -#endif // !defined(OS_MACOSX) - // iTunes is only support on OSX and Windows. #if !defined(OS_MACOSX) && !defined(OS_WIN) void FindITunesLibrary(const IAppsFinderCallback& callback) { @@ -55,24 +48,6 @@ void FindITunesLibrary(const IAppsFinderCallback& callback) { } #endif -bool PathIndicatesIPhotoLibrary(const std::string& device_id, - const base::FilePath& path) { - storage_monitor::StorageInfo::Type device_type; - std::string unique_id; - storage_monitor::StorageInfo::CrackDeviceId( - device_id, &device_type, &unique_id); - if (device_type != storage_monitor::StorageInfo::IPHOTO) - return false; - - // |unique_id| is the path to the library XML file at the library root. - base::FilePath library_root = - base::FilePath::FromUTF8Unsafe(unique_id).DirName(); - return (path == library_root) || - (path == library_root.AppendASCII("Data")) || - (path == library_root.AppendASCII("Originals")) || - (path == library_root.AppendASCII("Masters")); -} - bool PathIndicatesITunesLibrary(const std::string& device_id, const base::FilePath& path) { storage_monitor::StorageInfo::Type device_type; diff --git a/chrome/browser/media_galleries/fileapi/iapps_finder_impl.h b/chrome/browser/media_galleries/fileapi/iapps_finder_impl.h index 82c8424..409cc52 100644 --- a/chrome/browser/media_galleries/fileapi/iapps_finder_impl.h +++ b/chrome/browser/media_galleries/fileapi/iapps_finder_impl.h @@ -30,7 +30,6 @@ namespace iapps { #if defined(OS_MACOSX) -extern NSString* const kIPhotoRecentDatabasesKey; extern NSString* const kITunesRecentDatabasePathsKey; // Set the mac preferences to use for testing. The caller continues to own diff --git a/chrome/browser/media_galleries/fileapi/iapps_finder_impl_mac.mm b/chrome/browser/media_galleries/fileapi/iapps_finder_impl_mac.mm index 93960af..3140864 100644 --- a/chrome/browser/media_galleries/fileapi/iapps_finder_impl_mac.mm +++ b/chrome/browser/media_galleries/fileapi/iapps_finder_impl_mac.mm @@ -72,15 +72,6 @@ void FindMostRecentDatabase( callback.Run(most_recent_db_path.value()); } -base::FilePath ExtractIPhotoPath(NSString* path_ns) { - NSURL* url = [NSURL URLWithString:path_ns]; - if (![url isFileURL]) - return base::FilePath(); - - NSString* expanded_path_ns = [url path]; - return base::mac::NSStringToFilePath(expanded_path_ns); -} - base::FilePath ExtractITunesPath(NSString* path_ns) { NSString* expanded_path_ns = [path_ns stringByExpandingTildeInPath]; return base::mac::NSStringToFilePath(expanded_path_ns); @@ -88,18 +79,8 @@ base::FilePath ExtractITunesPath(NSString* path_ns) { } // namespace -NSString* const kIPhotoRecentDatabasesKey = @"iPhotoRecentDatabases"; NSString* const kITunesRecentDatabasePathsKey = @"iTunesRecentDatabasePaths"; -void FindIPhotoLibrary(const IAppsFinderCallback& callback) { - FindIAppsOnFileThread( - storage_monitor::StorageInfo::IPHOTO, - base::Bind(&FindMostRecentDatabase, - base::scoped_nsobject<NSString>(kIPhotoRecentDatabasesKey), - base::Bind(&ExtractIPhotoPath)), - callback); -} - void FindITunesLibrary(const IAppsFinderCallback& callback) { FindIAppsOnFileThread( storage_monitor::StorageInfo::ITUNES, diff --git a/chrome/browser/media_galleries/fileapi/iphoto_data_provider.cc b/chrome/browser/media_galleries/fileapi/iphoto_data_provider.cc deleted file mode 100644 index 9d7372b..0000000 --- a/chrome/browser/media_galleries/fileapi/iphoto_data_provider.cc +++ /dev/null @@ -1,187 +0,0 @@ -// 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/iphoto_data_provider.h" - -#include <stdint.h> - -#include <map> - -#include "base/bind.h" -#include "base/callback.h" -#include "base/location.h" -#include "base/logging.h" -#include "base/stl_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/threading/thread_restrictions.h" -#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" -#include "chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h" - -namespace iphoto { - -IPhotoDataProvider::IPhotoDataProvider(const base::FilePath& library_path) - : iapps::IAppsDataProvider(library_path), - weak_factory_(this) {} - -IPhotoDataProvider::~IPhotoDataProvider() {} - -void IPhotoDataProvider::DoParseLibrary( - const base::FilePath& library_path, - const ReadyCallback& ready_callback) { - xml_parser_ = new iapps::SafeIAppsLibraryParser; - xml_parser_->ParseIPhotoLibrary( - library_path, - base::Bind(&IPhotoDataProvider::OnLibraryParsed, - weak_factory_.GetWeakPtr(), - ready_callback)); -} - -void IPhotoDataProvider::OnLibraryParsed(const ReadyCallback& ready_callback, - bool result, - const parser::Library& library) { - DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); - set_valid(result); - if (valid()) - BuildIndices(library); - ready_callback.Run(valid()); -} - -void IPhotoDataProvider::BuildIndices(const parser::Library& library) { - typedef base::hash_map<uint64_t, const base::FilePath*> IdIndex; - - IdIndex photo_id_index; - IdIndex originals_id_index; - for (std::set<parser::Photo>::const_iterator photo_it = - library.all_photos.begin(); - photo_it != library.all_photos.end(); photo_it++) { - photo_id_index[photo_it->id] = &(photo_it->location); - if (!photo_it->original_location.empty()) - originals_id_index[photo_it->id] = &(photo_it->original_location); - } - - // Build up a set of IDs which have in-album duplicates. - // Those are the filenames we want to globally mangle. - std::set<uint64_t> dupe_ids; - for (parser::Albums::const_iterator album_it = library.albums.begin(); - album_it != library.albums.end(); album_it++) { - const parser::Album& album = album_it->second; - - std::set<std::string> album_paths; - for (parser::Album::const_iterator id_it = album.begin(); - id_it != album.end(); id_it++) { - uint64_t id = *id_it; - IdIndex::const_iterator photo_it = photo_id_index.find(id); - if (photo_it == photo_id_index.end()) - continue; - - std::string filename = photo_it->second->BaseName().value(); - if (ContainsKey(album_paths, filename)) - dupe_ids.insert(id); - else - album_paths.insert(filename); - } - } - - // Now build the directory index. - dir_index_.clear(); - originals_index_.clear(); - for (parser::Albums::const_iterator album_it = library.albums.begin(); - album_it != library.albums.end(); album_it++) { - std::string album_name = album_it->first; - const parser::Album& album = album_it->second; - - for (parser::Album::const_iterator id_it = album.begin(); - id_it != album.end(); id_it++) { - uint64_t id = *id_it; - IdIndex::const_iterator photo_it = photo_id_index.find(id); - if (photo_it == photo_id_index.end()) - continue; - base::FilePath path = *(photo_it->second); - - std::string filename = path.BaseName().value(); - if (ContainsKey(dupe_ids, id)) { - filename = path.BaseName().InsertBeforeExtension( - "(" + base::Uint64ToString(id) + ")").value(); - } - - dir_index_[album_name][filename] = path; - - IdIndex::const_iterator original_it = originals_id_index.find(id); - if (original_it != originals_id_index.end()) - originals_index_[album_name][filename] = *(original_it->second); - } - } -} - -std::vector<std::string> IPhotoDataProvider::GetAlbumNames() const { - std::vector<std::string> names; - - for (DirIndex::const_iterator dir_it = dir_index_.begin(); - dir_it != dir_index_.end(); dir_it++) { - names.push_back(dir_it->first); - } - - return names; -} - -std::map<std::string, base::FilePath> IPhotoDataProvider::GetAlbumContents( - const std::string& album) const { - std::map<std::string, base::FilePath> locations; - DirIndex::const_iterator dir_it = dir_index_.find(album); - if (dir_it == dir_index_.end()) - return locations; - - for (FileIndex::const_iterator file_it = dir_it->second.begin(); - file_it != dir_it->second.end(); file_it++) { - locations.insert(make_pair(file_it->first, file_it->second)); - } - - return locations; -} - -base::FilePath IPhotoDataProvider::GetPhotoLocationInAlbum( - const std::string& album, - const std::string& filename) const { - DirIndex::const_iterator dir_it = dir_index_.find(album); - if (dir_it == dir_index_.end()) - return base::FilePath(); - FileIndex::const_iterator file_it = dir_it->second.find(filename); - if (file_it == dir_it->second.end()) - return base::FilePath(); - return file_it->second; -} - -bool IPhotoDataProvider::HasOriginals(const std::string& album) const { - DirIndex::const_iterator originals_it = originals_index_.find(album); - return originals_it != originals_index_.end(); -} - -std::map<std::string, base::FilePath> IPhotoDataProvider::GetOriginals( - const std::string& album) const { - std::map<std::string, base::FilePath> locations; - DirIndex::const_iterator originals_it = originals_index_.find(album); - if (originals_it == originals_index_.end()) - return locations; - - for (FileIndex::const_iterator file_it = originals_it->second.begin(); - file_it != originals_it->second.end(); file_it++) { - locations.insert(make_pair(file_it->first, file_it->second)); - } - - return locations; -} - -base::FilePath IPhotoDataProvider::GetOriginalPhotoLocation( - const std::string& album, - const std::string& filename) const { - DirIndex::const_iterator originals_it = originals_index_.find(album); - if (originals_it == originals_index_.end()) - return base::FilePath(); - FileIndex::const_iterator file_it = originals_it->second.find(filename); - if (file_it == originals_it->second.end()) - return base::FilePath(); - return file_it->second; -} - -} // namespace iphoto diff --git a/chrome/browser/media_galleries/fileapi/iphoto_data_provider.h b/chrome/browser/media_galleries/fileapi/iphoto_data_provider.h deleted file mode 100644 index 6266012..0000000 --- a/chrome/browser/media_galleries/fileapi/iphoto_data_provider.h +++ /dev/null @@ -1,77 +0,0 @@ -// 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. - -#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_DATA_PROVIDER_H_ -#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_DATA_PROVIDER_H_ - -#include <map> -#include <set> -#include <string> - -#include "base/callback_forward.h" -#include "base/containers/hash_tables.h" -#include "base/files/file_path.h" -#include "base/files/file_path_watcher.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "chrome/browser/media_galleries/fileapi/iapps_data_provider.h" -#include "chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h" -#include "chrome/common/media_galleries/iphoto_library.h" - -namespace iphoto { - -// This class is the holder for iPhoto parsed data. Given a path to the iPhoto -// library XML file it will read it in, parse the data, and provide convenient -// methods to access it. When the file changes, it will update the data. -// It is not thread safe, but can be run on any thread with IO access. -class IPhotoDataProvider : public iapps::IAppsDataProvider { - public: - explicit IPhotoDataProvider(const base::FilePath& library_path); - ~IPhotoDataProvider() override; - - // Parse the library xml file. - void DoParseLibrary(const base::FilePath& library_path, - const ReadyCallback& ready_callback) override; - - virtual std::vector<std::string> GetAlbumNames() const; - virtual std::map<std::string, base::FilePath> GetAlbumContents( - const std::string& album) const; - virtual base::FilePath GetPhotoLocationInAlbum( - const std::string& album, - const std::string& filename) const; - - virtual bool HasOriginals(const std::string& album) const; - virtual std::map<std::string, base::FilePath> GetOriginals( - const std::string& album) const; - virtual base::FilePath GetOriginalPhotoLocation( - const std::string& album, - const std::string& filename) const; - - private: - typedef base::hash_map<std::string, base::FilePath> FileIndex; - // Map from album name to a map of filename to path. - typedef std::map<std::string, FileIndex> DirIndex; - - void OnLibraryParsed(const ReadyCallback& ready_callback, - bool result, - const parser::Library& library); - - void BuildIndices(const parser::Library& library); - - // Index for library data as it is presented in the virtual FS. - DirIndex dir_index_; - - // Index for originals data. - DirIndex originals_index_; - - scoped_refptr<iapps::SafeIAppsLibraryParser> xml_parser_; - - base::WeakPtrFactory<IPhotoDataProvider> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(IPhotoDataProvider); -}; - -} // namespace iphoto - -#endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_DATA_PROVIDER_H_ diff --git a/chrome/browser/media_galleries/fileapi/iphoto_data_provider_browsertest.cc b/chrome/browser/media_galleries/fileapi/iphoto_data_provider_browsertest.cc deleted file mode 100644 index 99d2d9b..0000000 --- a/chrome/browser/media_galleries/fileapi/iphoto_data_provider_browsertest.cc +++ /dev/null @@ -1,474 +0,0 @@ -// 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 <string> -#include <vector> - -#include "base/bind.h" -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/format_macros.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "base/message_loop/message_loop.h" -#include "base/run_loop.h" -#include "base/stl_util.h" -#include "base/strings/stringprintf.h" -#include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" -#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" -#include "chrome/browser/media_galleries/imported_media_gallery_registry.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "content/public/browser/browser_thread.h" -#include "url/gurl.h" - -using base::FilePath; - -namespace iphoto { - -class TestIPhotoDataProvider : public IPhotoDataProvider { - public: - TestIPhotoDataProvider(const base::FilePath& xml_library_path, - const base::Closure& callback) - : IPhotoDataProvider(xml_library_path), - callback_(callback) { - } - ~TestIPhotoDataProvider() override {} - - private: - void OnLibraryChanged(const base::FilePath& path, bool error) override { - IPhotoDataProvider::OnLibraryChanged(path, error); - callback_.Run(); - } - - base::Closure callback_; - - DISALLOW_COPY_AND_ASSIGN(TestIPhotoDataProvider); -}; - -class IPhotoDataProviderTest : public InProcessBrowserTest { - public: - IPhotoDataProviderTest() {} - - protected: - void SetUp() override { - ASSERT_TRUE(library_dir_.CreateUniqueTempDir()); - WriteLibraryInternal(); - // The ImportedMediaGalleryRegistry is created on which ever thread calls - // GetInstance() first. It shouldn't matter what thread creates, however - // in practice it is always created on the UI thread, so this calls - // GetInstance here to mirror those real conditions. - ImportedMediaGalleryRegistry::GetInstance(); - InProcessBrowserTest::SetUp(); - } - - void RunTest() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - base::RunLoop loop; - quit_closure_ = loop.QuitClosure(); - MediaFileSystemBackend::MediaTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&IPhotoDataProviderTest::StartTestOnMediaTaskRunner, - base::Unretained(this))); - loop.Run(); - } - - void WriteLibrary(const base::Closure& callback) { - SetLibraryChangeCallback(callback); - WriteLibraryInternal(); - } - - void SetLibraryChangeCallback(const base::Closure& callback) { - EXPECT_TRUE(library_changed_callback_.is_null()); - library_changed_callback_ = callback; - } - - IPhotoDataProvider* data_provider() const { - return ImportedMediaGalleryRegistry::IPhotoDataProvider(); - } - - const base::FilePath& library_dir() const { - return library_dir_.path(); - } - - base::FilePath XmlFile() const { - return library_dir_.path().AppendASCII("library.xml"); - } - - // Start the test. The data provider is refreshed before calling StartTest - // and the result of the refresh is passed in. - virtual void StartTest(bool parse_success) = 0; - - void TestDone() { - DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); - ImportedMediaGalleryRegistry* imported_registry = - ImportedMediaGalleryRegistry::GetInstance(); - imported_registry->iphoto_data_provider_.reset(); - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, - quit_closure_); - } - - // Override to provide a full library string. - virtual std::string GetLibraryString() { - return "<plist><dict>\n</dict></plist>\n"; - } - - private: - void StartTestOnMediaTaskRunner() { - DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); - ImportedMediaGalleryRegistry* imported_registry = - ImportedMediaGalleryRegistry::GetInstance(); - imported_registry->iphoto_data_provider_.reset( - new TestIPhotoDataProvider( - XmlFile(), - base::Bind(&IPhotoDataProviderTest::OnLibraryChanged, - base::Unretained(this)))); - data_provider()->RefreshData(base::Bind(&IPhotoDataProviderTest::StartTest, - base::Unretained(this))); - }; - - void OnLibraryChanged() { - DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); - if (!library_changed_callback_.is_null()) { - library_changed_callback_.Run(); - library_changed_callback_.Reset(); - } - } - - void WriteLibraryInternal() { - std::string xml = GetLibraryString(); - ASSERT_EQ(static_cast<int>(xml.size()), - base::WriteFile(XmlFile(), xml.c_str(), xml.size())); - } - - base::ScopedTempDir library_dir_; - - base::Closure library_changed_callback_; - - base::Closure quit_closure_; - - DISALLOW_COPY_AND_ASSIGN(IPhotoDataProviderTest); -}; - -class IPhotoDataProviderBasicTest : public IPhotoDataProviderTest { - public: - IPhotoDataProviderBasicTest() {} - - std::string GetLibraryString() override { - return "<plist><dict>\n" - "<key>List of Albums</key>\n" - "<array>" - " <dict>\n" - " <key>AlbumId</key>" - " <integer>14</integer>" - " <key>AlbumName</key>" - " <string>Album1</string>" - " <key>KeyList</key>" - " <array>" - " <string>1</string>" - " <string>3</string>" // [3] and [4] are name dupes - " <string>4</string>" - " </array>" - " </dict>\n" - " <dict>\n" - " <key>AlbumId</key>" - " <integer>15</integer>" - " <key>AlbumName</key>" - " <string>Album2</string>" - " <key>KeyList</key>" - " <array>" - " <string>2</string>" - " </array>" - " </dict>\n" - " <dict>\n" - " <key>AlbumId</key>" - " <integer>16</integer>" - " <key>AlbumName</key>" - " <string>Album5</string>" - " <key>KeyList</key>" - " <array>" - " <string>5</string>" // A name dupe of [2], but in another album. - " </array>" - " </dict>\n" - "</array>\n" - "<key>Master Image List</key>\n" - "<dict>\n" - " <key>1</key>\n" - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption</key>" - " <string>caption</string>" - " <key>GUID</key>\n" - " <string>guid1</string>" - " <key>ImagePath</key>" - " <string>/vol/path1.jpg</string>" - " <key>ThumbPath</key>" - " <string>/vol/thumb1.jpg</string>" - " </dict>\n" - " <key>2</key>\n" - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption</key>" - " <string>caption2</string>" - " <key>GUID</key>\n" - " <string>guid2</string>" - " <key>ImagePath</key>" - " <string>/vol/path2.jpg</string>" - " <key>ThumbPath</key>" - " <string>/vol/thumb2.jpg</string>" - " </dict>\n" - " <key>3</key>\n" - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption</key>" - " <string>caption3</string>" - " <key>GUID</key>\n" - " <string>guid3</string>" - " <key>ImagePath</key>" - " <string>/vol/path3.jpg</string>" - " <key>ThumbPath</key>" - " <string>/vol/thumb3.jpg</string>" - " </dict>\n" - " <key>4</key>\n" // A name duplicate of [3] in another path. - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption</key>" - " <string>caption</string>" - " <key>GUID</key>\n" - " <string>guid3</string>" - " <key>ImagePath</key>" - " <string>/vol/dupe/path3.jpg</string>" - " <key>ThumbPath</key>" - " <string>/vol/dupe/thumb3.jpg</string>" - " </dict>\n" - " <key>5</key>\n" // A name duplicate of [2] in another path. - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption</key>" - " <string>caption5</string>" - " <key>GUID</key>\n" - " <string>guid2</string>" - " <key>ImagePath</key>" - " <string>/vol/dupe/path2.jpg</string>" - " <key>ThumbPath</key>" - " <string>/vol/dupe/thumb2.jpg</string>" - " <key>OriginalPath</key>" \ - " <string>/original/vol/another2.jpg</string>" \ - " </dict>\n" - "</dict>\n" - "</dict></plist>\n"; - } - - void StartTest(bool parse_success) override { - EXPECT_TRUE(parse_success); - - std::vector<std::string> names = data_provider()->GetAlbumNames(); - EXPECT_EQ(3U, names.size()); - EXPECT_EQ("Album1", names[0]); - - EXPECT_EQ(FilePath("/vol/path1.jpg").value(), - data_provider()->GetPhotoLocationInAlbum( - "Album1", "path1.jpg").value()); - EXPECT_EQ(FilePath("/vol/path3.jpg").value(), - data_provider()->GetPhotoLocationInAlbum( - "Album1", "path3.jpg").value()); - EXPECT_EQ(FilePath("/vol/dupe/path3.jpg").value(), - data_provider()->GetPhotoLocationInAlbum( - "Album1", "path3(4).jpg").value()); - EXPECT_EQ(FilePath().value(), - data_provider()->GetPhotoLocationInAlbum( - "Album1", "path5.jpg").value()); - - // path2.jpg is name-duped, but in different albums, and so should not - // be mangled. - EXPECT_EQ(FilePath("/vol/dupe/path2.jpg").value(), - data_provider()->GetPhotoLocationInAlbum( - "Album5", "path2.jpg").value()); - EXPECT_EQ(FilePath("/vol/path2.jpg").value(), - data_provider()->GetPhotoLocationInAlbum( - "Album2", "path2.jpg").value()); - - std::map<std::string, base::FilePath> photos = - data_provider()->GetAlbumContents("nonexistent"); - EXPECT_EQ(0U, photos.size()); - photos = data_provider()->GetAlbumContents("Album1"); - EXPECT_EQ(3U, photos.size()); - EXPECT_TRUE(ContainsKey(photos, "path1.jpg")); - EXPECT_FALSE(ContainsKey(photos, "path2.jpg")); - EXPECT_TRUE(ContainsKey(photos, "path3.jpg")); - EXPECT_TRUE(ContainsKey(photos, "path3(4).jpg")); - EXPECT_EQ(FilePath("/vol/path1.jpg").value(), photos["path1.jpg"].value()); - EXPECT_EQ(FilePath("/vol/path3.jpg").value(), - photos["path3.jpg"].value()); - EXPECT_EQ(FilePath("/vol/dupe/path3.jpg").value(), - photos["path3(4).jpg"].value()); - - photos = data_provider()->GetAlbumContents("Album2"); - EXPECT_EQ(1U, photos.size()); - EXPECT_TRUE(ContainsKey(photos, "path2.jpg")); - - EXPECT_FALSE(data_provider()->HasOriginals("Album1")); - EXPECT_TRUE(data_provider()->HasOriginals("Album5")); - std::map<std::string, base::FilePath> originals = - data_provider()->GetOriginals("Album1"); - EXPECT_EQ(0U, originals.size()); - originals = data_provider()->GetOriginals("Album5"); - EXPECT_EQ(1U, originals.size()); - EXPECT_TRUE(ContainsKey(originals, "path2.jpg")); - EXPECT_FALSE(ContainsKey(originals, "path1.jpg")); - EXPECT_EQ(FilePath("/original/vol/another2.jpg").value(), - originals["path2.jpg"].value()); - base::FilePath original_path = - data_provider()->GetOriginalPhotoLocation("Album5", "path2.jpg"); - EXPECT_EQ(FilePath("/original/vol/another2.jpg").value(), - original_path.value()); - - TestDone(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(IPhotoDataProviderBasicTest); -}; - -class IPhotoDataProviderRefreshTest : public IPhotoDataProviderTest { - public: - IPhotoDataProviderRefreshTest() {} - - std::string another_album; - - std::string GetLibraryString() override { - return "<plist><dict>\n" - "<key>List of Albums</key>\n" - "<array>" - " <dict>" - " <key>AlbumId</key>" - " <integer>14</integer>" - " <key>AlbumName</key>" - " <string>Album1</string>" - " <key>KeyList</key>" - " <array>" - " <string>1</string>" - " </array>" - " </dict>\n" + - another_album + - "</array>\n" - "<key>Master Image List</key>\n" - "<dict>\n" - " <key>1</key>\n" - " <dict>\n" - " <key>MediaType</key>" - " <string>Image</string>" - " <key>Caption1</key>" - " <string>caption</string>" - " <key>GUID</key>\n" - " <string>guid1</string>" - " <key>ImagePath</key>" - " <string>/vol/path1.jpg</string>" - " <key>ThumbPath</key>" - " <string>/vol/thumb1.jpg</string>" - " </dict>\n" - "</dict>\n" - "</dict></plist>\n"; - } - - void StartTest(bool parse_success) override { - EXPECT_TRUE(parse_success); - - EXPECT_EQ(FilePath("/vol/path1.jpg"), - data_provider()->GetPhotoLocationInAlbum("Album1", "path1.jpg")); - std::vector<std::string> names = data_provider()->GetAlbumNames(); - EXPECT_EQ(1U, names.size()); - EXPECT_EQ("Album1", names[0]); - - another_album = - " <dict>" - " <key>AlbumId</key>" - " <integer>14</integer>" - " <key>AlbumName</key>" - " <string>Another Album</string>" - " <key>KeyList</key>" - " <array>" - " <string>1</string>" - " </array>" - " </dict>\n"; - - WriteLibrary(base::Bind(&IPhotoDataProviderRefreshTest::CheckAfterWrite, - base::Unretained(this))); - } - - void CheckAfterWrite() { - // No change -- data has not been parsed. - EXPECT_EQ(FilePath("/vol/path1.jpg"), - data_provider()->GetPhotoLocationInAlbum("Album1", "path1.jpg")); - std::vector<std::string> names = data_provider()->GetAlbumNames(); - EXPECT_EQ(1U, names.size()); - EXPECT_EQ("Album1", names[0]); - - data_provider()->RefreshData( - base::Bind(&IPhotoDataProviderRefreshTest::CheckRefresh, - base::Unretained(this))); - } - - void CheckRefresh(bool is_valid) { - EXPECT_TRUE(is_valid); - - EXPECT_EQ(FilePath("/vol/path1.jpg"), - data_provider()->GetPhotoLocationInAlbum("Album1", "path1.jpg")); - std::vector<std::string> names = data_provider()->GetAlbumNames(); - EXPECT_EQ(2U, names.size()); - if (names.size() == 2U) { - EXPECT_EQ("Album1", names[0]); - EXPECT_EQ("Another Album", names[1]); - } - - TestDone(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(IPhotoDataProviderRefreshTest); -}; - -class IPhotoDataProviderInvalidTest : public IPhotoDataProviderTest { - public: - IPhotoDataProviderInvalidTest() {} - - void StartTest(bool parse_success) override { - EXPECT_TRUE(parse_success); - - SetLibraryChangeCallback( - base::Bind(&IPhotoDataProvider::RefreshData, - base::Unretained(data_provider()), - base::Bind(&IPhotoDataProviderInvalidTest::CheckInvalid, - base::Unretained(this)))); - EXPECT_EQ(1L, base::WriteFile(XmlFile(), " ", 1)); - } - - void CheckInvalid(bool is_valid) { - EXPECT_FALSE(is_valid); - TestDone(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(IPhotoDataProviderInvalidTest); -}; - -IN_PROC_BROWSER_TEST_F(IPhotoDataProviderBasicTest, BasicTest) { - RunTest(); -} - -IN_PROC_BROWSER_TEST_F(IPhotoDataProviderRefreshTest, RefreshTest) { - RunTest(); -} - -IN_PROC_BROWSER_TEST_F(IPhotoDataProviderInvalidTest, InvalidTest) { - RunTest(); -} - -} // namespace iphoto diff --git a/chrome/browser/media_galleries/fileapi/iphoto_file_util.cc b/chrome/browser/media_galleries/fileapi/iphoto_file_util.cc deleted file mode 100644 index 1f58e3d..0000000 --- a/chrome/browser/media_galleries/fileapi/iphoto_file_util.cc +++ /dev/null @@ -1,355 +0,0 @@ -// 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/iphoto_file_util.h" - -#include <set> -#include <string> -#include <utility> -#include <vector> - -#include "base/bind_helpers.h" -#include "base/files/file_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" -#include "chrome/browser/media_galleries/fileapi/media_path_filter.h" -#include "chrome/browser/media_galleries/imported_media_gallery_registry.h" -#include "content/public/browser/browser_thread.h" -#include "storage/browser/blob/shareable_file_reference.h" -#include "storage/browser/fileapi/file_system_operation_context.h" -#include "storage/browser/fileapi/file_system_url.h" -#include "storage/browser/fileapi/native_file_util.h" -#include "storage/common/fileapi/directory_entry.h" -#include "storage/common/fileapi/file_system_util.h" - -using storage::DirectoryEntry; - -namespace iphoto { - -namespace { - -base::File::Error MakeDirectoryFileInfo(base::File::Info* file_info) { - base::File::Info result; - result.is_directory = true; - *file_info = result; - return base::File::FILE_OK; -} - -template <typename T> -bool ContainsElement(const std::vector<T>& collection, const T& key) { - typename std::vector<T>::const_iterator it = collection.begin(); - while (it != collection.end()) { - if (*it == key) - return true; - it++; - } - return false; -} - -std::vector<std::string> GetVirtualPathComponents( - const storage::FileSystemURL& url) { - ImportedMediaGalleryRegistry* imported_registry = - ImportedMediaGalleryRegistry::GetInstance(); - base::FilePath root = imported_registry->ImportedRoot().AppendASCII("iphoto"); - - DCHECK(root.IsParent(url.path()) || root == url.path()); - base::FilePath virtual_path; - root.AppendRelativePath(url.path(), &virtual_path); - - std::vector<std::string> result; - storage::VirtualPath::GetComponentsUTF8Unsafe(virtual_path, &result); - return result; -} - -} // namespace - -const char kIPhotoAlbumsDir[] = "Albums"; -const char kIPhotoOriginalsDir[] = "Originals"; - -IPhotoFileUtil::IPhotoFileUtil(MediaPathFilter* media_path_filter) - : NativeMediaFileUtil(media_path_filter), - imported_registry_(NULL), - weak_factory_(this) { -} - -IPhotoFileUtil::~IPhotoFileUtil() { -} - -void IPhotoFileUtil::GetFileInfoOnTaskRunnerThread( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const GetFileInfoCallback& callback) { - IPhotoDataProvider* data_provider = GetDataProvider(); - // |data_provider| may be NULL if the file system was revoked before this - // operation had a chance to run. - if (!data_provider) { - GetFileInfoWithFreshDataProvider(std::move(context), url, callback, false); - } else { - data_provider->RefreshData( - base::Bind(&IPhotoFileUtil::GetFileInfoWithFreshDataProvider, - weak_factory_.GetWeakPtr(), base::Passed(&context), url, - callback)); - } -} - -void IPhotoFileUtil::ReadDirectoryOnTaskRunnerThread( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const ReadDirectoryCallback& callback) { - IPhotoDataProvider* data_provider = GetDataProvider(); - // |data_provider| may be NULL if the file system was revoked before this - // operation had a chance to run. - if (!data_provider) { - ReadDirectoryWithFreshDataProvider(std::move(context), url, callback, - false); - } else { - data_provider->RefreshData( - base::Bind(&IPhotoFileUtil::ReadDirectoryWithFreshDataProvider, - weak_factory_.GetWeakPtr(), base::Passed(&context), url, - callback)); - } -} - -void IPhotoFileUtil::CreateSnapshotFileOnTaskRunnerThread( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const CreateSnapshotFileCallback& callback) { - IPhotoDataProvider* data_provider = GetDataProvider(); - // |data_provider| may be NULL if the file system was revoked before this - // operation had a chance to run. - if (!data_provider) { - CreateSnapshotFileWithFreshDataProvider(std::move(context), url, callback, - false); - } else { - data_provider->RefreshData( - base::Bind(&IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider, - weak_factory_.GetWeakPtr(), base::Passed(&context), url, - callback)); - } -} - -void IPhotoFileUtil::GetFileInfoWithFreshDataProvider( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const GetFileInfoCallback& callback, - bool valid_parse) { - if (!valid_parse) { - if (!callback.is_null()) { - content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind(callback, base::File::FILE_ERROR_IO, base::File::Info())); - } - return; - } - NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(std::move(context), url, - callback); -} - -void IPhotoFileUtil::ReadDirectoryWithFreshDataProvider( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const ReadDirectoryCallback& callback, - bool valid_parse) { - if (!valid_parse) { - if (!callback.is_null()) { - content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind(callback, base::File::FILE_ERROR_IO, EntryList(), false)); - } - return; - } - NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(std::move(context), url, - callback); -} - -void IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const CreateSnapshotFileCallback& callback, - bool valid_parse) { - if (!valid_parse) { - if (!callback.is_null()) { - base::File::Info file_info; - base::FilePath platform_path; - scoped_refptr<storage::ShareableFileReference> file_ref; - content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind(callback, base::File::FILE_ERROR_IO, file_info, - platform_path, file_ref)); - } - return; - } - NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(std::move(context), - url, callback); -} - -// Begin actual implementation. - -base::File::Error IPhotoFileUtil::GetFileInfoSync( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url, - base::File::Info* file_info, - base::FilePath* platform_path) { - std::vector<std::string> components = GetVirtualPathComponents(url); - - if (components.size() == 0) { - return MakeDirectoryFileInfo(file_info); - } - - // The 'Albums' directory. - if (components[0] == kIPhotoAlbumsDir) { - if (components.size() == 1) { - return MakeDirectoryFileInfo(file_info); - } else if (components.size() == 2) { - std::vector<std::string> albums = - GetDataProvider()->GetAlbumNames(); - if (ContainsElement(albums, components[1])) - return MakeDirectoryFileInfo(file_info); - } else if (components.size() == 3) { - if (components[2] == kIPhotoOriginalsDir) { - if (GetDataProvider()->HasOriginals(components[1])) - return MakeDirectoryFileInfo(file_info); - else - return base::File::FILE_ERROR_NOT_FOUND; - } - - base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( - components[1], components[2]); - if (!location.empty()) { - return NativeMediaFileUtil::GetFileInfoSync( - context, url, file_info, platform_path); - } - } else if (components.size() == 4 && - GetDataProvider()->HasOriginals(components[1]) && - components[2] == kIPhotoOriginalsDir) { - base::FilePath location = GetDataProvider()->GetOriginalPhotoLocation( - components[1], components[3]); - if (!location.empty()) { - return NativeMediaFileUtil::GetFileInfoSync( - context, url, file_info, platform_path); - } - } - } - - return base::File::FILE_ERROR_NOT_FOUND; -} - -base::File::Error IPhotoFileUtil::ReadDirectorySync( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url, - EntryList* file_list) { - DCHECK(file_list->empty()); - std::vector<std::string> components = GetVirtualPathComponents(url); - - // Root directory. Child is the /Albums dir. - if (components.size() == 0) { - file_list->push_back( - DirectoryEntry(kIPhotoAlbumsDir, DirectoryEntry::DIRECTORY)); - return base::File::FILE_OK; - } - - if (components[0] == kIPhotoAlbumsDir) { - if (components.size() == 1) { - // Albums dir contains all album names. - std::vector<std::string> albums = - GetDataProvider()->GetAlbumNames(); - for (std::vector<std::string>::const_iterator it = albums.begin(); - it != albums.end(); it++) { - file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY)); - } - return base::File::FILE_OK; - } else if (components.size() == 2) { - std::vector<std::string> albums = - GetDataProvider()->GetAlbumNames(); - if (!ContainsElement(albums, components[1])) - return base::File::FILE_ERROR_NOT_FOUND; - - // Album dirs contain all photos in them. - if (GetDataProvider()->HasOriginals(components[1])) { - file_list->push_back( - DirectoryEntry(kIPhotoOriginalsDir, DirectoryEntry::DIRECTORY)); - } - std::map<std::string, base::FilePath> locations = - GetDataProvider()->GetAlbumContents(components[1]); - for (std::map<std::string, base::FilePath>::const_iterator it = - locations.begin(); - it != locations.end(); it++) { - base::File::Info info; - if (!base::GetFileInfo(it->second, &info)) - return base::File::FILE_ERROR_IO; - file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE)); - } - return base::File::FILE_OK; - } else if (components.size() == 3 && - components[2] == kIPhotoOriginalsDir && - GetDataProvider()->HasOriginals(components[1])) { - std::map<std::string, base::FilePath> originals = - GetDataProvider()->GetOriginals(components[1]); - for (std::map<std::string, base::FilePath>::const_iterator it = - originals.begin(); - it != originals.end(); it++) { - base::File::Info info; - if (!base::GetFileInfo(it->second, &info)) - return base::File::FILE_ERROR_IO; - file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE)); - } - return base::File::FILE_OK; - } - } - - return base::File::FILE_ERROR_NOT_FOUND; -} - -base::File::Error IPhotoFileUtil::DeleteDirectorySync( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url) { - return base::File::FILE_ERROR_SECURITY; -} - -base::File::Error IPhotoFileUtil::DeleteFileSync( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url) { - return base::File::FILE_ERROR_SECURITY; -} - -base::File::Error IPhotoFileUtil::GetLocalFilePath( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url, - base::FilePath* local_file_path) { - std::vector<std::string> components = GetVirtualPathComponents(url); - - if (components.size() == 3 && components[0] == kIPhotoAlbumsDir) { - base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( - components[1], components[2]); - if (!location.empty()) { - *local_file_path = location; - return base::File::FILE_OK; - } - } - - if (components.size() == 4 && components[0] == kIPhotoAlbumsDir && - GetDataProvider()->HasOriginals(components[1]) && - components[2] == kIPhotoOriginalsDir) { - base::FilePath location = GetDataProvider()->GetOriginalPhotoLocation( - components[1], components[3]); - if (!location.empty()) { - *local_file_path = location; - return base::File::FILE_OK; - } - } - - return base::File::FILE_ERROR_NOT_FOUND; -} - -IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { - if (!imported_registry_) - imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); - return imported_registry_->IPhotoDataProvider(); -} - -} // namespace iphoto diff --git a/chrome/browser/media_galleries/fileapi/iphoto_file_util.h b/chrome/browser/media_galleries/fileapi/iphoto_file_util.h deleted file mode 100644 index db35156..0000000 --- a/chrome/browser/media_galleries/fileapi/iphoto_file_util.h +++ /dev/null @@ -1,99 +0,0 @@ -// 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. - -#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_FILE_UTIL_H_ -#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_FILE_UTIL_H_ - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" - -class ImportedMediaGalleryRegistry; - -namespace iphoto { - -class IPhotoDataProvider; - -// Presents a virtual file system containing iPhoto contents in the -// following organization: -// / = virtual root -// |- /Albums -// |- /AlbumName = An album entry by name. -// |- pic1.jpg = Entries for photos in the album. -// |- pic2.jpg -// |- /AnotherAlbum -// |- pic3.jpg -// |- /originals = A directory for originals. -// |- pic3.jpg = Original picture. Same name as album photo. - -extern const char kIPhotoAlbumsDir[]; - -class IPhotoFileUtil : public NativeMediaFileUtil { - public: - explicit IPhotoFileUtil(MediaPathFilter* media_path_filter); - ~IPhotoFileUtil() override; - - protected: - // NativeMediaFileUtil overrides. - void GetFileInfoOnTaskRunnerThread( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const GetFileInfoCallback& callback) override; - void ReadDirectoryOnTaskRunnerThread( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const ReadDirectoryCallback& callback) override; - void CreateSnapshotFileOnTaskRunnerThread( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const CreateSnapshotFileCallback& callback) override; - base::File::Error GetFileInfoSync( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url, - base::File::Info* file_info, - base::FilePath* platform_path) override; - base::File::Error ReadDirectorySync( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url, - EntryList* file_list) override; - base::File::Error DeleteDirectorySync( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url) override; - base::File::Error DeleteFileSync(storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url) override; - base::File::Error GetLocalFilePath( - storage::FileSystemOperationContext* context, - const storage::FileSystemURL& url, - base::FilePath* local_file_path) override; - - private: - void GetFileInfoWithFreshDataProvider( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const GetFileInfoCallback& callback, - bool valid_parse); - void ReadDirectoryWithFreshDataProvider( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const ReadDirectoryCallback& callback, - bool valid_parse); - virtual void CreateSnapshotFileWithFreshDataProvider( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const CreateSnapshotFileCallback& callback, - bool valid_parse); - - virtual IPhotoDataProvider* GetDataProvider(); - - ImportedMediaGalleryRegistry* imported_registry_; - - base::WeakPtrFactory<IPhotoFileUtil> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(IPhotoFileUtil); -}; - -} // namespace iphoto - -#endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_FILE_UTIL_H_ diff --git a/chrome/browser/media_galleries/fileapi/iphoto_file_util_unittest.cc b/chrome/browser/media_galleries/fileapi/iphoto_file_util_unittest.cc deleted file mode 100644 index c912ef5..0000000 --- a/chrome/browser/media_galleries/fileapi/iphoto_file_util_unittest.cc +++ /dev/null @@ -1,353 +0,0 @@ -// 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/iphoto_file_util.h" - -#include <map> -#include <set> -#include <string> -#include <utility> -#include <vector> - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/files/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/macros.h" -#include "base/run_loop.h" -#include "base/single_thread_task_runner.h" -#include "base/synchronization/waitable_event.h" -#include "base/thread_task_runner_handle.h" -#include "base/time/time.h" -#include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" -#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" -#include "chrome/browser/media_galleries/fileapi/media_path_filter.h" -#include "chrome/browser/media_galleries/imported_media_gallery_registry.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/test/mock_special_storage_policy.h" -#include "content/public/test/test_browser_thread.h" -#include "content/public/test/test_file_system_options.h" -#include "storage/browser/fileapi/async_file_util.h" -#include "storage/browser/fileapi/external_mount_points.h" -#include "storage/browser/fileapi/file_system_context.h" -#include "storage/browser/fileapi/file_system_operation_context.h" -#include "storage/browser/fileapi/file_system_operation_runner.h" -#include "testing/gtest/include/gtest/gtest.h" - -using storage::FileSystemOperationContext; -using storage::FileSystemOperation; -using storage::FileSystemURL; - -namespace iphoto { - -namespace { - -void ReadDirectoryTestHelperCallback( - base::RunLoop* run_loop, - FileSystemOperation::FileEntryList* contents, - bool* completed, - base::File::Error error, - const FileSystemOperation::FileEntryList& file_list, - bool has_more) { - DCHECK(!*completed); - *completed = !has_more && error == base::File::FILE_OK; - *contents = file_list; - run_loop->Quit(); -} - -void ReadDirectoryTestHelper(storage::FileSystemOperationRunner* runner, - const FileSystemURL& url, - FileSystemOperation::FileEntryList* contents, - bool* completed) { - DCHECK(contents); - DCHECK(completed); - base::RunLoop run_loop; - runner->ReadDirectory( - url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, - completed)); - run_loop.Run(); -} - -} // namespace - -class TestIPhotoDataProvider : public IPhotoDataProvider { - public: - explicit TestIPhotoDataProvider(const base::FilePath& fake_library_path) - : IPhotoDataProvider(fake_library_path) { - EXPECT_TRUE(fake_auto_add_dir_.CreateUniqueTempDir()); - } - - ~TestIPhotoDataProvider() override {} - - void RefreshData(const ReadyCallback& ready_callback) override { - ready_callback.Run(true /* success */); - } - - std::vector<std::string> GetAlbumNames() const override { - std::vector<std::string> names; - names.push_back("Album1"); - names.push_back("has_originals"); - return names; - } - - std::map<std::string, base::FilePath> GetAlbumContents( - const std::string& album) const override { - std::map<std::string, base::FilePath> contents; - contents["a.jpg"] = library_path().AppendASCII("a.jpg"); - return contents; - } - - base::FilePath GetPhotoLocationInAlbum( - const std::string& album, - const std::string& filename) const override { - return library_path().AppendASCII("a.jpg"); - } - - bool HasOriginals(const std::string& album) const override { - return (album == "has_originals"); - } - - std::map<std::string, base::FilePath> GetOriginals( - const std::string& album) const override { - std::map<std::string, base::FilePath> contents; - contents["a.jpg"] = library_path().AppendASCII("orig.jpg"); - return contents; - } - - base::FilePath GetOriginalPhotoLocation( - const std::string& album, - const std::string& filename) const override { - return library_path().AppendASCII("orig.jpg"); - } - - private: - base::ScopedTempDir fake_auto_add_dir_; -}; - -class TestIPhotoFileUtil : public IPhotoFileUtil { - public: - explicit TestIPhotoFileUtil(MediaPathFilter* media_path_filter, - IPhotoDataProvider* data_provider) - : IPhotoFileUtil(media_path_filter), - data_provider_(data_provider) { - } - ~TestIPhotoFileUtil() override {} - - private: - IPhotoDataProvider* GetDataProvider() override { return data_provider_; } - - IPhotoDataProvider* data_provider_; -}; - -class TestMediaFileSystemBackend : public MediaFileSystemBackend { - public: - TestMediaFileSystemBackend(const base::FilePath& profile_path, - IPhotoFileUtil* iphoto_file_util) - : MediaFileSystemBackend( - profile_path, - MediaFileSystemBackend::MediaTaskRunner().get()), - test_file_util_(iphoto_file_util) {} - - storage::AsyncFileUtil* GetAsyncFileUtil( - storage::FileSystemType type) override { - if (type != storage::kFileSystemTypeIphoto) - return NULL; - - return test_file_util_.get(); - } - - private: - scoped_ptr<storage::AsyncFileUtil> test_file_util_; -}; - -class IPhotoFileUtilTest : public testing::Test { - public: - IPhotoFileUtilTest() - : io_thread_(content::BrowserThread::IO, &message_loop_) { - } - - void SetUpDataProvider() { - ASSERT_TRUE(fake_library_dir_.CreateUniqueTempDir()); - ASSERT_EQ( - 0, - base::WriteFile( - fake_library_dir_.path().AppendASCII("a.jpg"), - NULL, - 0)); - ASSERT_EQ( - 0, - base::WriteFile( - fake_library_dir_.path().AppendASCII("orig.jpg"), - NULL, - 0)); - - iphoto_data_provider_.reset( - new TestIPhotoDataProvider(fake_library_dir_.path())); - } - - void SetUp() override { - ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); - ImportedMediaGalleryRegistry::GetInstance()->Initialize(); - - scoped_refptr<storage::SpecialStoragePolicy> storage_policy = - new content::MockSpecialStoragePolicy(); - - // Initialize fake IPhotoDataProvider on media task runner thread. - MediaFileSystemBackend::MediaTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&IPhotoFileUtilTest::SetUpDataProvider, - base::Unretained(this))); - base::WaitableEvent event(true, false /* initially_signalled */); - MediaFileSystemBackend::MediaTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); - event.Wait(); - - media_path_filter_.reset(new MediaPathFilter()); - ScopedVector<storage::FileSystemBackend> additional_providers; - additional_providers.push_back(new TestMediaFileSystemBackend( - profile_dir_.path(), - new TestIPhotoFileUtil(media_path_filter_.get(), - iphoto_data_provider_.get()))); - - file_system_context_ = new storage::FileSystemContext( - base::ThreadTaskRunnerHandle::Get().get(), - base::ThreadTaskRunnerHandle::Get().get(), - storage::ExternalMountPoints::CreateRefCounted().get(), - storage_policy.get(), NULL, std::move(additional_providers), - std::vector<storage::URLRequestAutoMountHandler>(), profile_dir_.path(), - content::CreateAllowFileAccessOptions()); - } - - protected: - void TestNonexistentFolder(const std::string& path_append) { - FileSystemOperation::FileEntryList contents; - FileSystemURL url = CreateURL(path_append); - bool completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - - ASSERT_FALSE(completed); - } - - FileSystemURL CreateURL(const std::string& path) const { - base::FilePath virtual_path = - ImportedMediaGalleryRegistry::GetInstance()->ImportedRoot(); - virtual_path = virtual_path.AppendASCII("iphoto"); - virtual_path = virtual_path.AppendASCII(path); - return file_system_context_->CreateCrackedFileSystemURL( - GURL("http://www.example.com"), - storage::kFileSystemTypeIphoto, - virtual_path); - } - - storage::FileSystemOperationRunner* operation_runner() const { - return file_system_context_->operation_runner(); - } - - scoped_refptr<storage::FileSystemContext> file_system_context() const { - return file_system_context_; - } - - TestIPhotoDataProvider* data_provider() const { - return iphoto_data_provider_.get(); - } - - private: - base::MessageLoop message_loop_; - content::TestBrowserThread io_thread_; - - base::ScopedTempDir profile_dir_; - base::ScopedTempDir fake_library_dir_; - - scoped_refptr<storage::FileSystemContext> file_system_context_; - scoped_ptr<MediaPathFilter> media_path_filter_; - scoped_ptr<TestIPhotoDataProvider> iphoto_data_provider_; - - DISALLOW_COPY_AND_ASSIGN(IPhotoFileUtilTest); -}; - -TEST_F(IPhotoFileUtilTest, RootContents) { - FileSystemOperation::FileEntryList contents; - FileSystemURL url = CreateURL(""); - bool completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - - ASSERT_TRUE(completed); - ASSERT_EQ(1u, contents.size()); - - EXPECT_TRUE(contents.front().is_directory); - - EXPECT_EQ(base::FilePath::FromUTF8Unsafe(kIPhotoAlbumsDir).value(), - contents.back().name); -} - -TEST_F(IPhotoFileUtilTest, AlbumsDirectoryContents) { - FileSystemOperation::FileEntryList contents; - FileSystemURL url = CreateURL(kIPhotoAlbumsDir); - bool completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - - ASSERT_TRUE(completed); - ASSERT_EQ(2u, contents.size()); - - EXPECT_TRUE(contents.front().is_directory); - - EXPECT_EQ("Album1", contents.front().name); - EXPECT_EQ("has_originals", contents.back().name); -} - -TEST_F(IPhotoFileUtilTest, AlbumContents) { - FileSystemOperation::FileEntryList contents; - FileSystemURL url = CreateURL(std::string(kIPhotoAlbumsDir) + "/Album1"); - bool completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - - ASSERT_TRUE(completed); - ASSERT_EQ(1u, contents.size()); - - EXPECT_FALSE(contents.front().is_directory); - - EXPECT_EQ("a.jpg", contents.back().name); -} - -TEST_F(IPhotoFileUtilTest, BadAccess) { - FileSystemOperation::FileEntryList contents; - FileSystemURL url = CreateURL("None"); - bool completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - ASSERT_FALSE(completed); - ASSERT_EQ(0u, contents.size()); - - url = CreateURL(std::string(kIPhotoAlbumsDir) + "/NoAlbum"); - completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - ASSERT_FALSE(completed); - ASSERT_EQ(0u, contents.size()); -} - -TEST_F(IPhotoFileUtilTest, Originals) { - FileSystemOperation::FileEntryList contents; - FileSystemURL url = - CreateURL(std::string(kIPhotoAlbumsDir) + "/has_originals"); - bool completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - - ASSERT_TRUE(completed); - ASSERT_EQ(2u, contents.size()); - EXPECT_TRUE(contents.front().is_directory); - EXPECT_EQ("Originals", contents.front().name); - EXPECT_FALSE(contents.back().is_directory); - EXPECT_EQ("a.jpg", contents.back().name); - - url = CreateURL(std::string(kIPhotoAlbumsDir) + "/has_originals/Originals"); - completed = false; - ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); - ASSERT_TRUE(completed); - ASSERT_EQ(1u, contents.size()); - - EXPECT_FALSE(contents.front().is_directory); - EXPECT_EQ("a.jpg", contents.front().name); -} - -} // namespace iphoto diff --git a/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc b/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc index 954a58a..c7f1c34 100644 --- a/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc +++ b/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc @@ -50,10 +50,6 @@ #include "chrome/browser/media_galleries/fileapi/picasa_file_util.h" #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) -#include "chrome/browser/media_galleries/fileapi/iphoto_file_util.h" -#endif // defined(OS_MACOSX) - using storage::FileSystemContext; using storage::FileSystemURL; @@ -147,11 +143,6 @@ MediaFileSystemBackend::MediaFileSystemBackend( picasa_file_util_used_(false), itunes_file_util_used_(false) #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - , - iphoto_file_util_(new iphoto::IPhotoFileUtil(media_path_filter_.get())), - iphoto_file_util_used_(false) -#endif // defined(OS_MACOSX) { } @@ -236,9 +227,6 @@ bool MediaFileSystemBackend::CanHandleType(storage::FileSystemType type) const { case storage::kFileSystemTypePicasa: case storage::kFileSystemTypeItunes: #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - case storage::kFileSystemTypeIphoto: -#endif // defined(OS_MACOSX) return true; default: return false; @@ -284,14 +272,6 @@ storage::AsyncFileUtil* MediaFileSystemBackend::GetAsyncFileUtil( } return picasa_file_util_.get(); #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - case storage::kFileSystemTypeIphoto: - if (!iphoto_file_util_used_) { - media_galleries::UsageCount(media_galleries::IPHOTO_FILE_SYSTEM_USED); - iphoto_file_util_used_ = true; - } - return iphoto_file_util_.get(); -#endif // defined(OS_MACOSX) default: NOTREACHED(); } @@ -312,7 +292,6 @@ MediaFileSystemBackend::GetCopyOrMoveFileValidatorFactory( switch (type) { case storage::kFileSystemTypeNativeMedia: case storage::kFileSystemTypeDeviceMedia: - case storage::kFileSystemTypeIphoto: case storage::kFileSystemTypeItunes: if (!media_copy_or_move_file_validator_factory_) { *error_code = base::File::FILE_ERROR_SECURITY; @@ -351,8 +330,7 @@ bool MediaFileSystemBackend::HasInplaceCopyImplementation( DCHECK(type == storage::kFileSystemTypeNativeMedia || type == storage::kFileSystemTypeDeviceMedia || type == storage::kFileSystemTypeItunes || - type == storage::kFileSystemTypePicasa || - type == storage::kFileSystemTypeIphoto); + type == storage::kFileSystemTypePicasa); return true; } diff --git a/chrome/browser/media_galleries/fileapi/media_file_system_backend.h b/chrome/browser/media_galleries/fileapi/media_file_system_backend.h index 71bdbcc..b8a0736 100644 --- a/chrome/browser/media_galleries/fileapi/media_file_system_backend.h +++ b/chrome/browser/media_galleries/fileapi/media_file_system_backend.h @@ -116,12 +116,6 @@ class MediaFileSystemBackend : public storage::FileSystemBackend { bool picasa_file_util_used_; bool itunes_file_util_used_; #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - scoped_ptr<storage::AsyncFileUtil> iphoto_file_util_; - - // Used for usage UMA tracking. - bool iphoto_file_util_used_; -#endif // defined(OS_MACOSX) DISALLOW_COPY_AND_ASSIGN(MediaFileSystemBackend); }; diff --git a/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.cc b/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.cc index 827b295..53e5bd0 100644 --- a/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.cc +++ b/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.cc @@ -24,14 +24,6 @@ namespace iapps { SafeIAppsLibraryParser::SafeIAppsLibraryParser() : parser_state_(INITIAL_STATE) {} -void SafeIAppsLibraryParser::ParseIPhotoLibrary( - const base::FilePath& library_file, - const IPhotoParserCallback& callback) { - library_file_path_ = library_file; - iphoto_callback_ = callback; - Start(); -} - void SafeIAppsLibraryParser::ParseITunesLibrary( const base::FilePath& library_file, const ITunesParserCallback& callback) { @@ -95,34 +87,11 @@ void SafeIAppsLibraryParser::OnUtilityProcessStarted() { IPC::TakeFileHandleForProcess( std::move(library_file_), utility_process_host_->GetData().handle))); - } else if (!iphoto_callback_.is_null()) { -#if defined(OS_MACOSX) - utility_process_host_->Send(new ChromeUtilityMsg_ParseIPhotoLibraryXmlFile( - IPC::TakeFileHandleForProcess( - std::move(library_file_), - utility_process_host_->GetData().handle))); -#endif } parser_state_ = STARTED_PARSING_STATE; } -#if defined(OS_MACOSX) -void SafeIAppsLibraryParser::OnGotIPhotoLibrary( - bool result, const iphoto::parser::Library& library) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - DCHECK(!iphoto_callback_.is_null()); - - if (parser_state_ != STARTED_PARSING_STATE) - return; - - MediaFileSystemBackend::MediaTaskRunner()->PostTask( - FROM_HERE, - base::Bind(iphoto_callback_, result, library)); - parser_state_ = FINISHED_PARSING_STATE; -} -#endif - void SafeIAppsLibraryParser::OnGotITunesLibrary( bool result, const itunes::parser::Library& library) { DCHECK_CURRENTLY_ON(BrowserThread::IO); @@ -150,11 +119,6 @@ void SafeIAppsLibraryParser::OnError() { parser_state_ = FINISHED_PARSING_STATE; if (!itunes_callback_.is_null()) OnGotITunesLibrary(false /* failed */, itunes::parser::Library()); - -#if defined(OS_MACOSX) - if (!iphoto_callback_.is_null()) - OnGotIPhotoLibrary(false /* failed */, iphoto::parser::Library()); -#endif } bool SafeIAppsLibraryParser::OnMessageReceived( @@ -163,10 +127,6 @@ bool SafeIAppsLibraryParser::OnMessageReceived( IPC_BEGIN_MESSAGE_MAP(SafeIAppsLibraryParser, message) IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, OnUtilityProcessStarted) -#if defined(OS_MACOSX) - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotIPhotoLibrary, - OnGotIPhotoLibrary) -#endif IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotITunesLibrary, OnGotITunesLibrary) IPC_MESSAGE_UNHANDLED(handled = false) diff --git a/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h b/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h index bd79e51..7b6dcfa 100644 --- a/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h +++ b/chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h @@ -14,7 +14,6 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "build/build_config.h" -#include "chrome/common/media_galleries/iphoto_library.h" #include "chrome/common/media_galleries/itunes_library.h" #include "content/public/browser/utility_process_host.h" #include "content/public/browser/utility_process_host_client.h" @@ -36,17 +35,11 @@ namespace iapps { // noted. class SafeIAppsLibraryParser : public content::UtilityProcessHostClient { public: - typedef base::Callback<void(bool, const iphoto::parser::Library&)> - IPhotoParserCallback; typedef base::Callback<void(bool, const itunes::parser::Library&)> ITunesParserCallback; SafeIAppsLibraryParser(); - // Start the parse of the iPhoto library file. - void ParseIPhotoLibrary(const base::FilePath& library_file, - const IPhotoParserCallback& callback); - // Start the parse of the iTunes library file. void ParseITunesLibrary(const base::FilePath& library_file, const ITunesParserCallback& callback); @@ -75,12 +68,6 @@ class SafeIAppsLibraryParser : public content::UtilityProcessHostClient { void OnUtilityProcessStarted(); // Notification from the utility process when it finishes parsing the - // iPhoto XML. Runs on the IO thread. -#if defined(OS_MACOSX) - void OnGotIPhotoLibrary(bool result, const iphoto::parser::Library& library); -#endif - - // Notification from the utility process when it finishes parsing the // iTunes XML. Runs on the IO thread. void OnGotITunesLibrary(bool result, const itunes::parser::Library& library); @@ -108,9 +95,6 @@ class SafeIAppsLibraryParser : public content::UtilityProcessHostClient { // Only accessed on the Media Task Runner. ITunesParserCallback itunes_callback_; - // Only accessed on the Media Task Runner. - IPhotoParserCallback iphoto_callback_; - // Verifies the messages from the utility process came at the right time. // Initialized on the Media Task Runner, but only accessed on the IO thread. ParserState parser_state_; diff --git a/chrome/browser/media_galleries/imported_media_gallery_registry.cc b/chrome/browser/media_galleries/imported_media_gallery_registry.cc index abbf8c8..211e8b8 100644 --- a/chrome/browser/media_galleries/imported_media_gallery_registry.cc +++ b/chrome/browser/media_galleries/imported_media_gallery_registry.cc @@ -8,7 +8,6 @@ #include "base/files/file_util.h" #include "base/logging.h" #include "build/build_config.h" -#include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" #include "chrome/browser/media_galleries/fileapi/itunes_data_provider.h" #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" @@ -118,45 +117,6 @@ bool ImportedMediaGalleryRegistry::RegisterITunesFilesystemOnUIThread( return result; } -bool ImportedMediaGalleryRegistry::RegisterIPhotoFilesystemOnUIThread( - const std::string& fs_name, const base::FilePath& library_xml_path) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - DCHECK(!library_xml_path.empty()); - - bool result = false; - - // TODO(gbillock): Investigate how to refactor this to reduce duplicated - // code. -#if defined(OS_MACOSX) - base::FilePath root = ImportedRoot(); - if (root.empty()) - return false; - result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( - fs_name, - storage::kFileSystemTypeIphoto, - storage::FileSystemMountOption(), - root.AppendASCII("iphoto")); - if (!result) - return result; - - iphoto_fs_names_.insert(fs_name); - - if (iphoto_fs_names_.size() == 1) { - MediaFileSystemBackend::MediaTaskRunner()->PostTask( - FROM_HERE, - Bind(&ImportedMediaGalleryRegistry::RegisterIPhotoFileSystem, - base::Unretained(this), library_xml_path)); -#ifndef NDEBUG - iphoto_xml_library_path_ = library_xml_path; - } else { - DCHECK_EQ(iphoto_xml_library_path_.value(), library_xml_path.value()); -#endif - } -#endif // defined(OS_MACOSX) - - return result; -} - bool ImportedMediaGalleryRegistry::RevokeImportedFilesystemOnUIThread( const std::string& fs_name) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); @@ -183,18 +143,6 @@ bool ImportedMediaGalleryRegistry::RevokeImportedFilesystemOnUIThread( } #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - if (iphoto_fs_names_.erase(fs_name)) { - if (iphoto_fs_names_.empty()) { - MediaFileSystemBackend::MediaTaskRunner()->PostTask( - FROM_HERE, - Bind(&ImportedMediaGalleryRegistry::RevokeIPhotoFileSystem, - base::Unretained(this))); - } - return ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name); - } -#endif // defined(OS_MACOSX) - return false; } @@ -221,16 +169,6 @@ ImportedMediaGalleryRegistry::ITunesDataProvider() { } #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) -// static -iphoto::IPhotoDataProvider* -ImportedMediaGalleryRegistry::IPhotoDataProvider() { - DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); - DCHECK(GetInstance()->iphoto_data_provider_); - return GetInstance()->iphoto_data_provider_.get(); -} -#endif // defined(OS_MACOSX) - ImportedMediaGalleryRegistry::ImportedMediaGalleryRegistry() {} ImportedMediaGalleryRegistry::~ImportedMediaGalleryRegistry() { @@ -240,9 +178,6 @@ ImportedMediaGalleryRegistry::~ImportedMediaGalleryRegistry() { DCHECK_EQ(0U, picasa_fs_names_.size()); DCHECK_EQ(0U, itunes_fs_names_.size()); #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - DCHECK_EQ(0U, iphoto_fs_names_.size()); -#endif // defined(OS_MACOSX) } #if defined(OS_WIN) || defined(OS_MACOSX) @@ -273,17 +208,3 @@ void ImportedMediaGalleryRegistry::RevokeITunesFileSystem() { } #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) -void ImportedMediaGalleryRegistry::RegisterIPhotoFileSystem( - const base::FilePath& xml_library_path) { - DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); - DCHECK(!iphoto_data_provider_); - iphoto_data_provider_.reset(new iphoto::IPhotoDataProvider(xml_library_path)); -} - -void ImportedMediaGalleryRegistry::RevokeIPhotoFileSystem() { - DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); - DCHECK(iphoto_data_provider_); - iphoto_data_provider_.reset(); -} -#endif // defined(OS_MACOSX) diff --git a/chrome/browser/media_galleries/imported_media_gallery_registry.h b/chrome/browser/media_galleries/imported_media_gallery_registry.h index 39f5e77..a9aa2b9 100644 --- a/chrome/browser/media_galleries/imported_media_gallery_registry.h +++ b/chrome/browser/media_galleries/imported_media_gallery_registry.h @@ -14,11 +14,6 @@ #include "base/memory/scoped_ptr.h" #include "build/build_config.h" -namespace iphoto { -class IPhotoDataProvider; -class IPhotoDataProviderTest; -} - namespace itunes { class ITunesDataProvider; class ITunesDataProviderTest; @@ -48,10 +43,6 @@ class ImportedMediaGalleryRegistry { const std::string& fs_name, const base::FilePath& xml_library_path); - bool RegisterIPhotoFilesystemOnUIThread( - const std::string& fs_name, - const base::FilePath& xml_library_path); - bool RevokeImportedFilesystemOnUIThread(const std::string& fs_name); // Path where all virtual file systems are "mounted." @@ -63,13 +54,8 @@ class ImportedMediaGalleryRegistry { static itunes::ITunesDataProvider* ITunesDataProvider(); #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - static iphoto::IPhotoDataProvider* IPhotoDataProvider(); -#endif // defined(OS_MACOSX) - private: friend struct base::DefaultLazyInstanceTraits<ImportedMediaGalleryRegistry>; - friend class iphoto::IPhotoDataProviderTest; friend class itunes::ITunesDataProviderTest; friend class picasa::PicasaDataProviderTest; @@ -84,11 +70,6 @@ class ImportedMediaGalleryRegistry { void RevokeITunesFileSystem(); #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - void RegisterIPhotoFileSystem(const base::FilePath& xml_library_path); - void RevokeIPhotoFileSystem(); -#endif // defined(OS_MACOSX) - base::FilePath imported_root_; #if defined(OS_WIN) || defined(OS_MACOSX) @@ -106,16 +87,6 @@ class ImportedMediaGalleryRegistry { #endif #endif // defined(OS_WIN) || defined(OS_MACOSX) -#if defined(OS_MACOSX) - scoped_ptr<iphoto::IPhotoDataProvider> iphoto_data_provider_; - - std::set<std::string> iphoto_fs_names_; - -#ifndef NDEBUG - base::FilePath iphoto_xml_library_path_; -#endif -#endif // defined(OS_MACOSX) - DISALLOW_COPY_AND_ASSIGN(ImportedMediaGalleryRegistry); }; diff --git a/chrome/browser/media_galleries/media_file_system_registry.cc b/chrome/browser/media_galleries/media_file_system_registry.cc index a5c3adb..a51aebb 100644 --- a/chrome/browser/media_galleries/media_file_system_registry.cc +++ b/chrome/browser/media_galleries/media_file_system_registry.cc @@ -719,10 +719,6 @@ class MediaFileSystemRegistry::MediaFileSystemContextImpl ImportedMediaGalleryRegistry* registry = ImportedMediaGalleryRegistry::GetInstance(); result = registry->RegisterPicasaFilesystemOnUIThread(fs_name, path); - } else if (StorageInfo::IsIPhotoDevice(device_id)) { - ImportedMediaGalleryRegistry* registry = - ImportedMediaGalleryRegistry::GetInstance(); - result = registry->RegisterIPhotoFilesystemOnUIThread(fs_name, path); } else { result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( fs_name, diff --git a/chrome/browser/media_galleries/media_galleries_histograms.h b/chrome/browser/media_galleries/media_galleries_histograms.h index 0b106cb..37836a1 100644 --- a/chrome/browser/media_galleries/media_galleries_histograms.h +++ b/chrome/browser/media_galleries/media_galleries_histograms.h @@ -35,7 +35,7 @@ enum MediaGalleriesUsages { REMOVE_ALL_GALLERY_WATCH, ITUNES_FILE_SYSTEM_USED, PICASA_FILE_SYSTEM_USED, - IPHOTO_FILE_SYSTEM_USED, + DELETED_IPHOTO_FILE_SYSTEM_USED, MEDIA_GALLERIES_NUM_USAGES }; diff --git a/chrome/browser/media_galleries/media_galleries_preferences.cc b/chrome/browser/media_galleries/media_galleries_preferences.cc index 35f1d89..fc4e96d 100644 --- a/chrome/browser/media_galleries/media_galleries_preferences.cc +++ b/chrome/browser/media_galleries/media_galleries_preferences.cc @@ -84,7 +84,6 @@ const char kMediaGalleriesDefaultGalleryTypeMusicDefaultValue[] = "music"; const char kMediaGalleriesDefaultGalleryTypePicturesDefaultValue[] = "pictures"; const char kMediaGalleriesDefaultGalleryTypeVideosDefaultValue[] = "videos"; -const char kIPhotoGalleryName[] = "iPhoto"; const char kITunesGalleryName[] = "iTunes"; const char kPicasaGalleryName[] = "Picasa"; @@ -487,7 +486,7 @@ void MediaGalleriesPreferences::EnsureInitialized(base::Closure callback) { // It cannot be incremented inline with each callback, as some may return // synchronously, decrement the counter to 0, and prematurely trigger // FinishInitialization. - pre_initialization_callbacks_waiting_ = 4; + pre_initialization_callbacks_waiting_ = 3; // Check whether we should be initializing -- are there any extensions that // are using media galleries? @@ -512,10 +511,6 @@ void MediaGalleriesPreferences::EnsureInitialized(base::Closure callback) { picasa::FindPicasaDatabase( base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, weak_factory_.GetWeakPtr())); - - iapps::FindIPhotoLibrary( - base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, - weak_factory_.GetWeakPtr())); } bool MediaGalleriesPreferences::IsInitialized() const { return initialized_; } @@ -664,9 +659,7 @@ void MediaGalleriesPreferences::OnStorageMonitorInit( void MediaGalleriesPreferences::OnFinderDeviceID(const std::string& device_id) { if (!device_id.empty()) { std::string gallery_name; - if (StorageInfo::IsIPhotoDevice(device_id)) - gallery_name = kIPhotoGalleryName; - else if (StorageInfo::IsITunesDevice(device_id)) + if (StorageInfo::IsITunesDevice(device_id)) gallery_name = kITunesGalleryName; else if (StorageInfo::IsPicasaDevice(device_id)) gallery_name = kPicasaGalleryName; @@ -763,8 +756,7 @@ bool MediaGalleriesPreferences::LookUpGalleryByPath( for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries_.begin(); it != known_galleries_.end(); ++it) { const std::string& device_id = it->second.device_id; - if (iapps::PathIndicatesIPhotoLibrary(device_id, path) || - iapps::PathIndicatesITunesLibrary(device_id, path)) { + if (iapps::PathIndicatesITunesLibrary(device_id, path)) { *gallery_info = it->second; return true; } diff --git a/chrome/browser/media_galleries/media_galleries_preferences.h b/chrome/browser/media_galleries/media_galleries_preferences.h index 2525a4b2..c0f14b2 100644 --- a/chrome/browser/media_galleries/media_galleries_preferences.h +++ b/chrome/browser/media_galleries/media_galleries_preferences.h @@ -307,7 +307,7 @@ class MediaGalleriesPreferences void OnStorageMonitorInit(bool api_has_been_used); - // Handle an iPhoto, iTunes, or Picasa finder returning a device ID to us. + // Handle an iTunes or Picasa finder returning a device ID to us. void OnFinderDeviceID(const std::string& device_id); // Builds |known_galleries_| from the persistent store. diff --git a/chrome/browser/media_galleries/media_galleries_test_util.cc b/chrome/browser/media_galleries/media_galleries_test_util.cc index 1c98c86..0828aab 100644 --- a/chrome/browser/media_galleries/media_galleries_test_util.cc +++ b/chrome/browser/media_galleries/media_galleries_test_util.cc @@ -172,11 +172,6 @@ base::FilePath EnsureMediaDirectoriesExists::GetFakeITunesRootPath() const { DCHECK(fake_dir_.IsValid()); return fake_dir_.path().AppendASCII("itunes"); } - -base::FilePath EnsureMediaDirectoriesExists::GetFakeIPhotoRootPath() const { - DCHECK(fake_dir_.IsValid()); - return fake_dir_.path().AppendASCII("iphoto"); -} #endif // OS_MACOSX void EnsureMediaDirectoriesExists::Init() { @@ -212,14 +207,6 @@ void EnsureMediaDirectoriesExists::Init() { base::mac::NSToCFCast(iapps::NSArrayFromFilePath(itunes_xml)), false); - // iPhoto override. - base::FilePath iphoto_xml = - GetFakeIPhotoRootPath().AppendASCII("AlbumData.xml"); - mac_preferences_->AddTestItem( - base::mac::NSToCFCast(iapps::kIPhotoRecentDatabasesKey), - base::mac::NSToCFCast(iapps::NSArrayFromFilePath(iphoto_xml)), - false); - iapps::SetMacPreferencesForTesting(mac_preferences_.get()); picasa::SetMacPreferencesForTesting(mac_preferences_.get()); #endif // OS_MACOSX diff --git a/chrome/browser/media_galleries/media_galleries_test_util.h b/chrome/browser/media_galleries/media_galleries_test_util.h index 5181601..9276488 100644 --- a/chrome/browser/media_galleries/media_galleries_test_util.h +++ b/chrome/browser/media_galleries/media_galleries_test_util.h @@ -60,7 +60,6 @@ class EnsureMediaDirectoriesExists { #if defined(OS_MACOSX) base::FilePath GetFakeITunesRootPath() const; - base::FilePath GetFakeIPhotoRootPath() const; #endif private: diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 4c642ed..accf45a 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1081,10 +1081,6 @@ 'browser/web_applications/web_app_linux.cc', ], 'chrome_browser_mac_sources': [ - 'browser/media_galleries/fileapi/iphoto_data_provider.cc', - 'browser/media_galleries/fileapi/iphoto_data_provider.h', - 'browser/media_galleries/fileapi/iphoto_file_util.cc', - 'browser/media_galleries/fileapi/iphoto_file_util.h', 'browser/password_manager/password_manager_util_mac.h', 'browser/password_manager/password_manager_util_mac.mm', ], diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 44291f3..faf3cdf 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -287,10 +287,6 @@ 'common/extensions/api/networking_private/networking_private_crypto.cc', 'common/extensions/api/networking_private/networking_private_crypto.h', ], - 'chrome_common_mac_sources': [ - 'common/media_galleries/iphoto_library.cc', - 'common/media_galleries/iphoto_library.h', - ] }, 'targets': [ { @@ -404,10 +400,6 @@ '../third_party/boringssl/boringssl.gyp:boringssl', ], }], - ['OS=="mac"', { - 'sources': [ '<@(chrome_common_mac_sources)' ], - 'dependencies': [ 'app_mode_app_support' ], - }], ['OS != "ios"', { 'dependencies': [ 'common_mojo_bindings', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 8d29f27..4565a1c 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2517,7 +2517,6 @@ '../third_party/ocmock/ocmock.gyp:ocmock', ], 'sources': [ - 'browser/media_galleries/fileapi/iphoto_data_provider_browsertest.cc', 'browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper_browsertest.mm', 'browser/spellchecker/spellcheck_message_filter_platform_mac_browsertest.cc', ], diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 3a30df0..2b11c67 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1393,10 +1393,6 @@ 'app/chrome_dll.rc', 'test/data/resource.rc', ], - 'chrome_unit_tests_mac_sources': [ - 'browser/media_galleries/fileapi/iphoto_file_util_unittest.cc', - 'utility/media_galleries/iphoto_library_parser_unittest.cc', - ], 'chrome_unit_tests_win_mac_sources': [ 'browser/media_galleries/fileapi/itunes_file_util_unittest.cc', 'browser/media_galleries/fileapi/picasa_file_util_unittest.cc', @@ -2603,7 +2599,6 @@ '../third_party/ocmock/ocmock.gyp:ocmock', 'chrome', ], - 'sources': [ '<@(chrome_unit_tests_mac_sources)' ], 'sources!': [ # This tests the function GetSpellCheckLanguages which is not used # on Mac. diff --git a/chrome/chrome_utility.gypi b/chrome/chrome_utility.gypi index 0ed6bdf..401761a 100644 --- a/chrome/chrome_utility.gypi +++ b/chrome/chrome_utility.gypi @@ -90,10 +90,6 @@ 'utility/media_galleries/media_metadata_parser.cc', 'utility/media_galleries/media_metadata_parser.h', ], - 'chrome_utility_mac_media_gallery_sources': [ - 'utility/media_galleries/iphoto_library_parser.cc', - 'utility/media_galleries/iphoto_library_parser.h', - ], 'chrome_utility_win_mac_media_gallery_sources': [ 'utility/media_galleries/iapps_xml_utils.cc', 'utility/media_galleries/iapps_xml_utils.h', @@ -197,11 +193,6 @@ 'utility/image_writer/image_writer_stub.cc', ] }], - ['OS=="mac"', { - 'sources': [ - '<@(chrome_utility_mac_media_gallery_sources)', - ], - }], ], }], ['enable_print_preview==0 and OS!="win"', { diff --git a/chrome/common/BUILD.gn b/chrome/common/BUILD.gn index c156b3a..d1cc2cd 100644 --- a/chrome/common/BUILD.gn +++ b/chrome/common/BUILD.gn @@ -188,8 +188,6 @@ static_library("common") { public_deps += [ "//third_party/boringssl" ] } if (is_mac) { - sources += - rebase_path(gypi_values.chrome_common_mac_sources, ".", "//chrome") public_deps += [ ":app_mode_app_support" ] } if (is_chromeos) { diff --git a/chrome/common/extensions/chrome_utility_extensions_messages.h b/chrome/common/extensions/chrome_utility_extensions_messages.h index ea3920fd..776f9e5 100644 --- a/chrome/common/extensions/chrome_utility_extensions_messages.h +++ b/chrome/common/extensions/chrome_utility_extensions_messages.h @@ -11,7 +11,6 @@ #include "base/files/file_path.h" #include "build/build_config.h" -#include "chrome/common/media_galleries/iphoto_library.h" #include "chrome/common/media_galleries/itunes_library.h" #include "chrome/common/media_galleries/metadata_types.h" #include "chrome/common/media_galleries/picasa_types.h" @@ -24,19 +23,6 @@ #define IPC_MESSAGE_START ChromeUtilityExtensionsMsgStart -#if defined(OS_MACOSX) -IPC_STRUCT_TRAITS_BEGIN(iphoto::parser::Photo) - IPC_STRUCT_TRAITS_MEMBER(id) - IPC_STRUCT_TRAITS_MEMBER(location) - IPC_STRUCT_TRAITS_MEMBER(original_location) -IPC_STRUCT_TRAITS_END() - -IPC_STRUCT_TRAITS_BEGIN(iphoto::parser::Library) - IPC_STRUCT_TRAITS_MEMBER(albums) - IPC_STRUCT_TRAITS_MEMBER(all_photos) -IPC_STRUCT_TRAITS_END() -#endif // defined(OS_MACOSX) - #if defined(OS_WIN) || defined(OS_MACOSX) IPC_STRUCT_TRAITS_BEGIN(itunes::parser::Track) IPC_STRUCT_TRAITS_MEMBER(id) @@ -85,13 +71,6 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseITunesPrefXml, std::string /* XML to parse */) #endif // defined(OS_WIN) -#if defined(OS_MACOSX) -// Tell the utility process to parse the iPhoto library XML file and -// return the parse result as well as the iPhoto library as an iphoto::Library. -IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseIPhotoLibraryXmlFile, - IPC::PlatformFileForTransit /* XML file to parse */) -#endif // defined(OS_MACOSX) - #if defined(OS_WIN) || defined(OS_MACOSX) // Tell the utility process to parse the iTunes library XML file and // return the parse result as well as the iTunes library as an itunes::Library. @@ -155,14 +134,6 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_GotITunesDirectory, base::FilePath /* Path to iTunes library */) #endif // defined(OS_WIN) -#if defined(OS_MACOSX) -// Reply after parsing the iPhoto library XML file with the parser result and -// an iphoto::Library data structure. -IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_GotIPhotoLibrary, - bool /* Parser result */, - iphoto::parser::Library /* iPhoto library */) -#endif // defined(OS_MACOSX) - #if defined(OS_WIN) || defined(OS_MACOSX) // Reply after parsing the iTunes library XML file with the parser result and // an itunes::Library data structure. diff --git a/chrome/common/extensions/docs/templates/intros/mediaGalleries.html b/chrome/common/extensions/docs/templates/intros/mediaGalleries.html index 9570bc9..197cc50 100644 --- a/chrome/common/extensions/docs/templates/intros/mediaGalleries.html +++ b/chrome/common/extensions/docs/templates/intros/mediaGalleries.html @@ -133,19 +133,4 @@ incrementing integer in parenthesis before the extension.</p> <h2 id="iPhoto">iPhoto</h2> -<p>If present, the user's iPhoto library can be accessed as a media gallery. -The files are structured within a subdirectory called "Albums/". Within that -subdirectory, each album in the user's iPhoto library will appear as a -subdirectory by name, and contain file entries for the photos in that album. -</p> -<p>Duplicate album names or image filenames within albums will get a -disambiguating suffix like "(NN)" where NN is a unique number.</p> -<p>Any items appearing in multiple albums in iPhoto will appear in all those -albums in the gallery.</p> -<p>If the user has modified any images within an album, there will be an -additional subdirectory called "originals/" within the album directory. -It will contain the original image with the same filename as in the parent -album subdirectory. The file as it appears in the parrent album directory -will be the one the user has invested time cropping, rotating, or -otherwise editing.</p> - +<p>iPhoto support was removed in Chrome 51.</p> diff --git a/chrome/common/media_galleries/iphoto_library.cc b/chrome/common/media_galleries/iphoto_library.cc deleted file mode 100644 index 03e13c0..0000000 --- a/chrome/common/media_galleries/iphoto_library.cc +++ /dev/null @@ -1,34 +0,0 @@ -// 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/common/media_galleries/iphoto_library.h" - -namespace iphoto { -namespace parser { - -Photo::Photo() - : id(0) { -} - -Photo::Photo(uint64_t id, - const base::FilePath& location, - const base::FilePath& original_location) - : id(id), location(location), original_location(original_location) {} - -bool Photo::operator<(const Photo& other) const { - return id < other.id; -} - -Library::Library() {} - -Library::Library(const Albums& albums, - const std::set<Photo>& all_photos) - : albums(albums), - all_photos(all_photos) {} - -Library::~Library() {} - - -} // namespace parser -} // namespace iphoto diff --git a/chrome/common/media_galleries/iphoto_library.h b/chrome/common/media_galleries/iphoto_library.h deleted file mode 100644 index dcae0ec..0000000 --- a/chrome/common/media_galleries/iphoto_library.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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. - -// These data structures can be used to describe the contents of an iPhoto -// library. - -#ifndef CHROME_COMMON_MEDIA_GALLERIES_IPHOTO_LIBRARY_H_ -#define CHROME_COMMON_MEDIA_GALLERIES_IPHOTO_LIBRARY_H_ - -#include <stdint.h> - -#include <map> -#include <set> - -#include "base/files/file_path.h" - -namespace iphoto { -namespace parser { - -struct Photo { - Photo(); - Photo(uint64_t id, - const base::FilePath& location, - const base::FilePath& original_location); - bool operator<(const Photo& other) const; - - uint64_t id; - base::FilePath location; - base::FilePath original_location; -}; - -typedef std::set<uint64_t> Album; -typedef std::map<std::string /*album name*/, Album> Albums; - -struct Library { - Library(); - Library(const Albums& albums, const std::set<Photo>& all_photos); - ~Library(); - - Albums albums; - std::set<Photo> all_photos; -}; - -} // namespace parser -} // namespace iphoto - -#endif // CHROME_COMMON_MEDIA_GALLERIES_IPHOTO_LIBRARY_H_ - diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn index 4a46e0b..3328dd2 100644 --- a/chrome/test/BUILD.gn +++ b/chrome/test/BUILD.gn @@ -1158,7 +1158,6 @@ if (!is_android) { "//third_party/ocmock", ] sources += [ - "../browser/media_galleries/fileapi/iphoto_data_provider_browsertest.cc", "../browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper_browsertest.mm", "../browser/spellchecker/spellcheck_message_filter_platform_mac_browsertest.cc", ] @@ -1929,10 +1928,6 @@ test("unit_tests") { ldflags = [ "-Wl,--strip-debug" ] } if (is_mac) { - sources += - rebase_path(chrome_tests_unit_gypi_values.chrome_unit_tests_mac_sources, - ".", - "//chrome") sources -= [ # This tests the function GetSpellCheckLanguages which is not used on # Mac. diff --git a/chrome/test/data/extensions/api_test/media_galleries/iphoto/manifest.json b/chrome/test/data/extensions/api_test/media_galleries/iphoto/manifest.json deleted file mode 100644 index 8194926..0000000 --- a/chrome/test/data/extensions/api_test/media_galleries/iphoto/manifest.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "chrome.mediaGalleries.iphoto", - "version": "0.1", - "description": "test IPhoto media gallery for chrome.mediaGalleries.getMediaFileSystems", - "app": { - "background": { - "scripts": ["common_injected.js", "test.js"] - } - }, - "permissions": [{"mediaGalleries": ["read", "allAutoDetected"]}] -} diff --git a/chrome/test/data/extensions/api_test/media_galleries/iphoto/test.js b/chrome/test/data/extensions/api_test/media_galleries/iphoto/test.js deleted file mode 100644 index c4b7875..0000000 --- a/chrome/test/data/extensions/api_test/media_galleries/iphoto/test.js +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2014 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. - -var mediaGalleries = chrome.mediaGalleries; -var expectedGalleryEntryLength; // Size of ../common/test.jpg. - -//Verifies a directory itself, then the contents. -function getAndVerifyDirectoryEntry(parentEntry, directoryName, - verifyFunction) { - function getDirectoryCallback(entry) { - chrome.test.assertTrue(entry.isDirectory); - verifyDirectoryEntry(entry, verifyFunction); - } - - parentEntry.getDirectory(directoryName, {create: false}, - getDirectoryCallback, chrome.test.fail); -} - -function verifyAllJPEGs(parentDirectoryEntry, filenames, doneCallback) { - var remaining = filenames; - function verifyNextJPEG() { - if (remaining.length == 0) { - doneCallback(); - return; - } - verifyJPEG(parentDirectoryEntry, remaining.pop(), - expectedGalleryEntryLength, verifyNextJPEG); - } - verifyNextJPEG(); -} - -function GalleryPropertiesTest(iphotoGallery) { - var galleryProperties = - mediaGalleries.getMediaFileSystemMetadata(iphotoGallery); - chrome.test.assertFalse(galleryProperties.isRemovable); - chrome.test.succeed(); -} - -function RootListingTest(iphotoGallery) { - function verify(directoryEntry, entries) { - chrome.test.assertEq(1, entries.length); - chrome.test.assertTrue(entries[0].isDirectory); - chrome.test.assertEq("Albums", entries[0].name); - chrome.test.succeed(); - } - - verifyDirectoryEntry(iphotoGallery.root, verify); -} - -function AlbumsListingTest(iphotoGallery) { - function verify(directoryEntry, entries) { - chrome.test.assertEq(2, entries.length); - chrome.test.assertTrue(entries[0].isDirectory); - chrome.test.assertTrue(entries[1].isDirectory); - chrome.test.assertEq("Album1", entries[0].name); - chrome.test.assertEq("Album2", entries[1].name); - chrome.test.succeed(); - } - - getAndVerifyDirectoryEntry(iphotoGallery.root, "Albums", verify); -} - -function Album1ListingTest(iphotoGallery) { - function verify(directoryEntry, entries) { - chrome.test.assertEq(2, entries.length); - chrome.test.assertTrue(entries[0].isFile); - chrome.test.assertTrue(entries[1].isFile); - chrome.test.assertEq("InBoth.jpg", entries[0].name); - chrome.test.assertEq("InFirstAlbumOnly.jpg", entries[1].name); - - verifyAllJPEGs(directoryEntry, ["InBoth.jpg", "InFirstAlbumOnly.jpg"], - chrome.test.succeed); - } - - getAndVerifyDirectoryEntry(iphotoGallery.root, - "Albums/Album1", verify); -} - -function Album2ListingTest(iphotoGallery) { - function verify(directoryEntry, entries) { - chrome.test.assertEq(1, entries.length); - chrome.test.assertTrue(entries[0].isFile); - chrome.test.assertEq("InBoth.jpg", entries[0].name); - - verifyAllJPEGs(directoryEntry, ["InBoth.jpg"], - chrome.test.succeed); - } - - getAndVerifyDirectoryEntry(iphotoGallery.root, - "Albums/Album2", verify); -} - -function getTest(testFunction) { - function getMediaFileSystemsList() { - mediaGalleries.getMediaFileSystems(getMediaFileSystemsCallback); - } - - function getMediaFileSystemsCallback(results) { - for (var i = 0; i < results.length; ++i) { - var properties = mediaGalleries.getMediaFileSystemMetadata(results[i]); - if (properties.name == "iPhoto") { - testFunction(results[i]); - return; - } - } - chrome.test.fail("iPhoto gallery not found"); - } - - return function() { - getMediaFileSystemsList(); - } -} - -CreateDummyWindowToPreventSleep(); - -chrome.test.getConfig(function(config) { - customArg = JSON.parse(config.customArg); - expectedGalleryEntryLength = customArg[0]; - - chrome.test.runTests([ - getTest(GalleryPropertiesTest), - getTest(RootListingTest), - getTest(AlbumsListingTest), - getTest(Album1ListingTest), - getTest(Album2ListingTest), - ]); -}); diff --git a/chrome/utility/BUILD.gn b/chrome/utility/BUILD.gn index f7c0d0e..d00c1cf 100644 --- a/chrome/utility/BUILD.gn +++ b/chrome/utility/BUILD.gn @@ -85,13 +85,6 @@ static_library("utility") { } else { sources += [ "image_writer/image_writer_stub.cc" ] } - - if (is_mac) { - sources += - rebase_path(gypi_values.chrome_utility_mac_media_gallery_sources, - ".", - "..") - } } if (use_nss_certs) { diff --git a/chrome/utility/extensions/extensions_handler.cc b/chrome/utility/extensions/extensions_handler.cc index 9518d9d..6b5beee 100644 --- a/chrome/utility/extensions/extensions_handler.cc +++ b/chrome/utility/extensions/extensions_handler.cc @@ -35,10 +35,6 @@ #include "components/wifi/wifi_service.h" #endif // defined(OS_WIN) -#if defined(OS_MACOSX) -#include "chrome/utility/media_galleries/iphoto_library_parser.h" -#endif // defined(OS_MACOSX) - #if defined(OS_WIN) || defined(OS_MACOSX) #include "chrome/utility/media_galleries/iapps_xml_utils.h" #include "chrome/utility/media_galleries/itunes_library_parser.h" @@ -95,11 +91,6 @@ bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { OnParseITunesPrefXml) #endif // defined(OS_WIN) -#if defined(OS_MACOSX) - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseIPhotoLibraryXmlFile, - OnParseIPhotoLibraryXmlFile) -#endif // defined(OS_MACOSX) - #if defined(OS_WIN) || defined(OS_MACOSX) IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesLibraryXmlFile, OnParseITunesLibraryXmlFile) @@ -156,17 +147,6 @@ void ExtensionsHandler::OnParseITunesPrefXml( } #endif // defined(OS_WIN) -#if defined(OS_MACOSX) -void ExtensionsHandler::OnParseIPhotoLibraryXmlFile( - const IPC::PlatformFileForTransit& iphoto_library_file) { - iphoto::IPhotoLibraryParser parser; - base::File file = IPC::PlatformFileForTransitToFile(iphoto_library_file); - bool result = parser.Parse(iapps::ReadFileAsString(std::move(file))); - Send(new ChromeUtilityHostMsg_GotIPhotoLibrary(result, parser.library())); - ReleaseProcessIfNeeded(); -} -#endif // defined(OS_MACOSX) - #if defined(OS_WIN) || defined(OS_MACOSX) void ExtensionsHandler::OnParseITunesLibraryXmlFile( const IPC::PlatformFileForTransit& itunes_library_file) { diff --git a/chrome/utility/extensions/extensions_handler.h b/chrome/utility/extensions/extensions_handler.h index 1ac86eb..8bcc16a 100644 --- a/chrome/utility/extensions/extensions_handler.h +++ b/chrome/utility/extensions/extensions_handler.h @@ -51,11 +51,6 @@ class ExtensionsHandler : public UtilityMessageHandler { void OnParseITunesPrefXml(const std::string& itunes_xml_data); #endif // defined(OS_WIN) -#if defined(OS_MACOSX) - void OnParseIPhotoLibraryXmlFile( - const IPC::PlatformFileForTransit& iphoto_library_file); -#endif // defined(OS_MACOSX) - #if defined(OS_WIN) || defined(OS_MACOSX) void OnParseITunesLibraryXmlFile( const IPC::PlatformFileForTransit& itunes_library_file); diff --git a/chrome/utility/media_galleries/iphoto_library_parser.cc b/chrome/utility/media_galleries/iphoto_library_parser.cc deleted file mode 100644 index a40d8cd..0000000 --- a/chrome/utility/media_galleries/iphoto_library_parser.cc +++ /dev/null @@ -1,265 +0,0 @@ -// 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/utility/media_galleries/iphoto_library_parser.h" - -#include <stdint.h> - -#include <string> - -#include "base/logging.h" -#include "base/stl_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_util.h" -#include "chrome/utility/media_galleries/iapps_xml_utils.h" -#include "third_party/libxml/chromium/libxml_utils.h" - -namespace iphoto { - -namespace { - -struct PhotoInfo { - uint64_t id; - base::FilePath location; - base::FilePath original_location; -}; - -struct AlbumInfo { - std::set<uint64_t> photo_ids; - std::string name; - uint64_t id; -}; - -class PhotosXmlDictReader : public iapps::XmlDictReader { - public: - PhotosXmlDictReader(XmlReader* reader, PhotoInfo* photo_info) - : iapps::XmlDictReader(reader), photo_info_(photo_info) {} - - bool HandleKeyImpl(const std::string& key) override { - if (key == "ImagePath") { - std::string value; - if (!iapps::ReadString(reader_, &value)) - return false; - photo_info_->location = base::FilePath(value); - } else if (key == "OriginalPath") { - std::string value; - if (!iapps::ReadString(reader_, &value)) - return false; - photo_info_->original_location = base::FilePath(value); - } else if (!SkipToNext()) { - return false; - } - return true; - } - - bool FinishedOk() override { return Found("ImagePath"); } - - private: - PhotoInfo* photo_info_; -}; - -// Contents of the album 'KeyList' key are -// <array> -// <string>1</string> -// <string>2</string> -// <string>3</string> -// </array> -bool ReadStringArray(XmlReader* reader, std::set<uint64_t>* photo_ids) { - if (reader->NodeName() != "array") - return false; - - // Advance past the array node and into the body of the array. - if (!reader->Read()) - return false; - - int array_content_depth = reader->Depth(); - - while (iapps::SeekToNodeAtCurrentDepth(reader, "string")) { - if (reader->Depth() != array_content_depth) - return false; - std::string photo_id; - if (!iapps::ReadString(reader, &photo_id)) - continue; - uint64_t id; - if (!base::StringToUint64(photo_id, &id)) - continue; - photo_ids->insert(id); - } - - return true; -} - -class AlbumXmlDictReader : public iapps::XmlDictReader { - public: - AlbumXmlDictReader(XmlReader* reader, AlbumInfo* album_info) - : iapps::XmlDictReader(reader), album_info_(album_info) {} - - bool ShouldLoop() override { - return !(Found("AlbumId") && Found("AlbumName") && Found("KeyList")); - } - - bool HandleKeyImpl(const std::string& key) override { - if (key == "AlbumId") { - if (!iapps::ReadInteger(reader_, &album_info_->id)) - return false; - } else if (key == "AlbumName") { - if (!iapps::ReadString(reader_, &album_info_->name)) - return false; - } else if (key == "KeyList") { - if (!iapps::SeekToNodeAtCurrentDepth(reader_, "array")) - return false; - if (!ReadStringArray(reader_, &album_info_->photo_ids)) - return false; - } else if (!SkipToNext()) { - return false; - } - return true; - } - - bool FinishedOk() override { return !ShouldLoop(); } - - private: - AlbumInfo* album_info_; -}; - -// Inside the master image list, we expect photos to be arranged as -// <dict> -// <key>$PHOTO_ID</key> -// <dict> -// $photo properties -// </dict> -// <key>$PHOTO_ID</key> -// <dict> -// $photo properties -// </dict> -// ... -// </dict> -// Returns true on success, false on error. -bool ParseAllPhotos(XmlReader* reader, - std::set<iphoto::parser::Photo>* all_photos) { - if (!iapps::SeekToNodeAtCurrentDepth(reader, "dict")) - return false; - int photos_dict_depth = reader->Depth() + 1; - if (!reader->Read()) - return false; - - bool errors = false; - while (reader->Depth() >= photos_dict_depth) { - if (!iapps::SeekToNodeAtCurrentDepth(reader, "key")) - break; - - std::string key; - if (!reader->ReadElementContent(&key)) { - errors = true; - break; - } - uint64_t id; - bool id_valid = base::StringToUint64(key, &id); - - if (!id_valid || - reader->Depth() != photos_dict_depth) { - errors = true; - break; - } - if (!iapps::SeekToNodeAtCurrentDepth(reader, "dict")) { - errors = true; - break; - } - - PhotoInfo photo_info; - photo_info.id = id; - // Walk through a dictionary filling in |result| with photo information. - // Return true if at least the location was found. - // In either case, the cursor is advanced out of the dictionary. - PhotosXmlDictReader dict_reader(reader, &photo_info); - if (!dict_reader.Read()) { - errors = true; - break; - } - - parser::Photo photo(photo_info.id, photo_info.location, - photo_info.original_location); - all_photos->insert(photo); - } - - return !errors; -} - -} // namespace - -IPhotoLibraryParser::IPhotoLibraryParser() {} -IPhotoLibraryParser::~IPhotoLibraryParser() {} - -class IPhotoLibraryXmlDictReader : public iapps::XmlDictReader { - public: - IPhotoLibraryXmlDictReader(XmlReader* reader, parser::Library* library) - : iapps::XmlDictReader(reader), library_(library), ok_(true) {} - - bool ShouldLoop() override { - return !(Found("List of Albums") && Found("Master Image List")); - } - - bool HandleKeyImpl(const std::string& key) override { - if (key == "List of Albums") { - if (!iapps::SeekToNodeAtCurrentDepth(reader_, "array") || - !reader_->Read()) { - return true; - } - while (iapps::SeekToNodeAtCurrentDepth(reader_, "dict")) { - AlbumInfo album_info; - AlbumXmlDictReader dict_reader(reader_, &album_info); - if (dict_reader.Read()) { - parser::Album album; - album = album_info.photo_ids; - // Strip / from album name and dedupe any collisions. - std::string name; - base::ReplaceChars(album_info.name, "//", " ", &name); - if (ContainsKey(library_->albums, name)) - name = name + "("+base::Uint64ToString(album_info.id)+")"; - library_->albums[name] = album; - } - } - } else if (key == "Master Image List") { - if (!ParseAllPhotos(reader_, &library_->all_photos)) { - ok_ = false; - return false; - } - } - return true; - } - - bool FinishedOk() override { return ok_; } - - // The IPhotoLibrary allows duplicate "List of Albums" and - // "Master Image List" keys (although that seems odd.) - bool AllowRepeats() override { return true; } - - private: - parser::Library* library_; - - // The base class bails when we request, and then calls |FinishedOk()| - // to decide what to return. We need to remember that we bailed because - // of an error. That's what |ok_| does. - bool ok_; -}; - -bool IPhotoLibraryParser::Parse(const std::string& library_xml) { - XmlReader reader; - if (!reader.Load(library_xml)) - return false; - - // Find the plist node and then search within that tag. - if (!iapps::SeekToNodeAtCurrentDepth(&reader, "plist")) - return false; - if (!reader.Read()) - return false; - - if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict")) - return false; - - IPhotoLibraryXmlDictReader dict_reader(&reader, &library_); - return dict_reader.Read(); -} - -} // namespace iphoto diff --git a/chrome/utility/media_galleries/iphoto_library_parser.h b/chrome/utility/media_galleries/iphoto_library_parser.h deleted file mode 100644 index 7398fdd..0000000 --- a/chrome/utility/media_galleries/iphoto_library_parser.h +++ /dev/null @@ -1,34 +0,0 @@ -// 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. - -#ifndef CHROME_UTILITY_MEDIA_GALLERIES_IPHOTO_LIBRARY_PARSER_H_ -#define CHROME_UTILITY_MEDIA_GALLERIES_IPHOTO_LIBRARY_PARSER_H_ - -#include <string> - -#include "base/macros.h" -#include "chrome/common/media_galleries/iphoto_library.h" - -namespace iphoto { - -class IPhotoLibraryParser { - public: - IPhotoLibraryParser(); - ~IPhotoLibraryParser(); - - // Returns true if at least one track was found. Malformed track entries - // are silently ignored. - bool Parse(const std::string& xml); - - const parser::Library& library() { return library_; } - - private: - parser::Library library_; - - DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParser); -}; - -} // namespace iphoto - -#endif // CHROME_UTILITY_MEDIA_GALLERIES_IPHOTO_LIBRARY_PARSER_H_ diff --git a/chrome/utility/media_galleries/iphoto_library_parser_unittest.cc b/chrome/utility/media_galleries/iphoto_library_parser_unittest.cc deleted file mode 100644 index 4dc6885..0000000 --- a/chrome/utility/media_galleries/iphoto_library_parser_unittest.cc +++ /dev/null @@ -1,327 +0,0 @@ -// 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 <stdint.h> - -#include "base/logging.h" -#include "base/macros.h" -#include "chrome/common/media_galleries/iphoto_library.h" -#include "chrome/utility/media_galleries/iphoto_library_parser.h" -#include "testing/gtest/include/gtest/gtest.h" - -#define SIMPLE_HEADER() \ - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \ - "<plist version=\"1.0\">" \ - " <dict>" \ - " <key>Archive Path</key>" \ - " <string>/Users/username/px</string>" - -#define ALBUMS_HEADER() \ - " <key>List of Albums</key>" \ - " <array>" - -#define ALBUMS_FOOTER() \ - " </array>" - -#define SIMPLE_ALBUM(id, name, photo1, photo2) \ - " <dict>" \ - " <key>AlbumId</key>" \ - " <integer>" #id "</integer>" \ - " <key>AlbumName</key>" \ - " <string>" name "</string>" \ - " <key>KeyList</key>" \ - " <array>" \ - " <string>" #photo1 "</string>" \ - " <string>" #photo2 "</string>" \ - " </array>" \ - " </dict>" - -#define IMAGE_LIST_HEADER() \ - " <key>Master Image List</key>" \ - " <dict>" - -#define IMAGE_LIST_FOOTER() \ - " </dict>" - -#define SIMPLE_PHOTO(id, guid, path, caption) \ - " <key>" #id "</key>" \ - " <dict>" \ - " <key>MediaType</key>" \ - " <string>Image</string>" \ - " <key>Caption</key>" \ - " <string>" caption "</string>" \ - " <key>GUID</key>" \ - " <string>" #guid "</string>" \ - " <key>ModDateAsTimerInterval</key>" \ - " <string>386221543.0000</string>" \ - " <key>DateAsTimerInterval</key>" \ - " <string>386221543.0000</string>" \ - " <key>DateAsTimerIntervalGMT</key>" \ - " <string>385123456.00</string>" \ - " <key>ImagePath</key>" \ - " <string>" path "</string>" \ - " <key>OriginalPath</key>" \ - " <string>/original" path "</string>" \ - " <key>ThumbPath</key>" \ - " <string>" path "</string>" \ - " </dict>" - -#define SIMPLE_FOOTER() \ - " </dict>" \ - "</plist>" - - // Mismatched key/string tag at ImagePath. -#define MALFORMED_PHOTO1(id, guid, path, caption) \ - " <key>" #id "</key>" \ - " <dict>" \ - " <key>MediaType</key>" \ - " <string>Image</string>" \ - " <key>Caption<key>" \ - " <string>" caption "</string>" \ - " <key>GUID</key>" \ - " <string>" #guid "</string>" \ - " <key>ImagePath</string>" \ - " <string>" path "</string>" \ - " <key>ThumbPath</key>" \ - " <string>" path "</string>" \ - " </dict>" - -// Missing "<" delimiter at ImagePath. -#define MALFORMED_PHOTO2(id, guid, path, caption) \ - " <key>" #id "</key>" \ - " <dict>" \ - " <key>MediaType</key>" \ - " <string>Image</string>" \ - " <key>Caption<key>" \ - " <string>" caption "</string>" \ - " <key>GUID</key>" \ - " <string>" #guid "</string>" \ - " <key>ImagePath/key>" \ - " <string>" path "</string>" \ - " <key>ThumbPath</key>" \ - " <string>" path "</string>" \ - " </dict>" - -namespace iphoto { - -namespace { - -void ComparePhoto(const parser::Photo& a, const parser::Photo& b) { - EXPECT_EQ(a.id, b.id); - EXPECT_EQ(a.location.value(), b.location.value()); - EXPECT_EQ(a.original_location.value(), b.original_location.value()); -} - -void CompareAlbum(const parser::Album& a, const parser::Album& b) { - EXPECT_EQ(a.size(), b.size()); - - parser::Album::const_iterator a_it; - parser::Album::const_iterator b_it; - for (a_it = a.begin(), b_it = b.begin(); - a_it != a.end() && b_it != b.end(); - ++a_it, ++b_it) { - EXPECT_EQ(*a_it, *b_it); - } -} - -void CompareAlbums(const parser::Albums& a, const parser::Albums& b) { - EXPECT_EQ(a.size(), b.size()); - - parser::Albums::const_iterator a_it; - parser::Albums::const_iterator b_it; - for (a_it = a.begin(), b_it = b.begin(); - a_it != a.end() && b_it != b.end(); - ++a_it, ++b_it) { - EXPECT_EQ(a_it->first, b_it->first); - CompareAlbum(a_it->second, b_it->second); - } -} - -void CompareLibrary(const parser::Library& a, const parser::Library& b) { - CompareAlbums(a.albums, b.albums); - - std::set<parser::Photo>::const_iterator a_it; - std::set<parser::Photo>::const_iterator b_it; - for (a_it = a.all_photos.begin(), b_it = b.all_photos.begin(); - a_it != a.all_photos.end() && b_it != b.all_photos.end(); - ++a_it, ++b_it) { - ComparePhoto(*a_it, *b_it); - } -} - -class IPhotoLibraryParserTest : public testing::Test { - public: - IPhotoLibraryParserTest() {} - - void TestParser(bool expected_result, const std::string& xml) { - IPhotoLibraryParser parser; - - EXPECT_EQ(expected_result, parser.Parse(xml)); - if (!expected_result) - return; - - CompareLibrary(expected_library_, parser.library()); - } - - void AddExpectedPhoto(uint32_t id, - const std::string& location, - const std::string& album) { - parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location), - base::FilePath::FromUTF8Unsafe("/original" + location)); - if (!album.empty()) - expected_library_.albums[album].insert(id); - expected_library_.all_photos.insert(photo); - } - - private: - parser::Library expected_library_; - - DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParserTest); -}; - -TEST_F(IPhotoLibraryParserTest, EmptyLibrary) { - TestParser(false, ""); -} - -TEST_F(IPhotoLibraryParserTest, MinimalXML) { - AddExpectedPhoto(1, "/dir/Photo With Space.jpg", ""); - TestParser( - true, - SIMPLE_HEADER() - IMAGE_LIST_HEADER() - SIMPLE_PHOTO(1, 1, "/dir/Photo With Space.jpg", "Photo 1") - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); -} - -TEST_F(IPhotoLibraryParserTest, MultiplePhotos) { - AddExpectedPhoto(1, "/dir/SongA1.jpg", ""); - AddExpectedPhoto(2, "/dir/SongA2.jpg", ""); - AddExpectedPhoto(3, "/dir/SongA3.jpg", ""); - AddExpectedPhoto(4, "/dir/SongB1.jpg", ""); - AddExpectedPhoto(5, "/dir/SongB2.jpg", ""); - AddExpectedPhoto(6, "/dir2/SongB1.jpg", ""); - AddExpectedPhoto(7, "/dir2/SongB2.jpg", ""); - TestParser( - true, - SIMPLE_HEADER() - IMAGE_LIST_HEADER() - SIMPLE_PHOTO(1, 1, "/dir/SongA1.jpg", "Photo 1") - SIMPLE_PHOTO(2, 2, "/dir/SongA2.jpg", "Photo 2") - SIMPLE_PHOTO(3, 3, "/dir/SongA3.jpg", "Photo 3") - SIMPLE_PHOTO(4, 4, "/dir/SongB1.jpg", "Photo 4") - SIMPLE_PHOTO(5, 5, "/dir/SongB2.jpg", "Photo 5") - SIMPLE_PHOTO(6, 6, "/dir2/SongB1.jpg", "Photo 6") - SIMPLE_PHOTO(7, 7, "/dir2/SongB2.jpg", "Photo 7") - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); -} - -TEST_F(IPhotoLibraryParserTest, Albums) { - AddExpectedPhoto(1, "/dir/PhotoA1.jpg", "Album 1"); - AddExpectedPhoto(2, "/dir/PhotoA2.jpg", "Album 1"); - AddExpectedPhoto(3, "/dir/PhotoA3.jpg", "Album 2"); - AddExpectedPhoto(4, "/dir/PhotoB1.jpg", "Album 2"); - AddExpectedPhoto(5, "/dir/PhotoB2.jpg", "Album 3"); - AddExpectedPhoto(6, "/dir2/PhotoB1.jpg", "Album 3"); - AddExpectedPhoto(7, "/dir2/PhotoB2.jpg", ""); - TestParser( - true, - SIMPLE_HEADER() - ALBUMS_HEADER() - SIMPLE_ALBUM(10, "Album 1", 1, 2) - SIMPLE_ALBUM(11, "Album 2", 3, 4) - SIMPLE_ALBUM(11, "Album/3", 5, 6) - ALBUMS_FOOTER() - IMAGE_LIST_HEADER() - SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1") - SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2") - SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3") - SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4") - SIMPLE_PHOTO(5, 5, "/dir/PhotoB2.jpg", "Photo 5") - SIMPLE_PHOTO(6, 6, "/dir2/PhotoB1.jpg", "Photo 6") - SIMPLE_PHOTO(7, 7, "/dir2/PhotoB2.jpg", "Photo 7") - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); -} - -TEST_F(IPhotoLibraryParserTest, MalformedStructure) { - TestParser( - false, - SIMPLE_HEADER() - ALBUMS_HEADER() - ALBUMS_HEADER() - ALBUMS_FOOTER() - SIMPLE_FOOTER()); - - TestParser( - false, - SIMPLE_HEADER() - ALBUMS_HEADER() - ALBUMS_FOOTER() - IMAGE_LIST_HEADER() - IMAGE_LIST_HEADER() - SIMPLE_PHOTO(1, 1, "/bad.jpg", "p1") - IMAGE_LIST_FOOTER() - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); - - TestParser( - false, - SIMPLE_HEADER() - ALBUMS_HEADER() - ALBUMS_FOOTER() - IMAGE_LIST_HEADER() - ALBUMS_HEADER() - SIMPLE_PHOTO(1, 1, "/bad.jpg", "p1") - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); -} - -TEST_F(IPhotoLibraryParserTest, MalformedSyntax) { - TestParser( - false, - SIMPLE_HEADER() - ALBUMS_HEADER() - ALBUMS_FOOTER() - IMAGE_LIST_HEADER() - MALFORMED_PHOTO1(1, 1, "/bad.jpg", "p1") - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); - - TestParser( - false, - SIMPLE_HEADER() - ALBUMS_HEADER() - ALBUMS_FOOTER() - IMAGE_LIST_HEADER() - MALFORMED_PHOTO2(1, 1, "/bad.jpg", "p1") - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); -} - -TEST_F(IPhotoLibraryParserTest, DuplicateAlbumNames) { - AddExpectedPhoto(1, "/dir/PhotoA1.jpg", "Album 1"); - AddExpectedPhoto(2, "/dir/PhotoA2.jpg", "Album 1"); - AddExpectedPhoto(3, "/dir/PhotoA3.jpg", "Album 1(11)"); - AddExpectedPhoto(4, "/dir/PhotoB1.jpg", "Album 1(11)"); - TestParser( - true, - SIMPLE_HEADER() - ALBUMS_HEADER() - SIMPLE_ALBUM(10, "Album 1", 1, 2) - SIMPLE_ALBUM(11, "Album 1", 3, 4) - ALBUMS_FOOTER() - IMAGE_LIST_HEADER() - SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1") - SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2") - SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3") - SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4") - IMAGE_LIST_FOOTER() - SIMPLE_FOOTER()); -} - -} // namespace - -} // namespace iphoto diff --git a/components/storage_monitor/media_storage_util.cc b/components/storage_monitor/media_storage_util.cc index 7b3b2c1..5dbfdcc 100644 --- a/components/storage_monitor/media_storage_util.cc +++ b/components/storage_monitor/media_storage_util.cc @@ -71,7 +71,6 @@ void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { if (type == StorageInfo::FIXED_MASS_STORAGE || type == StorageInfo::ITUNES || - type == StorageInfo::IPHOTO || type == StorageInfo::PICASA) { if (!base::PathExists(base::FilePath::FromUTF8Unsafe(unique_id))) missing_devices.insert(*it); @@ -194,7 +193,6 @@ base::FilePath MediaStorageUtil::FindDevicePathById( if (type == StorageInfo::FIXED_MASS_STORAGE || type == StorageInfo::ITUNES || - type == StorageInfo::IPHOTO || type == StorageInfo::PICASA) { // For this type, the unique_id is the path. return base::FilePath::FromUTF8Unsafe(unique_id); diff --git a/components/storage_monitor/storage_info.cc b/components/storage_monitor/storage_info.cc index a033940..d71f967 100644 --- a/components/storage_monitor/storage_info.cc +++ b/components/storage_monitor/storage_info.cc @@ -22,7 +22,6 @@ const char kMtpPtpPrefix[] = "mtp:"; const char kMacImageCapturePrefix[] = "ic:"; const char kITunesPrefix[] = "itunes:"; const char kPicasaPrefix[] = "picasa:"; -const char kIPhotoPrefix[] = "iphoto:"; base::string16 GetDisplayNameForDevice(uint64_t storage_size_in_bytes, const base::string16& name) { @@ -91,8 +90,6 @@ std::string StorageInfo::MakeDeviceId(Type type, const std::string& unique_id) { return std::string(kITunesPrefix) + unique_id; case PICASA: return std::string(kPicasaPrefix) + unique_id; - case IPHOTO: - return std::string(kIPhotoPrefix) + unique_id; } NOTREACHED(); return std::string(); @@ -121,8 +118,6 @@ bool StorageInfo::CrackDeviceId(const std::string& device_id, found_type = ITUNES; } else if (prefix == kPicasaPrefix) { found_type = PICASA; - } else if (prefix == kIPhotoPrefix) { - found_type = IPHOTO; } else { NOTREACHED(); return false; @@ -161,7 +156,6 @@ bool StorageInfo::IsMassStorageDevice(const std::string& device_id) { type == REMOVABLE_MASS_STORAGE_NO_DCIM || type == FIXED_MASS_STORAGE || type == ITUNES || - type == IPHOTO || type == PICASA); } @@ -172,12 +166,6 @@ bool StorageInfo::IsITunesDevice(const std::string& device_id) { } // static -bool StorageInfo::IsIPhotoDevice(const std::string& device_id) { - Type type; - return CrackDeviceId(device_id, &type, NULL) && type == IPHOTO; -} - -// static bool StorageInfo::IsPicasaDevice(const std::string& device_id) { Type type; return CrackDeviceId(device_id, &type, NULL) && type == PICASA; diff --git a/components/storage_monitor/storage_info.h b/components/storage_monitor/storage_info.h index fc7d520..56abeea 100644 --- a/components/storage_monitor/storage_info.h +++ b/components/storage_monitor/storage_info.h @@ -29,8 +29,6 @@ class StorageInfo { ITUNES, // A Picasa database. PICASA, - // An iPhoto library. - IPHOTO, }; StorageInfo(); @@ -70,8 +68,6 @@ class StorageInfo { static bool IsPicasaDevice(const std::string& device_id); - static bool IsIPhotoDevice(const std::string& device_id); - static bool IsMTPDevice(const std::string& device_id); // Get the display name for the removable device represented by this diff --git a/content/browser/renderer_host/pepper/pepper_file_io_host.cc b/content/browser/renderer_host/pepper/pepper_file_io_host.cc index c3e52a6..eea865b 100644 --- a/content/browser/renderer_host/pepper/pepper_file_io_host.cc +++ b/content/browser/renderer_host/pepper/pepper_file_io_host.cc @@ -198,7 +198,6 @@ int32_t PepperFileIOHost::OnHostMsgOpen( case storage::kFileSystemTypeDeviceMedia: case storage::kFileSystemTypePicasa: case storage::kFileSystemTypeItunes: - case storage::kFileSystemTypeIphoto: break; default: return PP_ERROR_NOACCESS; diff --git a/storage/browser/fileapi/file_system_context.cc b/storage/browser/fileapi/file_system_context.cc index 6d84f1e..8631801 100644 --- a/storage/browser/fileapi/file_system_context.cc +++ b/storage/browser/fileapi/file_system_context.cc @@ -104,7 +104,6 @@ int FileSystemContext::GetPermissionPolicy(FileSystemType type) { FILE_PERMISSION_USE_FILE_PERMISSION; case kFileSystemTypeDeviceMedia: - case kFileSystemTypeIphoto: case kFileSystemTypeItunes: case kFileSystemTypeNativeMedia: case kFileSystemTypePicasa: diff --git a/storage/common/fileapi/file_system_types.h b/storage/common/fileapi/file_system_types.h index 645b759..3f4f942 100644 --- a/storage/common/fileapi/file_system_types.h +++ b/storage/common/fileapi/file_system_types.h @@ -81,9 +81,6 @@ enum FileSystemType { // Indicates a synthetic iTunes filesystem. kFileSystemTypeItunes, - // Indicates a synthetic iPhoto filesystem. - kFileSystemTypeIphoto, - // Indicates a Drive filesystem which provides access to Google Drive. kFileSystemTypeDrive, diff --git a/storage/common/fileapi/file_system_util.cc b/storage/common/fileapi/file_system_util.cc index 3d9384b..3bb9b14 100644 --- a/storage/common/fileapi/file_system_util.cc +++ b/storage/common/fileapi/file_system_util.cc @@ -304,8 +304,6 @@ std::string GetFileSystemTypeString(FileSystemType type) { return "Picasa"; case kFileSystemTypeItunes: return "Itunes"; - case kFileSystemTypeIphoto: - return "Iphoto"; case kFileSystemTypeDrive: return "Drive"; case kFileSystemTypeSyncable: diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index d53cd2d55..3b49155 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -74315,7 +74315,7 @@ To add a new entry, add it with any value and run test to compute valid value. <int value="24" label="RemoveAllGalleryWatch API invocations (obsolete)"/> <int value="25" label="iTunes file system used this session"/> <int value="26" label="Picasa file system used this session"/> - <int value="27" label="iPhoto file system used this session"/> + <int value="27" label="iPhoto file system used this session (obsolete)"/> </enum> <enum name="MediaKeyError" type="int"> |