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