OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 20010 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_BLOB_BLOB_URL_REQUEST_JOB_H_ |
| 6 #define WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ |
| 7 |
| 8 #include "base/ref_counted.h" |
| 9 #include "base/scoped_callback_factory.h" |
| 10 #include "base/scoped_ptr.h" |
| 11 #include "net/base/completion_callback.h" |
| 12 #include "net/base/file_stream.h" |
| 13 #include "net/http/http_byte_range.h" |
| 14 #include "net/url_request/url_request_job.h" |
| 15 #include "webkit/blob/blob_data.h" |
| 16 |
| 17 namespace base { |
| 18 class MessageLoopProxy; |
| 19 } |
| 20 |
| 21 namespace file_util { |
| 22 struct FileInfo; |
| 23 } |
| 24 |
| 25 namespace webkit_blob { |
| 26 |
| 27 // A request job that handles reading blob URLs. |
| 28 class BlobURLRequestJob : public URLRequestJob { |
| 29 public: |
| 30 BlobURLRequestJob(URLRequest* request, |
| 31 BlobData* blob_data, |
| 32 base::MessageLoopProxy* resolving_message_loop_proxy); |
| 33 virtual ~BlobURLRequestJob(); |
| 34 |
| 35 // URLRequestJob methods. |
| 36 virtual void Start(); |
| 37 virtual void Kill(); |
| 38 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); |
| 39 virtual bool GetMimeType(std::string* mime_type) const; |
| 40 virtual void GetResponseInfo(net::HttpResponseInfo* info); |
| 41 virtual int GetResponseCode() const; |
| 42 virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers); |
| 43 |
| 44 private: |
| 45 void ResolveFile(const FilePath& file_path); |
| 46 void CountSize(); |
| 47 void Seek(int64 offset); |
| 48 void AdvanceItem(); |
| 49 void AdvanceBytesRead(int result); |
| 50 bool ReadLoop(int* bytes_read); |
| 51 bool ReadItem(); |
| 52 bool ReadBytes(const BlobData::Item& item, int bytes_to_read); |
| 53 bool ReadFile(const BlobData::Item& item, int bytes_to_read); |
| 54 void HeadersCompleted(int status_code, const std::string& status_txt); |
| 55 int ReadCompleted(); |
| 56 void NotifySuccess(); |
| 57 void NotifyFailure(int); |
| 58 |
| 59 void DidResolve(bool exists, const file_util::FileInfo& file_info); |
| 60 void DidRead(int result); |
| 61 |
| 62 base::ScopedCallbackFactory<BlobURLRequestJob> callback_factory_; |
| 63 scoped_refptr<BlobData> blob_data_; |
| 64 scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; |
| 65 net::CompletionCallbackImpl<BlobURLRequestJob> io_callback_; |
| 66 std::vector<int64> item_length_list_; |
| 67 net::FileStream stream_; |
| 68 size_t item_index_; |
| 69 int64 total_size_; |
| 70 int64 current_item_offset_; |
| 71 int64 remaining_bytes_; |
| 72 scoped_refptr<net::IOBuffer> read_buf_; |
| 73 int read_buf_offset_; |
| 74 int read_buf_size_; |
| 75 int read_buf_remaining_bytes_; |
| 76 bool error_; |
| 77 bool headers_set_; |
| 78 bool byte_range_set_; |
| 79 net::HttpByteRange byte_range_; |
| 80 scoped_ptr<net::HttpResponseInfo> response_info_; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob); |
| 83 }; |
| 84 |
| 85 } // namespace webkit_blob |
| 86 |
| 87 #endif // WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ |
OLD | NEW |