This source file includes following definitions.
- GetInstance
- Initialize
- RegisterPicasaFilesystemOnUIThread
- RegisterITunesFilesystemOnUIThread
- RegisterIPhotoFilesystemOnUIThread
- RevokeImportedFilesystemOnUIThread
- ImportedRoot
- PicasaDataProvider
- ITunesDataProvider
- IPhotoDataProvider
- RegisterPicasaFileSystem
- RevokePicasaFileSystem
- RegisterITunesFileSystem
- RevokeITunesFileSystem
- RegisterIPhotoFileSystem
- RevokeIPhotoFileSystem
#include "chrome/browser/media_galleries/imported_media_gallery_registry.h"
#include "base/bind.h"
#include "base/file_util.h"
#include "base/logging.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"
#include "chrome/common/extensions/extension_constants.h"
#include "content/public/browser/browser_thread.h"
#include "webkit/browser/fileapi/external_mount_points.h"
#include "webkit/common/fileapi/file_system_mount_option.h"
using base::Bind;
using fileapi::ExternalMountPoints;
namespace {
static base::LazyInstance<ImportedMediaGalleryRegistry>::Leaky
g_imported_media_gallery_registry = LAZY_INSTANCE_INITIALIZER;
}
ImportedMediaGalleryRegistry* ImportedMediaGalleryRegistry::GetInstance() {
return g_imported_media_gallery_registry.Pointer();
}
void ImportedMediaGalleryRegistry::Initialize() {
base::ThreadRestrictions::AssertIOAllowed();
if (imported_root_.empty()) {
if (!base::CreateTemporaryFile(&imported_root_))
imported_root_ = base::FilePath();
}
}
bool ImportedMediaGalleryRegistry::RegisterPicasaFilesystemOnUIThread(
const std::string& fs_name, const base::FilePath& database_path) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!fs_name.empty());
DCHECK(!database_path.empty());
bool result = false;
#if defined(OS_WIN) || defined(OS_MACOSX)
base::FilePath root = ImportedRoot();
if (root.empty())
return false;
result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
fs_name, fileapi::kFileSystemTypePicasa, fileapi::FileSystemMountOption(),
root.AppendASCII("picasa"));
if (!result)
return result;
picasa_fs_names_.insert(fs_name);
if (picasa_fs_names_.size() == 1) {
MediaFileSystemBackend::MediaTaskRunner()->PostTask(
FROM_HERE,
Bind(&ImportedMediaGalleryRegistry::RegisterPicasaFileSystem,
base::Unretained(this), database_path));
#ifndef NDEBUG
picasa_database_path_ = database_path;
} else {
DCHECK_EQ(picasa_database_path_.value(), database_path.value());
#endif
}
#endif
return result;
}
bool ImportedMediaGalleryRegistry::RegisterITunesFilesystemOnUIThread(
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;
#if defined(OS_WIN) || defined(OS_MACOSX)
base::FilePath root = ImportedRoot();
if (root.empty())
return false;
result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
fs_name, fileapi::kFileSystemTypeItunes, fileapi::FileSystemMountOption(),
root.AppendASCII("itunes"));
if (!result)
return result;
itunes_fs_names_.insert(fs_name);
if (itunes_fs_names_.size() == 1) {
MediaFileSystemBackend::MediaTaskRunner()->PostTask(
FROM_HERE,
Bind(&ImportedMediaGalleryRegistry::RegisterITunesFileSystem,
base::Unretained(this), library_xml_path));
#ifndef NDEBUG
itunes_xml_library_path_ = library_xml_path;
} else {
DCHECK_EQ(itunes_xml_library_path_.value(), library_xml_path.value());
#endif
}
#endif
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;
#if defined(OS_MACOSX)
base::FilePath root = ImportedRoot();
if (root.empty())
return false;
result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
fs_name, fileapi::kFileSystemTypeIphoto, fileapi::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
return result;
}
bool ImportedMediaGalleryRegistry::RevokeImportedFilesystemOnUIThread(
const std::string& fs_name) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
#if defined(OS_WIN) || defined(OS_MACOSX)
if (picasa_fs_names_.erase(fs_name)) {
if (picasa_fs_names_.empty()) {
MediaFileSystemBackend::MediaTaskRunner()->PostTask(
FROM_HERE,
Bind(&ImportedMediaGalleryRegistry::RevokePicasaFileSystem,
base::Unretained(this)));
}
return ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name);
}
if (itunes_fs_names_.erase(fs_name)) {
if (itunes_fs_names_.empty()) {
MediaFileSystemBackend::MediaTaskRunner()->PostTask(
FROM_HERE,
Bind(&ImportedMediaGalleryRegistry::RevokeITunesFileSystem,
base::Unretained(this)));
}
return ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name);
}
#endif
#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
return false;
}
base::FilePath ImportedMediaGalleryRegistry::ImportedRoot() {
DCHECK(!imported_root_.empty());
return imported_root_;
}
#if defined(OS_WIN) || defined(OS_MACOSX)
picasa::PicasaDataProvider*
ImportedMediaGalleryRegistry::PicasaDataProvider() {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
DCHECK(GetInstance()->picasa_data_provider_);
return GetInstance()->picasa_data_provider_.get();
}
itunes::ITunesDataProvider*
ImportedMediaGalleryRegistry::ITunesDataProvider() {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
DCHECK(GetInstance()->itunes_data_provider_);
return GetInstance()->itunes_data_provider_.get();
}
#endif
#if defined(OS_MACOSX)
iphoto::IPhotoDataProvider*
ImportedMediaGalleryRegistry::IPhotoDataProvider() {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
DCHECK(GetInstance()->iphoto_data_provider_);
return GetInstance()->iphoto_data_provider_.get();
}
#endif
ImportedMediaGalleryRegistry::ImportedMediaGalleryRegistry() {}
ImportedMediaGalleryRegistry::~ImportedMediaGalleryRegistry() {
if (!imported_root_.empty())
base::DeleteFile(imported_root_, false);
#if defined(OS_WIN) || defined(OS_MACOSX)
DCHECK_EQ(0U, picasa_fs_names_.size());
DCHECK_EQ(0U, itunes_fs_names_.size());
#endif
#if defined(OS_MACOSX)
DCHECK_EQ(0U, iphoto_fs_names_.size());
#endif
}
#if defined(OS_WIN) || defined(OS_MACOSX)
void ImportedMediaGalleryRegistry::RegisterPicasaFileSystem(
const base::FilePath& database_path) {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
DCHECK(!picasa_data_provider_);
picasa_data_provider_.reset(new picasa::PicasaDataProvider(database_path));
}
void ImportedMediaGalleryRegistry::RevokePicasaFileSystem() {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
DCHECK(picasa_data_provider_);
picasa_data_provider_.reset();
}
void ImportedMediaGalleryRegistry::RegisterITunesFileSystem(
const base::FilePath& xml_library_path) {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
DCHECK(!itunes_data_provider_);
itunes_data_provider_.reset(new itunes::ITunesDataProvider(xml_library_path));
}
void ImportedMediaGalleryRegistry::RevokeITunesFileSystem() {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
DCHECK(itunes_data_provider_);
itunes_data_provider_.reset();
}
#endif
#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