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 WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_ | |
| 6 #define WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <utility> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/file_path.h" | |
| 13 #include "base/platform_file.h" | |
| 14 #include "base/memory/ref_counted.h" | |
|
kinuko
2012/04/20 11:26:37
Do we need this?
kinaba
2012/04/23 08:56:41
No. Removed.
| |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "webkit/fileapi/file_writer.h" | |
| 18 | |
| 19 namespace net { | |
| 20 class FileStream; | |
| 21 } | |
| 22 | |
| 23 namespace fileapi { | |
| 24 | |
| 25 // Thin wrapper around net::FileStream | |
| 26 class LocalFileWriter : public FileWriter { | |
| 27 public: | |
| 28 LocalFileWriter(const FilePath& file_path); | |
| 29 | |
| 30 // TODO(kinaba): currently this can be called only when there's no in-flight | |
| 31 // operations. Can we loosen it? | |
|
kinuko
2012/04/20 11:26:37
I think it's ok (if we make it clear on FileWriter
kinaba
2012/04/23 08:56:41
Removed the restriction (removed DCHECK()'s for wa
| |
| 32 virtual ~LocalFileWriter(); | |
| 33 | |
| 34 // FileWriter overrides. | |
| 35 virtual int Write(net::IOBuffer* buf, int buf_len, | |
| 36 const net::CompletionCallback& callback) OVERRIDE; | |
| 37 virtual int Seek(int64 offset, | |
| 38 const net::Int64CompletionCallback& callback) OVERRIDE; | |
| 39 virtual void Cancel(const net::CompletionCallback& callback) OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 // Opens the file stream and then call |main_operation|. |main_operation| is | |
|
kinuko
2012/04/20 11:26:37
nit: call -> calls
kinaba
2012/04/23 08:56:41
Done.
| |
| 43 // called even when it failed to open, so that it can invoke the user-supplied | |
| 44 // callback function kept in the |main_operation| closure. | |
| 45 int InitiateOpen(const net::CompletionCallback& main_operation); | |
| 46 void DidOpen(const net::CompletionCallback& main_operation, int result); | |
| 47 | |
| 48 // Passed as the |main_operation| of InitiateOpen() function. | |
| 49 void ReadyToWrite(net::IOBuffer* buf, int buf_len, | |
| 50 const net::CompletionCallback& callback, | |
| 51 int file_open_result); | |
| 52 void ReadyToSeek(int64 offset, | |
| 53 const net::Int64CompletionCallback& callback, | |
| 54 int file_open_result); | |
| 55 | |
| 56 // Starts an async operation of the underlying FileStream, assuming it is | |
| 57 // already open. | |
| 58 int InitiateWrite(net::IOBuffer* buf, int buf_len, | |
| 59 const net::CompletionCallback& callback); | |
| 60 int InitiateSeek(int64 offset, | |
| 61 const net::Int64CompletionCallback& callback); | |
| 62 | |
| 63 // Handles the completion of an async operation. | |
| 64 void DidWrite(const net::CompletionCallback& callback, int result); | |
| 65 void DidSeek(const net::Int64CompletionCallback& callback, int64 result); | |
| 66 | |
| 67 // Stops the in-flight operation and calls |cancel_callback_| if it has been | |
| 68 // set by Cancel() for the current operation. | |
| 69 bool CancelIfRequested(); | |
| 70 | |
| 71 base::WeakPtrFactory<LocalFileWriter> weak_factory_; | |
|
kinuko
2012/04/20 11:26:37
If we don't allow deleting this while there's an a
kinaba
2012/04/23 08:56:41
Changed the semantics to allow delete while alive
| |
| 72 scoped_ptr<net::FileStream> stream_impl_; | |
| 73 const FilePath file_path_; | |
| 74 bool has_pending_operation_; | |
| 75 net::CompletionCallback cancel_callback_; | |
| 76 DISALLOW_COPY_AND_ASSIGN(LocalFileWriter); | |
| 77 }; | |
| 78 | |
| 79 } // namespace fileapi | |
| 80 | |
| 81 #endif // WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_ | |
| OLD | NEW |