| OLD | NEW |
| 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 WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ | 5 #ifndef WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ |
| 6 #define WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ | 6 #define WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "net/http/http_byte_range.h" | 11 #include "net/http/http_byte_range.h" |
| 12 #include "net/url_request/url_request_job.h" | 12 #include "net/url_request/url_request_job.h" |
| 13 #include "webkit/blob/blob_data.h" | 13 #include "webkit/blob/blob_data.h" |
| 14 #include "webkit/storage/webkit_storage_export.h" | 14 #include "webkit/storage/webkit_storage_export.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class MessageLoopProxy; | 17 class MessageLoopProxy; |
| 18 struct PlatformFileInfo; | 18 struct PlatformFileInfo; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace fileapi { |
| 22 class FileSystemContext; |
| 23 } |
| 24 |
| 21 namespace net { | 25 namespace net { |
| 22 class DrainableIOBuffer; | 26 class DrainableIOBuffer; |
| 23 class IOBuffer; | 27 class IOBuffer; |
| 24 } | 28 } |
| 25 | 29 |
| 26 namespace webkit_blob { | 30 namespace webkit_blob { |
| 27 | 31 |
| 28 class LocalFileStreamReader; | 32 class FileStreamReader; |
| 29 | 33 |
| 30 // A request job that handles reading blob URLs. | 34 // A request job that handles reading blob URLs. |
| 31 class WEBKIT_STORAGE_EXPORT BlobURLRequestJob : public net::URLRequestJob { | 35 class WEBKIT_STORAGE_EXPORT BlobURLRequestJob : public net::URLRequestJob { |
| 32 public: | 36 public: |
| 33 BlobURLRequestJob(net::URLRequest* request, | 37 BlobURLRequestJob(net::URLRequest* request, |
| 34 net::NetworkDelegate* network_delegate, | 38 net::NetworkDelegate* network_delegate, |
| 35 BlobData* blob_data, | 39 BlobData* blob_data, |
| 40 fileapi::FileSystemContext* file_system_context, |
| 36 base::MessageLoopProxy* resolving_message_loop_proxy); | 41 base::MessageLoopProxy* resolving_message_loop_proxy); |
| 37 | 42 |
| 38 // net::URLRequestJob methods. | 43 // net::URLRequestJob methods. |
| 39 virtual void Start() OVERRIDE; | 44 virtual void Start() OVERRIDE; |
| 40 virtual void Kill() OVERRIDE; | 45 virtual void Kill() OVERRIDE; |
| 41 virtual bool ReadRawData(net::IOBuffer* buf, | 46 virtual bool ReadRawData(net::IOBuffer* buf, |
| 42 int buf_size, | 47 int buf_size, |
| 43 int* bytes_read) OVERRIDE; | 48 int* bytes_read) OVERRIDE; |
| 44 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 49 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 45 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; | 50 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
| 46 virtual int GetResponseCode() const OVERRIDE; | 51 virtual int GetResponseCode() const OVERRIDE; |
| 47 virtual void SetExtraRequestHeaders( | 52 virtual void SetExtraRequestHeaders( |
| 48 const net::HttpRequestHeaders& headers) OVERRIDE; | 53 const net::HttpRequestHeaders& headers) OVERRIDE; |
| 49 | 54 |
| 50 protected: | 55 protected: |
| 51 virtual ~BlobURLRequestJob(); | 56 virtual ~BlobURLRequestJob(); |
| 52 | 57 |
| 53 private: | 58 private: |
| 54 typedef std::map<size_t, LocalFileStreamReader*> IndexToReaderMap; | 59 typedef std::map<size_t, FileStreamReader*> IndexToReaderMap; |
| 55 | 60 |
| 56 // For preparing for read: get the size, apply the range and perform seek. | 61 // For preparing for read: get the size, apply the range and perform seek. |
| 57 void DidStart(); | 62 void DidStart(); |
| 58 void CountSize(); | 63 void CountSize(); |
| 59 void DidCountSize(int error); | 64 void DidCountSize(int error); |
| 60 void DidGetFileItemLength(size_t index, int64 result); | 65 void DidGetFileItemLength(size_t index, int64 result); |
| 61 void Seek(int64 offset); | 66 void Seek(int64 offset); |
| 62 | 67 |
| 63 // For reading the blob. | 68 // For reading the blob. |
| 64 bool ReadLoop(int* bytes_read); | 69 bool ReadLoop(int* bytes_read); |
| 65 bool ReadItem(); | 70 bool ReadItem(); |
| 66 void AdvanceItem(); | 71 void AdvanceItem(); |
| 67 void AdvanceBytesRead(int result); | 72 void AdvanceBytesRead(int result); |
| 68 bool ReadBytesItem(const BlobData::Item& item, int bytes_to_read); | 73 bool ReadBytesItem(const BlobData::Item& item, int bytes_to_read); |
| 69 bool ReadFileItem(LocalFileStreamReader* reader, int bytes_to_read); | 74 bool ReadFileItem(FileStreamReader* reader, int bytes_to_read); |
| 70 | 75 |
| 71 void DidReadFile(int result); | 76 void DidReadFile(int result); |
| 72 void DeleteCurrentFileReader(); | 77 void DeleteCurrentFileReader(); |
| 73 | 78 |
| 74 int ComputeBytesToRead() const; | 79 int ComputeBytesToRead() const; |
| 75 int BytesReadCompleted(); | 80 int BytesReadCompleted(); |
| 76 | 81 |
| 77 void NotifySuccess(); | 82 void NotifySuccess(); |
| 78 void NotifyFailure(int); | 83 void NotifyFailure(int); |
| 79 void HeadersCompleted(int status_code, const std::string& status_txt); | 84 void HeadersCompleted(int status_code, const std::string& status_txt); |
| 80 | 85 |
| 81 // Returns a LocalFileStreamReader for a blob item at |index|. | 86 // Returns a FileStreamReader for a blob item at |index|. |
| 82 // If the item at |index| is not of TYPE_FILE this returns NULL. | 87 // If the item at |index| is not of file this returns NULL. |
| 83 LocalFileStreamReader* GetFileStreamReader(size_t index); | 88 FileStreamReader* GetFileStreamReader(size_t index); |
| 84 | 89 |
| 85 // Creates a FileStreamReader for the item at |index| with additional_offset. | 90 // Creates a FileStreamReader for the item at |index| with additional_offset. |
| 86 void CreateFileStreamReader(size_t index, int64 additional_offset); | 91 void CreateFileStreamReader(size_t index, int64 additional_offset); |
| 87 | 92 |
| 88 base::WeakPtrFactory<BlobURLRequestJob> weak_factory_; | 93 base::WeakPtrFactory<BlobURLRequestJob> weak_factory_; |
| 89 scoped_refptr<BlobData> blob_data_; | 94 scoped_refptr<BlobData> blob_data_; |
| 95 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 90 scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; | 96 scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; |
| 91 std::vector<int64> item_length_list_; | 97 std::vector<int64> item_length_list_; |
| 92 int64 total_size_; | 98 int64 total_size_; |
| 93 int64 remaining_bytes_; | 99 int64 remaining_bytes_; |
| 94 int pending_get_file_info_count_; | 100 int pending_get_file_info_count_; |
| 95 IndexToReaderMap index_to_reader_; | 101 IndexToReaderMap index_to_reader_; |
| 96 size_t current_item_index_; | 102 size_t current_item_index_; |
| 97 int64 current_item_offset_; | 103 int64 current_item_offset_; |
| 98 scoped_refptr<net::DrainableIOBuffer> read_buf_; | 104 scoped_refptr<net::DrainableIOBuffer> read_buf_; |
| 99 bool error_; | 105 bool error_; |
| 100 bool headers_set_; | 106 bool headers_set_; |
| 101 bool byte_range_set_; | 107 bool byte_range_set_; |
| 102 net::HttpByteRange byte_range_; | 108 net::HttpByteRange byte_range_; |
| 103 scoped_ptr<net::HttpResponseInfo> response_info_; | 109 scoped_ptr<net::HttpResponseInfo> response_info_; |
| 104 | 110 |
| 105 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob); | 111 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob); |
| 106 }; | 112 }; |
| 107 | 113 |
| 108 } // namespace webkit_blob | 114 } // namespace webkit_blob |
| 109 | 115 |
| 110 #endif // WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ | 116 #endif // WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_ |
| OLD | NEW |