root_delete_helper.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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. 4 5#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_ROOT_DELETE_HELPER_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_ROOT_DELETE_HELPER_H_ 7 8#include "base/basictypes.h" 9#include "base/callback.h" 10#include "base/files/file.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/weak_ptr.h" 13#include "webkit/browser/fileapi/file_system_url.h" 14 15class GURL; 16 17namespace fileapi { 18class FileSystemContext; 19} 20 21namespace sync_file_system { 22 23class LocalFileSyncStatus; 24 25// A helper class to delete the root directory of a given Sync FileSystem. 26// This could happen when AppRoot (or SyncRoot) is deleted by remote operation, 27// and we want to delete all local files + all pending local changes in this 28// case. 29// 30// Expected to be called on and will callback on IO thread. 31class RootDeleteHelper { 32 public: 33 typedef base::Callback<void(base::File::Error)> FileStatusCallback; 34 35 RootDeleteHelper(fileapi::FileSystemContext* file_system_context, 36 LocalFileSyncStatus* sync_status, 37 const fileapi::FileSystemURL& url, 38 const FileStatusCallback& callback); 39 ~RootDeleteHelper(); 40 41 void Run(); 42 43 private: 44 void DidDeleteFileSystem(base::File::Error error); 45 void DidResetFileChangeTracker(); 46 void DidOpenFileSystem(const GURL& root, 47 const std::string& name, 48 base::File::Error error); 49 50 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 51 const fileapi::FileSystemURL url_; 52 FileStatusCallback callback_; 53 54 // Not owned; owner of this instance owns it. 55 LocalFileSyncStatus* sync_status_; 56 57 base::WeakPtrFactory<RootDeleteHelper> weak_factory_; 58 59 DISALLOW_COPY_AND_ASSIGN(RootDeleteHelper); 60}; 61 62} // namespace sync_file_system 63 64#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_ROOT_DELETE_HELPER_H_ 65