Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / sync_file_system / local / root_delete_helper.cc
blob63a90008b862a5e082a7edde3cea69a640842afc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/local/root_delete_helper.h"
7 #include "base/sequenced_task_runner.h"
8 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
9 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h"
10 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
11 #include "chrome/browser/sync_file_system/logger.h"
12 #include "chrome/browser/sync_file_system/sync_callbacks.h"
13 #include "storage/browser/fileapi/file_system_context.h"
14 #include "storage/browser/fileapi/file_system_url.h"
15 #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h"
16 #include "storage/common/fileapi/file_system_util.h"
18 namespace sync_file_system {
20 namespace {
22 // This runs on FileSystemContext's default_file_task_runner.
23 void ResetFileChangeTracker(storage::FileSystemContext* file_system_context,
24 const storage::FileSystemURL& url) {
25 DCHECK(file_system_context->default_file_task_runner()->
26 RunsTasksOnCurrentThread());
27 SyncFileSystemBackend* backend =
28 SyncFileSystemBackend::GetBackend(file_system_context);
29 DCHECK(backend);
30 DCHECK(backend->change_tracker());
31 backend->change_tracker()->ResetForFileSystem(url.origin(), url.type());
34 } // namespace
36 RootDeleteHelper::RootDeleteHelper(
37 storage::FileSystemContext* file_system_context,
38 LocalFileSyncStatus* sync_status,
39 const storage::FileSystemURL& url,
40 const FileStatusCallback& callback)
41 : file_system_context_(file_system_context),
42 url_(url),
43 callback_(callback),
44 sync_status_(sync_status),
45 weak_factory_(this) {
46 DCHECK(file_system_context_.get());
47 DCHECK(url_.is_valid());
48 DCHECK(!callback_.is_null());
49 DCHECK(sync_status_);
50 // This is expected to run on the filesystem root.
51 DCHECK(storage::VirtualPath::IsRootPath(url.path()));
54 RootDeleteHelper::~RootDeleteHelper() {
57 void RootDeleteHelper::Run() {
58 util::Log(logging::LOG_VERBOSE, FROM_HERE,
59 "Deleting the entire local filesystem for remote root deletion: "
60 "%s", url_.DebugString().c_str());
62 file_system_context_->DeleteFileSystem(
63 url_.origin(), url_.type(),
64 base::Bind(&RootDeleteHelper::DidDeleteFileSystem,
65 weak_factory_.GetWeakPtr()));
68 void RootDeleteHelper::DidDeleteFileSystem(base::File::Error error) {
69 // Ignore errors, no idea how to deal with it.
71 DCHECK(!sync_status_->IsWritable(url_));
72 DCHECK(!sync_status_->IsWriting(url_));
74 // All writes to the entire file system must be now blocked, so we have
75 // to be able to safely reset the local changes and sync statuses for it.
76 // TODO(kinuko): This should be probably automatically handled in
77 // DeleteFileSystem via QuotaUtil::DeleteOriginDataOnFileThread.
78 file_system_context_->default_file_task_runner()->PostTaskAndReply(
79 FROM_HERE,
80 base::Bind(&ResetFileChangeTracker, file_system_context_, url_),
81 base::Bind(&RootDeleteHelper::DidResetFileChangeTracker,
82 weak_factory_.GetWeakPtr()));
85 void RootDeleteHelper::DidResetFileChangeTracker() {
86 DCHECK(!sync_status_->IsWritable(url_));
87 DCHECK(!sync_status_->IsWriting(url_));
89 // Reopening the filesystem.
90 file_system_context_->sandbox_delegate()->OpenFileSystem(
91 url_.origin(),
92 url_.type(),
93 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
94 base::Bind(&RootDeleteHelper::DidOpenFileSystem,
95 weak_factory_.GetWeakPtr()),
96 GURL());
99 void RootDeleteHelper::DidOpenFileSystem(const GURL& /* root */,
100 const std::string& /* name */,
101 base::File::Error error) {
102 FileStatusCallback callback = callback_;
103 callback.Run(error);
106 } // namespace sync_file_system