Chromium Code Reviews| 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_GDATA_FILE_WRITE_HELPER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_FILE_WRITE_HELPER_H_ | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "base/file_path.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | |
| 12 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | |
| 13 | |
| 14 namespace gdata { | |
| 15 | |
| 16 // This class provides higher level operations for writing to GData files over | |
| 17 // GDataFileSystemInterface. | |
| 18 class FileWriteHelper { | |
| 19 public: | |
| 20 explicit FileWriteHelper(GDataFileSystemInterface* file_system); | |
| 21 ~FileWriteHelper(); | |
| 22 | |
| 23 // Prepares a local temporary file path and passes it to |callback| on the | |
| 24 // blocking thread pool that allows file operations. The modification to | |
| 25 // the file is reflected to GData |path|. If |path| does not exist, a new | |
| 26 // file is created. | |
| 27 // | |
| 28 // Must be called from UI thread. | |
| 29 void PrepareWritableFileAndRun(const FilePath& path, | |
| 30 const OpenFileCallback& callback); | |
| 31 | |
| 32 private: | |
| 33 // Part of PrepareWritableFilePathAndRun(). It tries CreateFile for the case | |
| 34 // file does not exist yet, does OpenFile to download and mark the file as | |
| 35 // dirty, runs |callback|, and finally calls CloseFile. | |
| 36 void PrepareWritableFileAndRunAfterCreateFile( | |
| 37 const FilePath& file_path, | |
| 38 const OpenFileCallback& callback, | |
| 39 GDataFileError result); | |
| 40 void PrepareWritableFileAndRunAfterOpenFile( | |
| 41 const FilePath& file_path, | |
| 42 const OpenFileCallback& callback, | |
| 43 GDataFileError result, | |
| 44 const FilePath& local_cache_path); | |
| 45 void PrepareWritableFileAndRunAfterCallback(const FilePath& file_path); | |
| 46 | |
| 47 // File system owned by GDataSystemService. | |
| 48 GDataFileSystemInterface* file_system_; | |
| 49 | |
| 50 // WeakPtrFactory bound to the UI thread. | |
|
satorux1
2012/08/02 07:37:51
please add
// Note: This should remain the last
kinaba
2012/08/02 08:30:02
Done.
| |
| 51 base::WeakPtrFactory<FileWriteHelper> weak_ptr_factory_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(FileWriteHelper); | |
| 54 }; | |
| 55 | |
| 56 } // namespace gdata | |
| 57 | |
| 58 #endif // CHROME_BROWSER_CHROMEOS_GDATA_FILE_WRITE_HELPER_H_ | |
| OLD | NEW |