Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: webkit/fileapi/local_file_writer.h

Issue 10126004: fileapi: FileWriter and LocalFileWriter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: #include Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/file_writer.h ('k') | webkit/fileapi/local_file_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/callback.h"
13 #include "base/file_path.h"
14 #include "base/platform_file.h"
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 // This class is a thin wrapper around net::FileStream for writing local files.
26 class LocalFileWriter : public FileWriter {
27 public:
28 // Create a writer for the existing file in the path |file_path| starting from
29 // |initial_offset|.
30 LocalFileWriter(const FilePath& file_path, int64 initial_offset);
31 virtual ~LocalFileWriter();
32
33 // FileWriter overrides.
34 virtual int Write(net::IOBuffer* buf, int buf_len,
35 const net::CompletionCallback& callback) OVERRIDE;
36 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE;
37
38 private:
39 // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek().
40 // If failed, the error code is returned by calling |error_callback|.
41 int InitiateOpen(const net::CompletionCallback& error_callback,
42 const base::Closure& main_operation);
43 void DidOpen(const net::CompletionCallback& error_callback,
44 const base::Closure& main_operation,
45 int result);
46
47 // Seeks to |initial_offset_| and proceeds to |main_operation| if it succeeds.
48 // If failed, the error code is returned by calling |error_callback|.
49 void InitiateSeek(const net::CompletionCallback& error_callback,
50 const base::Closure& main_operation);
51 void DidSeek(const net::CompletionCallback& error_callback,
52 const base::Closure& main_operation,
53 int64 result);
54
55 // Passed as the |main_operation| of InitiateOpen() function.
56 void ReadyToWrite(net::IOBuffer* buf, int buf_len,
57 const net::CompletionCallback& callback);
58
59 // Writes asynchronously to the file.
60 int InitiateWrite(net::IOBuffer* buf, int buf_len,
61 const net::CompletionCallback& callback);
62 void DidWrite(const net::CompletionCallback& callback, int result);
63
64 // Stops the in-flight operation and calls |cancel_callback_| if it has been
65 // set by Cancel() for the current operation.
66 bool CancelIfRequested();
67
68 // Initialization parameters.
69 const FilePath file_path_;
70 const int64 initial_offset_;
71
72 // Current states of the operation.
73 bool has_pending_operation_;
74 scoped_ptr<net::FileStream> stream_impl_;
75 net::CompletionCallback cancel_callback_;
76
77 base::WeakPtrFactory<LocalFileWriter> weak_factory_;
78 DISALLOW_COPY_AND_ASSIGN(LocalFileWriter);
79 };
80
81 } // namespace fileapi
82
83 #endif // WEBKIT_FILEAPI_LOCAL_FILE_WRITER_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/file_writer.h ('k') | webkit/fileapi/local_file_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698