return false;
}
-std::vector<std::string> GetVirtualPathComponents(
- const fileapi::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;
- fileapi::VirtualPath::GetComponentsUTF8Unsafe(virtual_path, &result);
- return result;
-}
-
} // namespace
const char kIPhotoAlbumsDir[] = "Albums";
scoped_ptr<fileapi::FileSystemOperationContext> context,
const fileapi::FileSystemURL& url,
const GetFileInfoCallback& callback) {
- GetDataProvider()->RefreshData(
- base::Bind(&IPhotoFileUtil::GetFileInfoWithFreshDataProvider,
- weak_factory_.GetWeakPtr(), base::Passed(&context), url,
- 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(context.Pass(), url, callback, false);
+ } else {
+ data_provider->RefreshData(
+ base::Bind(&IPhotoFileUtil::GetFileInfoWithFreshDataProvider,
+ weak_factory_.GetWeakPtr(), base::Passed(&context), url,
+ callback));
+ }
}
void IPhotoFileUtil::ReadDirectoryOnTaskRunnerThread(
scoped_ptr<fileapi::FileSystemOperationContext> context,
const fileapi::FileSystemURL& url,
const ReadDirectoryCallback& callback) {
- GetDataProvider()->RefreshData(
- base::Bind(&IPhotoFileUtil::ReadDirectoryWithFreshDataProvider,
- weak_factory_.GetWeakPtr(), base::Passed(&context), url,
- 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(context.Pass(), url, callback, false);
+ } else {
+ data_provider->RefreshData(
+ base::Bind(&IPhotoFileUtil::ReadDirectoryWithFreshDataProvider,
+ weak_factory_.GetWeakPtr(), base::Passed(&context), url,
+ callback));
+ }
}
void IPhotoFileUtil::CreateSnapshotFileOnTaskRunnerThread(
scoped_ptr<fileapi::FileSystemOperationContext> context,
const fileapi::FileSystemURL& url,
const CreateSnapshotFileCallback& callback) {
- GetDataProvider()->RefreshData(
- base::Bind(&IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider,
- weak_factory_.GetWeakPtr(), base::Passed(&context), url,
- 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(context.Pass(), url, callback,
+ false);
+ } else {
+ data_provider->RefreshData(
+ base::Bind(&IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider,
+ weak_factory_.GetWeakPtr(), base::Passed(&context), url,
+ callback));
+ }
}
void IPhotoFileUtil::GetFileInfoWithFreshDataProvider(
const fileapi::FileSystemURL& url,
base::File::Info* file_info,
base::FilePath* platform_path) {
- std::vector<std::string> components = GetVirtualPathComponents(url);
+ std::vector<std::string> components;
+ fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components);
if (components.size() == 0) {
return MakeDirectoryFileInfo(file_info);
const fileapi::FileSystemURL& url,
EntryList* file_list) {
DCHECK(file_list->empty());
- std::vector<std::string> components = GetVirtualPathComponents(url);
+ std::vector<std::string> components;
+ fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components);
// Root directory. Child is the /Albums dir.
if (components.size() == 0) {
fileapi::FileSystemOperationContext* context,
const fileapi::FileSystemURL& url,
base::FilePath* local_file_path) {
- std::vector<std::string> components = GetVirtualPathComponents(url);
+ std::vector<std::string> components;
+ fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components);
if (components.size() == 3 && components[0] == kIPhotoAlbumsDir) {
base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum(