This source file includes following definitions.
- ResetFileChangeTracker
- weak_factory_
- Run
- DidDeleteFileSystem
- DidResetFileChangeTracker
- DidOpenFileSystem
#include "chrome/browser/sync_file_system/local/root_delete_helper.h"
#include "base/sequenced_task_runner.h"
#include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
#include "chrome/browser/sync_file_system/local/local_file_sync_status.h"
#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
#include "chrome/browser/sync_file_system/logger.h"
#include "chrome/browser/sync_file_system/sync_callbacks.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/file_system_url.h"
#include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h"
#include "webkit/common/fileapi/file_system_util.h"
namespace sync_file_system {
namespace {
void ResetFileChangeTracker(
fileapi::FileSystemContext* file_system_context,
const fileapi::FileSystemURL& url) {
DCHECK(file_system_context->default_file_task_runner()->
RunsTasksOnCurrentThread());
SyncFileSystemBackend* backend =
SyncFileSystemBackend::GetBackend(file_system_context);
DCHECK(backend);
DCHECK(backend->change_tracker());
backend->change_tracker()->ResetForFileSystem(url.origin(), url.type());
}
}
RootDeleteHelper::RootDeleteHelper(
fileapi::FileSystemContext* file_system_context,
LocalFileSyncStatus* sync_status,
const fileapi::FileSystemURL& url,
const FileStatusCallback& callback)
: file_system_context_(file_system_context),
url_(url),
callback_(callback),
sync_status_(sync_status),
weak_factory_(this) {
DCHECK(file_system_context_);
DCHECK(url_.is_valid());
DCHECK(!callback_.is_null());
DCHECK(sync_status_);
DCHECK(fileapi::VirtualPath::IsRootPath(url.path()));
}
RootDeleteHelper::~RootDeleteHelper() {
}
void RootDeleteHelper::Run() {
util::Log(logging::LOG_VERBOSE, FROM_HERE,
"Deleting the entire local filesystem for remote root deletion: "
"%s", url_.DebugString().c_str());
file_system_context_->DeleteFileSystem(
url_.origin(), url_.type(),
base::Bind(&RootDeleteHelper::DidDeleteFileSystem,
weak_factory_.GetWeakPtr()));
}
void RootDeleteHelper::DidDeleteFileSystem(base::File::Error error) {
DCHECK(!sync_status_->IsWritable(url_));
DCHECK(!sync_status_->IsWriting(url_));
file_system_context_->default_file_task_runner()->PostTaskAndReply(
FROM_HERE,
base::Bind(&ResetFileChangeTracker, file_system_context_, url_),
base::Bind(&RootDeleteHelper::DidResetFileChangeTracker,
weak_factory_.GetWeakPtr()));
}
void RootDeleteHelper::DidResetFileChangeTracker() {
DCHECK(!sync_status_->IsWritable(url_));
DCHECK(!sync_status_->IsWriting(url_));
file_system_context_->sandbox_delegate()->OpenFileSystem(
url_.origin(), url_.type(),
fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
base::Bind(&RootDeleteHelper::DidOpenFileSystem,
weak_factory_.GetWeakPtr()), GURL());
}
void RootDeleteHelper::DidOpenFileSystem(const GURL& ,
const std::string& ,
base::File::Error error) {
FileStatusCallback callback = callback_;
callback.Run(error);
}
}