| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_CHROMEOS_DRIVE_FILE_WRITE_HELPER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_HELPER_H_ | |
| 7 | |
| 8 #include "base/callback_forward.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "chrome/browser/chromeos/drive/file_errors.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class FilePath; | |
| 14 } | |
| 15 | |
| 16 namespace drive { | |
| 17 | |
| 18 class FileSystemInterface; | |
| 19 | |
| 20 // This class provides higher level operations for writing to Drive files over | |
| 21 // FileSystemInterface. | |
| 22 class FileWriteHelper { | |
| 23 public: | |
| 24 // Callback for PrepareWritableFileAndRun. | |
| 25 typedef base::Callback<void(FileError error, | |
| 26 const base::FilePath& file_path)> | |
| 27 OpenFileCallback; | |
| 28 | |
| 29 explicit FileWriteHelper(FileSystemInterface* file_system); | |
| 30 ~FileWriteHelper(); | |
| 31 | |
| 32 // Prepares a local temporary file path and passes it to |callback| on the | |
| 33 // blocking thread pool that allows file operations. The modification to | |
| 34 // the file is reflected to GData |path|. If |path| does not exist, a new | |
| 35 // file is created. | |
| 36 // | |
| 37 // Must be called from UI thread. | |
| 38 void PrepareWritableFileAndRun(const base::FilePath& path, | |
| 39 const OpenFileCallback& callback); | |
| 40 | |
| 41 private: | |
| 42 // Part of PrepareWritableFilePathAndRun(). It tries CreateFile for the case | |
| 43 // file does not exist yet, does OpenFile to download and mark the file as | |
| 44 // dirty, runs |callback|, and finally closes the file. | |
| 45 void PrepareWritableFileAndRunAfterOpenFile( | |
| 46 const base::FilePath& file_path, | |
| 47 const OpenFileCallback& callback, | |
| 48 FileError result, | |
| 49 const base::FilePath& local_cache_path, | |
| 50 const base::Closure& close_callback); | |
| 51 | |
| 52 FileSystemInterface* file_system_; // Owned by DriveIntegrationService. | |
| 53 | |
| 54 // WeakPtrFactory bound to the UI thread. | |
| 55 // Note: This should remain the last member so it'll be destroyed and | |
| 56 // invalidate its weak pointers before any other members are destroyed. | |
| 57 base::WeakPtrFactory<FileWriteHelper> weak_ptr_factory_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(FileWriteHelper); | |
| 60 }; | |
| 61 | |
| 62 } // namespace drive | |
| 63 | |
| 64 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_HELPER_H_ | |
| OLD | NEW |