Chromium Code Reviews| 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..fd06e411d1e0f42fbbebf0dd5a8d48cd12d4e72d |
| --- /dev/null |
| +++ b/webkit/fileapi/local_file_writer.h |
| @@ -0,0 +1,94 @@ |
| +// 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/callback.h" |
| +#include "base/file_path.h" |
| +#include "base/platform_file.h" |
| +#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 |
|
kinuko
2012/04/23 09:29:57
nit: Please make comments look like sentence and e
kinaba
2012/04/23 10:55:14
Done.
|
| +class LocalFileWriter : public FileWriter { |
| + public: |
| + enum FileOpenMode { |
| + OPEN, |
| + CREATE, |
| + }; |
| + |
| + // Create a writer for the file in the path |file_path| starting from |
| + // |initial_offset|. If |mode| is |CREATE|, |file_path| is set to an empty |
|
kinuko
2012/04/23 09:29:57
This might feel a bit ambiguous-- does this mean T
kinaba
2012/04/23 10:55:14
What I intend is O_CREAT|O_WRONLY|O_TRUNC, which i
kinuko
2012/04/23 12:50:28
I can imagine the situation. I think it's ok to h
kinuko
2012/04/23 13:13:47
By the way we'll also need to check if the given p
|
| + // file when opened. If |mode| is |OPEN|, |file_path| must point to an |
| + // existing file, and the file content will not be changed while opening the |
| + // file. |
| + LocalFileWriter(const FilePath& file_path, |
| + int64 initial_offset, |
| + FileOpenMode mode); |
| + virtual ~LocalFileWriter(); |
| + |
| + // FileWriter overrides. |
| + virtual int Write(net::IOBuffer* buf, int buf_len, |
| + const net::CompletionCallback& callback) OVERRIDE; |
| + virtual void Cancel(const net::CompletionCallback& callback) OVERRIDE; |
| + |
| + private: |
| + // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek(). |
| + // If failed, the error code is returned by calling |error_callback|. |
| + int InitiateOpen(const net::CompletionCallback& error_callback, |
| + const base::Closure& main_operation); |
| + void DidOpen(const net::CompletionCallback& error_callback, |
| + const base::Closure& main_operation, |
| + int result); |
| + |
| + // Seeks to |initial_offset_| and proceeds to |main_operation| if it succeeds. |
| + // If failed, the error code is returned by calling |error_callback|. |
| + void InitiateSeek(const net::CompletionCallback& error_callback, |
| + const base::Closure& main_operation); |
| + void DidSeek(const net::CompletionCallback& error_callback, |
| + const base::Closure& main_operation, |
| + int64 result); |
| + |
| + // Passed as the |main_operation| of InitiateOpen() function. |
| + void ReadyToWrite(net::IOBuffer* buf, int buf_len, |
| + const net::CompletionCallback& callback); |
| + |
| + // Writes asynchronously to the file. |
| + int InitiateWrite(net::IOBuffer* buf, int buf_len, |
| + const net::CompletionCallback& callback); |
| + void DidWrite(const net::CompletionCallback& callback, int result); |
| + |
| + // Stops the in-flight operation and calls |cancel_callback_| if it has been |
| + // set by Cancel() for the current operation. |
| + bool CancelIfRequested(); |
| + |
| + // Initialization parameters. |
| + const FilePath file_path_; |
| + const int file_open_flags_; |
| + const int64 initial_offset_; |
| + |
| + // Current states of the operation. |
| + bool has_pending_operation_; |
| + scoped_ptr<net::FileStream> stream_impl_; |
| + net::CompletionCallback cancel_callback_; |
| + |
| + base::WeakPtrFactory<LocalFileWriter> weak_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(LocalFileWriter); |
| +}; |
| + |
| +} // namespace fileapi |
| + |
| +#endif // WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_ |