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

Side by Side Diff: storage/browser/blob/blob_url_request_job.h

Issue 1376123002: Revert of [Blob] BlobReader class & tests, and removal of all redundant reading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "net/http/http_byte_range.h" 13 #include "net/http/http_byte_range.h"
14 #include "net/http/http_status_code.h" 14 #include "net/http/http_status_code.h"
15 #include "net/url_request/url_request_job.h" 15 #include "net/url_request/url_request_job.h"
16 #include "storage/browser/blob/blob_data_snapshot.h"
16 #include "storage/browser/storage_browser_export.h" 17 #include "storage/browser/storage_browser_export.h"
17 18
18 namespace base { 19 namespace base {
19 class SingleThreadTaskRunner; 20 class SingleThreadTaskRunner;
20 } 21 }
21 22
22 namespace net { 23 namespace net {
23 class DrainableIOBuffer; 24 class DrainableIOBuffer;
24 class IOBuffer; 25 class IOBuffer;
25 } 26 }
26 27
27 namespace storage { 28 namespace storage {
28 29
29 class BlobDataHandle;
30 class BlobReader;
31 class FileStreamReader; 30 class FileStreamReader;
32 class FileSystemContext; 31 class FileSystemContext;
33 32
34 // A request job that handles reading blob URLs. 33 // A request job that handles reading blob URLs.
35 class STORAGE_EXPORT BlobURLRequestJob 34 class STORAGE_EXPORT BlobURLRequestJob
36 : public net::URLRequestJob { 35 : public net::URLRequestJob {
37 public: 36 public:
38 BlobURLRequestJob(net::URLRequest* request, 37 BlobURLRequestJob(net::URLRequest* request,
39 net::NetworkDelegate* network_delegate, 38 net::NetworkDelegate* network_delegate,
40 BlobDataHandle* blob_handle, 39 scoped_ptr<BlobDataSnapshot> blob_data,
41 storage::FileSystemContext* file_system_context, 40 storage::FileSystemContext* file_system_context,
42 base::SingleThreadTaskRunner* resolving_thread_task_runner); 41 base::SingleThreadTaskRunner* resolving_thread_task_runner);
43 42
44 // net::URLRequestJob methods. 43 // net::URLRequestJob methods.
45 void Start() override; 44 void Start() override;
46 void Kill() override; 45 void Kill() override;
47 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; 46 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override;
48 bool GetMimeType(std::string* mime_type) const override; 47 bool GetMimeType(std::string* mime_type) const override;
49 void GetResponseInfo(net::HttpResponseInfo* info) override; 48 void GetResponseInfo(net::HttpResponseInfo* info) override;
50 int GetResponseCode() const override; 49 int GetResponseCode() const override;
51 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; 50 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
52 51
53 protected: 52 protected:
54 ~BlobURLRequestJob() override; 53 ~BlobURLRequestJob() override;
55 54
56 private: 55 private:
57 typedef std::map<size_t, FileStreamReader*> IndexToReaderMap; 56 typedef std::map<size_t, FileStreamReader*> IndexToReaderMap;
58 57
59 // For preparing for read: get the size, apply the range and perform seek. 58 // For preparing for read: get the size, apply the range and perform seek.
60 void DidStart(); 59 void DidStart();
61 void DidCalculateSize(int result); 60 bool AddItemLength(size_t index, int64 item_length);
62 void DidReadRawData(int result); 61 bool CountSize();
62 void DidCountSize(int error);
63 void DidGetFileItemLength(size_t index, int64 result);
64 void Seek(int64 offset);
63 65
66 // For reading the blob.
67 bool ReadLoop(int* bytes_read);
68 bool ReadItem();
69 void AdvanceItem();
70 void AdvanceBytesRead(int result);
71 bool ReadBytesItem(const BlobDataItem& item, int bytes_to_read);
72
73 bool ReadFileItem(FileStreamReader* reader, int bytes_to_read);
74 void DidReadFile(int chunk_number, int result);
75 void DeleteCurrentFileReader();
76
77 bool ReadDiskCacheEntryItem(const BlobDataItem& item, int bytes_to_read);
78 void DidReadDiskCacheEntry(int result);
79
80 int ComputeBytesToRead() const;
81 int BytesReadCompleted();
82
83 // These methods convert the result of blob data reading into response headers
84 // and pass it to URLRequestJob's NotifyDone() or NotifyHeadersComplete().
85 void NotifySuccess();
64 void NotifyFailure(int); 86 void NotifyFailure(int);
65 void HeadersCompleted(net::HttpStatusCode status_code); 87 void HeadersCompleted(net::HttpStatusCode status_code);
66 88
89 // Returns a FileStreamReader for a blob item at |index|.
90 // If the item at |index| is not of file this returns NULL.
91 FileStreamReader* GetFileStreamReader(size_t index);
92
93 // Creates a FileStreamReader for the item at |index| with additional_offset.
94 // If failed, then returns false.
95 bool CreateFileStreamReader(size_t index, int64 additional_offset);
96
97 scoped_ptr<BlobDataSnapshot> blob_data_;
98
99 // Variables for controlling read from |blob_data_|.
100 scoped_refptr<storage::FileSystemContext> file_system_context_;
101 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
102 std::vector<int64> item_length_list_;
103 int64 total_size_;
104 int64 remaining_bytes_;
105 int pending_get_file_info_count_;
106 IndexToReaderMap index_to_reader_;
107 size_t current_item_index_;
108 int64 current_item_offset_;
109
110 // Holds the buffer for read data with the IOBuffer interface.
111 scoped_refptr<net::DrainableIOBuffer> read_buf_;
112
67 // Is set when NotifyFailure() is called and reset when DidStart is called. 113 // Is set when NotifyFailure() is called and reset when DidStart is called.
68 bool error_; 114 bool error_;
69 115
70 bool byte_range_set_; 116 bool byte_range_set_;
71 net::HttpByteRange byte_range_; 117 net::HttpByteRange byte_range_;
72 118
73 scoped_ptr<BlobDataHandle> blob_handle_; 119 // Used to create unique id's for tracing.
74 scoped_ptr<BlobReader> blob_reader_; 120 int current_file_chunk_number_;
121
75 scoped_ptr<net::HttpResponseInfo> response_info_; 122 scoped_ptr<net::HttpResponseInfo> response_info_;
76 123
77 base::WeakPtrFactory<BlobURLRequestJob> weak_factory_; 124 base::WeakPtrFactory<BlobURLRequestJob> weak_factory_;
78 125
79 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob); 126 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob);
80 }; 127 };
81 128
82 } // namespace storage 129 } // namespace storage
83 130
84 #endif // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_ 131 #endif // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_storage_context.cc ('k') | storage/browser/blob/blob_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698