Index: webkit/fileapi/local_file_writer.h |
diff --git a/webkit/fileapi/local_file_writer.h b/webkit/fileapi/local_file_writer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3b1b9adcf91b8844c25555b347cf9fd6680208a6 |
--- /dev/null |
+++ b/webkit/fileapi/local_file_writer.h |
@@ -0,0 +1,81 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_ |
+#define WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_ |
+#pragma once |
+ |
+#include <utility> |
+ |
+#include "base/compiler_specific.h" |
+#include "base/file_path.h" |
+#include "base/platform_file.h" |
+#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.
|
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "webkit/fileapi/file_writer.h" |
+ |
+namespace net { |
+class FileStream; |
+} |
+ |
+namespace fileapi { |
+ |
+// Thin wrapper around net::FileStream |
+class LocalFileWriter : public FileWriter { |
+ public: |
+ LocalFileWriter(const FilePath& file_path); |
+ |
+ // TODO(kinaba): currently this can be called only when there's no in-flight |
+ // 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
|
+ virtual ~LocalFileWriter(); |
+ |
+ // FileWriter overrides. |
+ virtual int Write(net::IOBuffer* buf, int buf_len, |
+ const net::CompletionCallback& callback) OVERRIDE; |
+ virtual int Seek(int64 offset, |
+ const net::Int64CompletionCallback& callback) OVERRIDE; |
+ virtual void Cancel(const net::CompletionCallback& callback) OVERRIDE; |
+ |
+ private: |
+ // 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.
|
+ // called even when it failed to open, so that it can invoke the user-supplied |
+ // callback function kept in the |main_operation| closure. |
+ int InitiateOpen(const net::CompletionCallback& main_operation); |
+ void DidOpen(const net::CompletionCallback& main_operation, int result); |
+ |
+ // Passed as the |main_operation| of InitiateOpen() function. |
+ void ReadyToWrite(net::IOBuffer* buf, int buf_len, |
+ const net::CompletionCallback& callback, |
+ int file_open_result); |
+ void ReadyToSeek(int64 offset, |
+ const net::Int64CompletionCallback& callback, |
+ int file_open_result); |
+ |
+ // Starts an async operation of the underlying FileStream, assuming it is |
+ // already open. |
+ int InitiateWrite(net::IOBuffer* buf, int buf_len, |
+ const net::CompletionCallback& callback); |
+ int InitiateSeek(int64 offset, |
+ const net::Int64CompletionCallback& callback); |
+ |
+ // Handles the completion of an async operation. |
+ void DidWrite(const net::CompletionCallback& callback, int result); |
+ void DidSeek(const net::Int64CompletionCallback& callback, int64 result); |
+ |
+ // Stops the in-flight operation and calls |cancel_callback_| if it has been |
+ // set by Cancel() for the current operation. |
+ bool CancelIfRequested(); |
+ |
+ 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
|
+ scoped_ptr<net::FileStream> stream_impl_; |
+ const FilePath file_path_; |
+ bool has_pending_operation_; |
+ net::CompletionCallback cancel_callback_; |
+ DISALLOW_COPY_AND_ASSIGN(LocalFileWriter); |
+}; |
+ |
+} // namespace fileapi |
+ |
+#endif // WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_ |