| 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 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 | 9 | 
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" | 
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" | 
| 12 #include "net/http/http_byte_range.h" | 12 #include "net/http/http_byte_range.h" | 
| 13 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" | 
| 14 #include "net/url_request/url_request_job.h" | 14 #include "net/url_request/url_request_job.h" | 
|  | 15 #include "storage/browser/blob/blob_data_snapshot.h" | 
| 15 #include "storage/browser/storage_browser_export.h" | 16 #include "storage/browser/storage_browser_export.h" | 
| 16 #include "storage/common/blob/blob_data.h" |  | 
| 17 | 17 | 
| 18 namespace base { | 18 namespace base { | 
| 19 class MessageLoopProxy; | 19 class MessageLoopProxy; | 
| 20 } | 20 } | 
| 21 | 21 | 
| 22 namespace storage { | 22 namespace storage { | 
| 23 class FileSystemContext; | 23 class FileSystemContext; | 
| 24 } | 24 } | 
| 25 | 25 | 
| 26 namespace net { | 26 namespace net { | 
| 27 class DrainableIOBuffer; | 27 class DrainableIOBuffer; | 
| 28 class IOBuffer; | 28 class IOBuffer; | 
| 29 } | 29 } | 
| 30 | 30 | 
| 31 namespace storage { | 31 namespace storage { | 
| 32 | 32 | 
| 33 class FileStreamReader; | 33 class FileStreamReader; | 
| 34 | 34 | 
| 35 // A request job that handles reading blob URLs. | 35 // A request job that handles reading blob URLs. | 
| 36 class STORAGE_EXPORT BlobURLRequestJob | 36 class STORAGE_EXPORT BlobURLRequestJob | 
| 37     : public net::URLRequestJob { | 37     : public net::URLRequestJob { | 
| 38  public: | 38  public: | 
| 39   BlobURLRequestJob(net::URLRequest* request, | 39   BlobURLRequestJob(net::URLRequest* request, | 
| 40                     net::NetworkDelegate* network_delegate, | 40                     net::NetworkDelegate* network_delegate, | 
| 41                     const scoped_refptr<BlobData>& blob_data, | 41                     scoped_ptr<BlobDataSnapshot> blob_data, | 
| 42                     storage::FileSystemContext* file_system_context, | 42                     storage::FileSystemContext* file_system_context, | 
| 43                     base::MessageLoopProxy* resolving_message_loop_proxy); | 43                     base::MessageLoopProxy* resolving_message_loop_proxy); | 
| 44 | 44 | 
| 45   // net::URLRequestJob methods. | 45   // net::URLRequestJob methods. | 
| 46   void Start() override; | 46   void Start() override; | 
| 47   void Kill() override; | 47   void Kill() override; | 
| 48   bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; | 48   bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; | 
| 49   bool GetMimeType(std::string* mime_type) const override; | 49   bool GetMimeType(std::string* mime_type) const override; | 
| 50   void GetResponseInfo(net::HttpResponseInfo* info) override; | 50   void GetResponseInfo(net::HttpResponseInfo* info) override; | 
| 51   int GetResponseCode() const override; | 51   int GetResponseCode() const override; | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 63   void CountSize(); | 63   void CountSize(); | 
| 64   void DidCountSize(int error); | 64   void DidCountSize(int error); | 
| 65   void DidGetFileItemLength(size_t index, int64 result); | 65   void DidGetFileItemLength(size_t index, int64 result); | 
| 66   void Seek(int64 offset); | 66   void Seek(int64 offset); | 
| 67 | 67 | 
| 68   // For reading the blob. | 68   // For reading the blob. | 
| 69   bool ReadLoop(int* bytes_read); | 69   bool ReadLoop(int* bytes_read); | 
| 70   bool ReadItem(); | 70   bool ReadItem(); | 
| 71   void AdvanceItem(); | 71   void AdvanceItem(); | 
| 72   void AdvanceBytesRead(int result); | 72   void AdvanceBytesRead(int result); | 
| 73   bool ReadBytesItem(const BlobData::Item& item, int bytes_to_read); | 73   bool ReadBytesItem(const BlobDataItem& item, int bytes_to_read); | 
| 74   bool ReadFileItem(FileStreamReader* reader, int bytes_to_read); | 74   bool ReadFileItem(FileStreamReader* reader, int bytes_to_read); | 
| 75 | 75 | 
| 76   void DidReadFile(int result); | 76   void DidReadFile(int result); | 
| 77   void DeleteCurrentFileReader(); | 77   void DeleteCurrentFileReader(); | 
| 78 | 78 | 
| 79   int ComputeBytesToRead() const; | 79   int ComputeBytesToRead() const; | 
| 80   int BytesReadCompleted(); | 80   int BytesReadCompleted(); | 
| 81 | 81 | 
| 82   // These methods convert the result of blob data reading into response headers | 82   // These methods convert the result of blob data reading into response headers | 
| 83   // and pass it to URLRequestJob's NotifyDone() or NotifyHeadersComplete(). | 83   // and pass it to URLRequestJob's NotifyDone() or NotifyHeadersComplete(). | 
| 84   void NotifySuccess(); | 84   void NotifySuccess(); | 
| 85   void NotifyFailure(int); | 85   void NotifyFailure(int); | 
| 86   void HeadersCompleted(net::HttpStatusCode status_code); | 86   void HeadersCompleted(net::HttpStatusCode status_code); | 
| 87 | 87 | 
| 88   // Returns a FileStreamReader for a blob item at |index|. | 88   // Returns a FileStreamReader for a blob item at |index|. | 
| 89   // If the item at |index| is not of file this returns NULL. | 89   // If the item at |index| is not of file this returns NULL. | 
| 90   FileStreamReader* GetFileStreamReader(size_t index); | 90   FileStreamReader* GetFileStreamReader(size_t index); | 
| 91 | 91 | 
| 92   // Creates a FileStreamReader for the item at |index| with additional_offset. | 92   // Creates a FileStreamReader for the item at |index| with additional_offset. | 
| 93   void CreateFileStreamReader(size_t index, int64 additional_offset); | 93   void CreateFileStreamReader(size_t index, int64 additional_offset); | 
| 94 | 94 | 
| 95   scoped_refptr<BlobData> blob_data_; | 95   scoped_ptr<BlobDataSnapshot> blob_data_; | 
| 96 | 96 | 
| 97   // Variables for controlling read from |blob_data_|. | 97   // Variables for controlling read from |blob_data_|. | 
| 98   scoped_refptr<storage::FileSystemContext> file_system_context_; | 98   scoped_refptr<storage::FileSystemContext> file_system_context_; | 
| 99   scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; | 99   scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; | 
| 100   std::vector<int64> item_length_list_; | 100   std::vector<int64> item_length_list_; | 
| 101   int64 total_size_; | 101   int64 total_size_; | 
| 102   int64 remaining_bytes_; | 102   int64 remaining_bytes_; | 
| 103   int pending_get_file_info_count_; | 103   int pending_get_file_info_count_; | 
| 104   IndexToReaderMap index_to_reader_; | 104   IndexToReaderMap index_to_reader_; | 
| 105   size_t current_item_index_; | 105   size_t current_item_index_; | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 117   scoped_ptr<net::HttpResponseInfo> response_info_; | 117   scoped_ptr<net::HttpResponseInfo> response_info_; | 
| 118 | 118 | 
| 119   base::WeakPtrFactory<BlobURLRequestJob> weak_factory_; | 119   base::WeakPtrFactory<BlobURLRequestJob> weak_factory_; | 
| 120 | 120 | 
| 121   DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob); | 121   DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob); | 
| 122 }; | 122 }; | 
| 123 | 123 | 
| 124 }  // namespace storage | 124 }  // namespace storage | 
| 125 | 125 | 
| 126 #endif  // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_ | 126 #endif  // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_ | 
| OLD | NEW | 
|---|