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

Side by Side Diff: webkit/browser/blob/blob_reader.h

Issue 22314003: NavigationController prototype Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: NavController prototype - chrome side Created 7 years, 3 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
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_BROWSER_BLOB_BLOB_READER_H_
6 #define WEBKIT_BROWSER_BLOB_BLOB_READER_H_
7
8 #include <map>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "webkit/browser/blob/file_stream_reader.h"
13 #include "webkit/browser/webkit_storage_browser_export.h"
14 #include "webkit/common/blob/blob_data.h"
15
16 namespace base {
17 class SequencedTaskRunner;
18 }
19
20 namespace fileapi {
21 class FileSystemContext;
22 }
23
24 namespace net {
25 class DrainableIOBuffer;
26 }
27
28 namespace webkit_blob {
29
30 // A reader implementation that will read the contents of a BlobData.
31 // Should only be used on the IO thread. Delete semantics so delete
32 // whenever you like. If deleted with a pending call, the callback
33 // will not be called (per the FileStreamReader interface design).
34 class WEBKIT_STORAGE_BROWSER_EXPORT BlobReader : public FileStreamReader {
35 public:
36 // Constructs a reader that will start reading from |blob_data|.
37 // The filesystem context is needed to support reading file and
38 // filesystem backed blobs.
39 BlobReader(BlobData* blob_data,
40 fileapi::FileSystemContext* file_system_context);
41 virtual ~BlobReader();
42
43 // Must be called prior to making the first call to Read().
44 void SetInitialOffset(int64 position);
45
46 // FileStreamReader impl, GetLength returns the full size of
47 // the BlobData without subtracting the initial offset.
48 virtual int Read(net::IOBuffer* buf, int buf_len,
49 const net::CompletionCallback& callback) OVERRIDE;
50 virtual int64 GetLength(const net::Int64CompletionCallback& callback) OVERRIDE ;
51
52 private:
53 typedef std::map<size_t, FileStreamReader*> IndexToReaderMap;
54
55 // For size computations.
56 void CountSize();
57 void DidGetFileItemLength(size_t index, int64 result);
58 bool AddItemLength(size_t index, int64 item_length);
59 void OnSizeCounted();
60
61 // For reading the blob.
62 int DoRead();
63 void PerformInitialSeek();
64 int ReadLoop();
65 bool ReadItem();
66 void AdvanceItem();
67 void AdvanceBytesRead(int result);
68 bool ReadBytesItem(const BlobData::Item& item, int bytes_to_read);
69 bool ReadFileItem(FileStreamReader* reader, int bytes_to_read);
70 void DidReadFile(int result);
71 int ComputeBytesToRead() const;
72 int OnReadComplete();
73
74 // Called upon an error of any kind.
75 void OnError(int error_code);
76
77 FileStreamReader* GetFileStreamReader(size_t index);
78 void CreateFileStreamReader(size_t index, int64 additional_offset);
79 void DeleteCurrentFileReader();
80
81 base::WeakPtrFactory<BlobReader> weak_factory_;
82 scoped_refptr<BlobData> blob_data_;
83 net::CompletionCallback pending_read_callback_;
84 scoped_refptr<net::IOBuffer> pending_read_buf_;
85 int pending_read_length_;
86 net::Int64CompletionCallback pending_size_callback_;
87 int64 initial_offset_;
88 bool is_counting_size_;
89 bool has_total_size_;
90 bool has_started_reading_;
91
92 // Variables for controlling read from |blob_data_|.
93 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
94 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
95 std::vector<int64> item_length_list_;
96 int64 total_size_;
97 int64 remaining_bytes_;
98 int pending_get_file_info_count_;
99 IndexToReaderMap index_to_reader_;
100 size_t current_item_index_;
101 int64 current_item_offset_;
102
103 // Holds the buffer for read data with the IOBuffer interface.
104 scoped_refptr<net::DrainableIOBuffer> read_buf_;
105
106 // Is set when OnError() is called.
107 int error_;
108
109 DISALLOW_COPY_AND_ASSIGN(BlobReader);
110 };
111
112 } // namespace webkit_blob
113
114 #endif // WEBKIT_BROWSER_BLOB_BLOB_READER_H_
OLDNEW
« no previous file with comments | « webkit/browser/appcache/view_appcache_internals_job.cc ('k') | webkit/browser/blob/blob_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698