| Index: chrome/browser/chromeos/drive/file_system.cc
|
| diff --git a/chrome/browser/chromeos/drive/file_system.cc b/chrome/browser/chromeos/drive/file_system.cc
|
| index 95de0cf2d5f0550c1c75187d3843d6e76720b7a6..19467fee172fcfea32ce268362a436b30660bed9 100644
|
| --- a/chrome/browser/chromeos/drive/file_system.cc
|
| +++ b/chrome/browser/chromeos/drive/file_system.cc
|
| @@ -39,21 +39,6 @@ namespace {
|
|
|
| //================================ Helper functions ============================
|
|
|
| -// Creates a temporary JSON file representing a document with |alternate_url|
|
| -// and |resource_id| under |document_dir| on blocking pool.
|
| -FileError CreateDocumentJsonFileOnBlockingPool(
|
| - const base::FilePath& document_dir,
|
| - const GURL& alternate_url,
|
| - const std::string& resource_id,
|
| - base::FilePath* temp_file_path) {
|
| - DCHECK(temp_file_path);
|
| -
|
| - if (!file_util::CreateTemporaryFileInDir(document_dir, temp_file_path) ||
|
| - !util::CreateGDocFile(*temp_file_path, alternate_url, resource_id))
|
| - return FILE_ERROR_FAILED;
|
| - return FILE_ERROR_OK;
|
| -}
|
| -
|
| // Helper function for binding |path| to GetResourceEntryWithFilePathCallback
|
| // and create GetResourceEntryCallback.
|
| void RunGetResourceEntryWithFilePathCallback(
|
| @@ -87,106 +72,8 @@ void GetFileCallbackToFileOperationCallbackAdapter(
|
| callback.Run(error);
|
| }
|
|
|
| -// Creates a file with unique name in |dir| and stores the path to |temp_file|.
|
| -// Additionally, sets the permission of the file to allow read access from
|
| -// others and group member users (i.e, "-rw-r--r--").
|
| -// We need this wrapper because Drive cache files may be read from other
|
| -// processes (e.g., cros_disks for mounting zip files).
|
| -//
|
| -// Must be called on the blocking pool.
|
| -bool CreateTemporaryReadableFileInDir(const base::FilePath& dir,
|
| - base::FilePath* temp_file) {
|
| - if (!file_util::CreateTemporaryFileInDir(dir, temp_file))
|
| - return false;
|
| - return file_util::SetPosixFilePermissions(
|
| - *temp_file,
|
| - file_util::FILE_PERMISSION_READ_BY_USER |
|
| - file_util::FILE_PERMISSION_WRITE_BY_USER |
|
| - file_util::FILE_PERMISSION_READ_BY_GROUP |
|
| - file_util::FILE_PERMISSION_READ_BY_OTHERS);
|
| -}
|
| -
|
| } // namespace
|
|
|
| -// FileSystem::GetFileCompleteForOpenParams struct implementation.
|
| -struct FileSystem::GetFileCompleteForOpenParams {
|
| - GetFileCompleteForOpenParams(const OpenFileCallback& callback,
|
| - const std::string& resource_id,
|
| - const std::string& md5);
|
| - OpenFileCallback callback;
|
| - std::string resource_id;
|
| - std::string md5;
|
| -};
|
| -
|
| -FileSystem::GetFileCompleteForOpenParams::GetFileCompleteForOpenParams(
|
| - const OpenFileCallback& callback,
|
| - const std::string& resource_id,
|
| - const std::string& md5)
|
| - : callback(callback),
|
| - resource_id(resource_id),
|
| - md5(md5) {
|
| -}
|
| -
|
| -// FileSystem::GetResolvedFileParams struct implementation.
|
| -struct FileSystem::GetResolvedFileParams {
|
| - GetResolvedFileParams(
|
| - const base::FilePath& drive_file_path,
|
| - const DriveClientContext& context,
|
| - scoped_ptr<ResourceEntry> entry,
|
| - const GetFileContentInitializedCallback& initialized_callback,
|
| - const GetFileCallback& get_file_callback,
|
| - const google_apis::GetContentCallback& get_content_callback)
|
| - : drive_file_path(drive_file_path),
|
| - context(context),
|
| - entry(entry.Pass()),
|
| - initialized_callback(initialized_callback),
|
| - get_file_callback(get_file_callback),
|
| - get_content_callback(get_content_callback) {
|
| - DCHECK(!get_file_callback.is_null());
|
| - DCHECK(this->entry);
|
| - }
|
| -
|
| - void OnError(FileError error) {
|
| - get_file_callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>());
|
| - }
|
| -
|
| - void OnCacheFileFound(const base::FilePath& local_file_path) {
|
| - if (initialized_callback.is_null()) {
|
| - return;
|
| - }
|
| -
|
| - scoped_ptr<ResourceEntry> new_entry(new ResourceEntry(*entry));
|
| - initialized_callback.Run(FILE_ERROR_OK,
|
| - new_entry.Pass(),
|
| - local_file_path,
|
| - base::Closure());
|
| - }
|
| -
|
| - void OnStartDownloading(const base::Closure& cancel_download_closure) {
|
| - if (initialized_callback.is_null()) {
|
| - return;
|
| - }
|
| -
|
| - scoped_ptr<ResourceEntry> new_entry(new ResourceEntry(*entry));
|
| - initialized_callback.Run(FILE_ERROR_OK,
|
| - new_entry.Pass(),
|
| - base::FilePath(),
|
| - cancel_download_closure);
|
| - }
|
| -
|
| - void OnComplete(const base::FilePath& local_file_path) {
|
| - get_file_callback.Run(FILE_ERROR_OK, local_file_path,
|
| - scoped_ptr<ResourceEntry>(new ResourceEntry(*entry)));
|
| - }
|
| -
|
| - const base::FilePath drive_file_path;
|
| - const DriveClientContext context;
|
| - scoped_ptr<ResourceEntry> entry;
|
| - const GetFileContentInitializedCallback initialized_callback;
|
| - const GetFileCallback get_file_callback;
|
| - const google_apis::GetContentCallback get_content_callback;
|
| -};
|
| -
|
| FileSystem::FileSystem(
|
| Profile* profile,
|
| internal::FileCache* cache,
|
| @@ -494,36 +381,12 @@ void FileSystem::GetFileByPath(const base::FilePath& file_path,
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(!callback.is_null());
|
|
|
| - resource_metadata_->GetResourceEntryByPathOnUIThread(
|
| + operations_.EnsureFileDownloaded(
|
| file_path,
|
| - base::Bind(&FileSystem::OnGetResourceEntryCompleteForGetFileByPath,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - file_path,
|
| - callback));
|
| -}
|
| -
|
| -void FileSystem::OnGetResourceEntryCompleteForGetFileByPath(
|
| - const base::FilePath& file_path,
|
| - const GetFileCallback& callback,
|
| - FileError error,
|
| - scoped_ptr<ResourceEntry> entry) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(!callback.is_null());
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>());
|
| - return;
|
| - }
|
| - DCHECK(entry);
|
| -
|
| - GetResolvedFileByPath(
|
| - make_scoped_ptr(new GetResolvedFileParams(
|
| - file_path,
|
| - DriveClientContext(USER_INITIATED),
|
| - entry.Pass(),
|
| - GetFileContentInitializedCallback(),
|
| - callback,
|
| - google_apis::GetContentCallback())));
|
| + DriveClientContext(USER_INITIATED),
|
| + GetFileContentInitializedCallback(),
|
| + google_apis::GetContentCallback(),
|
| + callback);
|
| }
|
|
|
| void FileSystem::GetFileByResourceId(
|
| @@ -560,14 +423,12 @@ void FileSystem::GetFileByResourceIdAfterGetEntry(
|
| return;
|
| }
|
|
|
| - GetResolvedFileByPath(
|
| - make_scoped_ptr(new GetResolvedFileParams(
|
| - file_path,
|
| - context,
|
| - entry.Pass(),
|
| - GetFileContentInitializedCallback(),
|
| - get_file_callback,
|
| - get_content_callback)));
|
| + operations_.EnsureFileDownloaded(
|
| + file_path,
|
| + context,
|
| + GetFileContentInitializedCallback(),
|
| + get_content_callback,
|
| + get_file_callback);
|
| }
|
|
|
| void FileSystem::GetFileContentByPath(
|
| @@ -580,45 +441,15 @@ void FileSystem::GetFileContentByPath(
|
| DCHECK(!get_content_callback.is_null());
|
| DCHECK(!completion_callback.is_null());
|
|
|
| - resource_metadata_->GetResourceEntryByPathOnUIThread(
|
| + operations_.EnsureFileDownloaded(
|
| file_path,
|
| - base::Bind(&FileSystem::GetFileContentByPathAfterGetEntry,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - file_path,
|
| - initialized_callback,
|
| - get_content_callback,
|
| + DriveClientContext(USER_INITIATED),
|
| + initialized_callback,
|
| + get_content_callback,
|
| + base::Bind(&GetFileCallbackToFileOperationCallbackAdapter,
|
| completion_callback));
|
| }
|
|
|
| -void FileSystem::GetFileContentByPathAfterGetEntry(
|
| - const base::FilePath& file_path,
|
| - const GetFileContentInitializedCallback& initialized_callback,
|
| - const google_apis::GetContentCallback& get_content_callback,
|
| - const FileOperationCallback& completion_callback,
|
| - FileError error,
|
| - scoped_ptr<ResourceEntry> entry) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(!initialized_callback.is_null());
|
| - DCHECK(!get_content_callback.is_null());
|
| - DCHECK(!completion_callback.is_null());
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - completion_callback.Run(error);
|
| - return;
|
| - }
|
| -
|
| - DCHECK(entry);
|
| - GetResolvedFileByPath(
|
| - make_scoped_ptr(new GetResolvedFileParams(
|
| - file_path,
|
| - DriveClientContext(USER_INITIATED),
|
| - entry.Pass(),
|
| - initialized_callback,
|
| - base::Bind(&GetFileCallbackToFileOperationCallbackAdapter,
|
| - completion_callback),
|
| - get_content_callback)));
|
| -}
|
| -
|
| void FileSystem::GetResourceEntryByPath(
|
| const base::FilePath& file_path,
|
| const GetResourceEntryCallback& callback) {
|
| @@ -795,316 +626,6 @@ void FileSystem::ReadDirectoryByPathAfterRead(
|
| callback.Run(FILE_ERROR_OK, hide_hosted_docs_, entries.Pass());
|
| }
|
|
|
| -void FileSystem::GetResolvedFileByPath(
|
| - scoped_ptr<GetResolvedFileParams> params) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - if (params->entry->file_info().is_directory()) {
|
| - params->OnError(FILE_ERROR_NOT_A_FILE);
|
| - return;
|
| - }
|
| -
|
| - // The file's entry should have its file specific info.
|
| - DCHECK(params->entry->has_file_specific_info());
|
| -
|
| - // For a hosted document, we create a special JSON file to represent the
|
| - // document instead of fetching the document content in one of the exported
|
| - // formats. The JSON file contains the edit URL and resource ID of the
|
| - // document.
|
| - if (params->entry->file_specific_info().is_hosted_document()) {
|
| - base::FilePath* temp_file_path = new base::FilePath;
|
| - ResourceEntry* entry_ptr = params->entry.get();
|
| - base::PostTaskAndReplyWithResult(
|
| - blocking_task_runner_,
|
| - FROM_HERE,
|
| - base::Bind(&CreateDocumentJsonFileOnBlockingPool,
|
| - cache_->GetCacheDirectoryPath(
|
| - internal::FileCache::CACHE_TYPE_TMP_DOCUMENTS),
|
| - GURL(entry_ptr->file_specific_info().alternate_url()),
|
| - entry_ptr->resource_id(),
|
| - temp_file_path),
|
| - base::Bind(
|
| - &FileSystem::GetResolvedFileByPathAfterCreateDocumentJsonFile,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms),
|
| - base::Owned(temp_file_path)));
|
| - return;
|
| - }
|
| -
|
| - // Returns absolute path of the file if it were cached or to be cached.
|
| - ResourceEntry* entry_ptr = params->entry.get();
|
| - cache_->GetFileOnUIThread(
|
| - entry_ptr->resource_id(),
|
| - entry_ptr->file_specific_info().file_md5(),
|
| - base::Bind(
|
| - &FileSystem::GetResolvedFileByPathAfterGetFileFromCache,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms)));
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterCreateDocumentJsonFile(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - const base::FilePath* file_path,
|
| - FileError error) {
|
| - DCHECK(params);
|
| - DCHECK(file_path);
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - params->OnError(error);
|
| - return;
|
| - }
|
| -
|
| - params->OnCacheFileFound(*file_path);
|
| - params->OnComplete(*file_path);
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterGetFileFromCache(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - FileError error,
|
| - const base::FilePath& cache_file_path) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - // Have we found the file in cache? If so, return it back to the caller.
|
| - if (error == FILE_ERROR_OK) {
|
| - params->OnCacheFileFound(cache_file_path);
|
| - params->OnComplete(cache_file_path);
|
| - return;
|
| - }
|
| -
|
| - // If cache file is not found, try to download the file from the server
|
| - // instead. This logic is rather complicated but here's how this works:
|
| - //
|
| - // Retrieve fresh file metadata from server. We will extract file size and
|
| - // download url from there. Note that the download url is transient.
|
| - //
|
| - // Check if we have enough space, based on the expected file size.
|
| - // - if we don't have enough space, try to free up the disk space
|
| - // - if we still don't have enough space, return "no space" error
|
| - // - if we have enough space, start downloading the file from the server
|
| - GetResolvedFileParams* params_ptr = params.get();
|
| - scheduler_->GetResourceEntry(
|
| - params_ptr->entry->resource_id(),
|
| - params_ptr->context,
|
| - base::Bind(&FileSystem::GetResolvedFileByPathAfterGetResourceEntry,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms)));
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterGetResourceEntry(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - google_apis::GDataErrorCode status,
|
| - scoped_ptr<google_apis::ResourceEntry> entry) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - const FileError error = util::GDataToFileError(status);
|
| - if (error != FILE_ERROR_OK) {
|
| - params->OnError(error);
|
| - return;
|
| - }
|
| -
|
| - // The download URL is:
|
| - // 1) src attribute of content element, on GData WAPI.
|
| - // 2) the value of the key 'downloadUrl', on Drive API v2.
|
| - // In both cases, we can use ResourceEntry::download_url().
|
| - const GURL& download_url = entry->download_url();
|
| -
|
| - // The download URL can be empty for non-downloadable files (such as files
|
| - // shared from others with "prevent downloading by viewers" flag set.)
|
| - if (download_url.is_empty()) {
|
| - params->OnError(FILE_ERROR_ACCESS_DENIED);
|
| - return;
|
| - }
|
| -
|
| - DCHECK_EQ(params->entry->resource_id(), entry->resource_id());
|
| - resource_metadata_->RefreshEntryOnUIThread(
|
| - ConvertToResourceEntry(*entry),
|
| - base::Bind(&FileSystem::GetResolvedFileByPathAfterRefreshEntry,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms),
|
| - download_url));
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterRefreshEntry(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - const GURL& download_url,
|
| - FileError error,
|
| - const base::FilePath& drive_file_path,
|
| - scoped_ptr<ResourceEntry> entry) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - params->OnError(error);
|
| - return;
|
| - }
|
| -
|
| - int64 file_size = entry->file_info().size();
|
| - params->entry = entry.Pass(); // Update the entry in |params|.
|
| - cache_->FreeDiskSpaceIfNeededForOnUIThread(
|
| - file_size,
|
| - base::Bind(&FileSystem::GetResolvedFileByPathAfterFreeDiskSpace,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms),
|
| - download_url));
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterFreeDiskSpace(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - const GURL& download_url,
|
| - bool has_enough_space) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - if (!has_enough_space) {
|
| - // If no enough space, return FILE_ERROR_NO_SPACE.
|
| - params->OnError(FILE_ERROR_NO_SPACE);
|
| - return;
|
| - }
|
| -
|
| - // We have enough disk space. Create download destination file.
|
| - const base::FilePath temp_download_directory = cache_->GetCacheDirectoryPath(
|
| - internal::FileCache::CACHE_TYPE_TMP_DOWNLOADS);
|
| - base::FilePath* file_path = new base::FilePath;
|
| - base::PostTaskAndReplyWithResult(
|
| - blocking_task_runner_,
|
| - FROM_HERE,
|
| - base::Bind(&CreateTemporaryReadableFileInDir,
|
| - temp_download_directory,
|
| - file_path),
|
| - base::Bind(&FileSystem::GetResolveFileByPathAfterCreateTemporaryFile,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms),
|
| - download_url,
|
| - base::Owned(file_path)));
|
| -}
|
| -
|
| -void FileSystem::GetResolveFileByPathAfterCreateTemporaryFile(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - const GURL& download_url,
|
| - base::FilePath* temp_file,
|
| - bool success) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - if (!success) {
|
| - params->OnError(FILE_ERROR_FAILED);
|
| - return;
|
| - }
|
| -
|
| - GetResolvedFileParams* params_ptr = params.get();
|
| - JobID id = scheduler_->DownloadFile(
|
| - params_ptr->drive_file_path,
|
| - *temp_file,
|
| - download_url,
|
| - params_ptr->context,
|
| - base::Bind(&FileSystem::GetResolvedFileByPathAfterDownloadFile,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms)),
|
| - params_ptr->get_content_callback);
|
| - params_ptr->OnStartDownloading(
|
| - base::Bind(&FileSystem::CancelJobInScheduler,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - id));
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterDownloadFile(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - google_apis::GDataErrorCode status,
|
| - const base::FilePath& downloaded_file_path) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - // If user cancels download of a pinned-but-not-fetched file, mark file as
|
| - // unpinned so that we do not sync the file again.
|
| - if (status == google_apis::GDATA_CANCELLED) {
|
| - cache_->GetCacheEntryOnUIThread(
|
| - params->entry->resource_id(),
|
| - params->entry->file_specific_info().file_md5(),
|
| - base::Bind(
|
| - &FileSystem::GetResolvedFileByPathAfterGetCacheEntryForCancel,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - params->entry->resource_id(),
|
| - params->entry->file_specific_info().file_md5()));
|
| - }
|
| -
|
| - FileError error = util::GDataToFileError(status);
|
| - if (error != FILE_ERROR_OK) {
|
| - params->OnError(error);
|
| - return;
|
| - }
|
| -
|
| - ResourceEntry* entry = params->entry.get();
|
| - cache_->StoreOnUIThread(
|
| - entry->resource_id(),
|
| - entry->file_specific_info().file_md5(),
|
| - downloaded_file_path,
|
| - internal::FileCache::FILE_OPERATION_MOVE,
|
| - base::Bind(&FileSystem::GetResolvedFileByPathAfterStore,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms),
|
| - downloaded_file_path));
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterGetCacheEntryForCancel(
|
| - const std::string& resource_id,
|
| - const std::string& md5,
|
| - bool success,
|
| - const FileCacheEntry& cache_entry) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // TODO(hshi): http://crbug.com/127138 notify when file properties change.
|
| - // This allows file manager to clear the "Available offline" checkbox.
|
| - if (success && cache_entry.is_pinned()) {
|
| - cache_->UnpinOnUIThread(resource_id,
|
| - md5,
|
| - base::Bind(&util::EmptyFileOperationCallback));
|
| - }
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterStore(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - const base::FilePath& downloaded_file_path,
|
| - FileError error) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - blocking_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(base::IgnoreResult(&file_util::Delete),
|
| - downloaded_file_path,
|
| - false /* recursive*/));
|
| - params->OnError(error);
|
| - return;
|
| - }
|
| - // Storing to cache changes the "offline available" status, hence notify.
|
| - OnDirectoryChanged(params->drive_file_path.DirName());
|
| -
|
| - ResourceEntry* entry = params->entry.get();
|
| - cache_->GetFileOnUIThread(
|
| - entry->resource_id(),
|
| - entry->file_specific_info().file_md5(),
|
| - base::Bind(&FileSystem::GetResolvedFileByPathAfterGetFile,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(¶ms)));
|
| -}
|
| -
|
| -void FileSystem::GetResolvedFileByPathAfterGetFile(
|
| - scoped_ptr<GetResolvedFileParams> params,
|
| - FileError error,
|
| - const base::FilePath& cache_file) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(params);
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - params->OnError(error);
|
| - return;
|
| - }
|
| - params->OnComplete(cache_file);
|
| -}
|
| -
|
| void FileSystem::RefreshDirectory(
|
| const base::FilePath& directory_path,
|
| const FileOperationCallback& callback) {
|
| @@ -1367,9 +888,12 @@ void FileSystem::OpenFile(const base::FilePath& file_path,
|
| }
|
| open_files_.insert(file_path);
|
|
|
| - resource_metadata_->GetResourceEntryByPathOnUIThread(
|
| + operations_.EnsureFileDownloaded(
|
| file_path,
|
| - base::Bind(&FileSystem::OnGetResourceEntryCompleteForOpenFile,
|
| + DriveClientContext(USER_INITIATED),
|
| + GetFileContentInitializedCallback(),
|
| + google_apis::GetContentCallback(),
|
| + base::Bind(&FileSystem::OpenFileAfterFileDownloaded,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| file_path,
|
| base::Bind(&FileSystem::OnOpenFileFinished,
|
| @@ -1378,24 +902,21 @@ void FileSystem::OpenFile(const base::FilePath& file_path,
|
| callback)));
|
| }
|
|
|
| -void FileSystem::OnGetResourceEntryCompleteForOpenFile(
|
| +void FileSystem::OpenFileAfterFileDownloaded(
|
| const base::FilePath& file_path,
|
| const OpenFileCallback& callback,
|
| FileError error,
|
| + const base::FilePath& local_file_path,
|
| scoped_ptr<ResourceEntry> entry) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(!callback.is_null());
|
| - DCHECK(entry.get() || error != FILE_ERROR_OK);
|
| -
|
| - if (entry.get() && !entry->has_file_specific_info())
|
| - error = FILE_ERROR_NOT_FOUND;
|
|
|
| if (error == FILE_ERROR_OK) {
|
| - if (entry->file_specific_info().file_md5().empty() ||
|
| - entry->file_specific_info().is_hosted_document()) {
|
| - // No support for opening a directory or hosted document.
|
| + DCHECK(entry);
|
| + DCHECK(entry->has_file_specific_info());
|
| + if (entry->file_specific_info().is_hosted_document())
|
| + // No support for opening a hosted document.
|
| error = FILE_ERROR_INVALID_OPERATION;
|
| - }
|
| }
|
|
|
| if (error != FILE_ERROR_OK) {
|
| @@ -1403,60 +924,30 @@ void FileSystem::OnGetResourceEntryCompleteForOpenFile(
|
| return;
|
| }
|
|
|
| - DCHECK(!entry->resource_id().empty());
|
| - // Extract a pointer before we call Pass() so we can use it below.
|
| - ResourceEntry* entry_ptr = entry.get();
|
| - GetResolvedFileByPath(
|
| - make_scoped_ptr(new GetResolvedFileParams(
|
| - file_path,
|
| - DriveClientContext(USER_INITIATED),
|
| - entry.Pass(),
|
| - GetFileContentInitializedCallback(),
|
| - base::Bind(&FileSystem::OnGetFileCompleteForOpenFile,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - GetFileCompleteForOpenParams(
|
| - callback,
|
| - entry_ptr->resource_id(),
|
| - entry_ptr->file_specific_info().file_md5())),
|
| - google_apis::GetContentCallback())));
|
| -}
|
| -
|
| -void FileSystem::OnGetFileCompleteForOpenFile(
|
| - const GetFileCompleteForOpenParams& params,
|
| - FileError error,
|
| - const base::FilePath& file_path,
|
| - scoped_ptr<ResourceEntry> entry) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(!params.callback.is_null());
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - params.callback.Run(error, base::FilePath());
|
| - return;
|
| - }
|
| -
|
| - // OpenFile ensures that the file is a regular file.
|
| - DCHECK(entry && !entry->file_specific_info().is_hosted_document());
|
| -
|
| cache_->MarkDirtyOnUIThread(
|
| - params.resource_id,
|
| - params.md5,
|
| - base::Bind(&FileSystem::OnMarkDirtyInCacheCompleteForOpenFile,
|
| + entry->resource_id(),
|
| + entry->file_specific_info().file_md5(),
|
| + base::Bind(&FileSystem::OpenFileAfterMarkDirty,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| - params));
|
| + entry->resource_id(),
|
| + entry->file_specific_info().file_md5(),
|
| + callback));
|
| }
|
|
|
| -void FileSystem::OnMarkDirtyInCacheCompleteForOpenFile(
|
| - const GetFileCompleteForOpenParams& params,
|
| +void FileSystem::OpenFileAfterMarkDirty(
|
| + const std::string& resource_id,
|
| + const std::string& md5,
|
| + const OpenFileCallback& callback,
|
| FileError error) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(!params.callback.is_null());
|
| + DCHECK(!callback.is_null());
|
|
|
| if (error != FILE_ERROR_OK) {
|
| - params.callback.Run(error, base::FilePath());
|
| + callback.Run(error, base::FilePath());
|
| return;
|
| }
|
|
|
| - cache_->GetFileOnUIThread(params.resource_id, params.md5, params.callback);
|
| + cache_->GetFileOnUIThread(resource_id, md5, callback);
|
| }
|
|
|
| void FileSystem::OnOpenFileFinished(
|
| @@ -1647,8 +1138,4 @@ void FileSystem::CheckLocalModificationAndRunAfterGetFileInfo(
|
| callback.Run(FILE_ERROR_OK, entry.Pass());
|
| }
|
|
|
| -void FileSystem::CancelJobInScheduler(JobID id) {
|
| - scheduler_->CancelJob(id);
|
| -}
|
| -
|
| } // namespace drive
|
|
|