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

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

Issue 2906543002: Add support for reading blobs when using the network service. (Closed)
Patch Set: fix threading issue with weakptr Created 3 years, 6 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
« no previous file with comments | « storage/browser/BUILD.gn ('k') | storage/browser/blob/blob_url_request_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "net/http/http_byte_range.h" 16 #include "net/http/http_byte_range.h"
17 #include "net/http/http_status_code.h" 17 #include "net/http/http_status_code.h"
18 #include "net/url_request/url_request_job.h" 18 #include "net/url_request/url_request_job.h"
19 #include "storage/browser/blob/blob_reader.h" 19 #include "storage/browser/blob/blob_reader.h"
20 #include "storage/browser/storage_browser_export.h" 20 #include "storage/browser/storage_browser_export.h"
21 21
22 namespace base { 22 namespace base {
23 class SingleThreadTaskRunner; 23 class SingleThreadTaskRunner;
24 } 24 }
25 25
26 namespace net { 26 namespace net {
27 class HttpResponseHeaders;
27 class IOBuffer; 28 class IOBuffer;
28 } 29 }
29 30
30 namespace storage { 31 namespace storage {
31 32
32 class BlobDataHandle; 33 class BlobDataHandle;
33 class FileStreamReader; 34 class FileStreamReader;
34 class FileSystemContext; 35 class FileSystemContext;
35 36
36 // A request job that handles reading blob URLs. 37 // A request job that handles reading blob URLs.
37 class STORAGE_EXPORT BlobURLRequestJob 38 class STORAGE_EXPORT BlobURLRequestJob
38 : public net::URLRequestJob { 39 : public net::URLRequestJob {
39 public: 40 public:
40 BlobURLRequestJob(net::URLRequest* request, 41 BlobURLRequestJob(net::URLRequest* request,
41 net::NetworkDelegate* network_delegate, 42 net::NetworkDelegate* network_delegate,
42 BlobDataHandle* blob_handle, 43 BlobDataHandle* blob_handle,
43 storage::FileSystemContext* file_system_context, 44 storage::FileSystemContext* file_system_context,
44 base::SingleThreadTaskRunner* resolving_thread_task_runner); 45 base::SingleThreadTaskRunner* resolving_thread_task_runner);
45 46
46 // net::URLRequestJob methods. 47 // net::URLRequestJob methods.
47 void Start() override; 48 void Start() override;
48 void Kill() override; 49 void Kill() override;
49 int ReadRawData(net::IOBuffer* buf, int buf_size) override; 50 int ReadRawData(net::IOBuffer* buf, int buf_size) override;
50 bool GetMimeType(std::string* mime_type) const override; 51 bool GetMimeType(std::string* mime_type) const override;
51 void GetResponseInfo(net::HttpResponseInfo* info) override; 52 void GetResponseInfo(net::HttpResponseInfo* info) override;
52 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; 53 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
53 54
55 // Helper method to create the HTTP headers for the response.
56 // |blob_handles|, |blob_reader|, |byte_range| and |content_size| are only
57 // used if status_code isn't an error.
58 static scoped_refptr<net::HttpResponseHeaders> GenerateHeaders(
59 net::HttpStatusCode status_code,
60 BlobDataHandle* blob_handle,
61 BlobReader* blob_reader,
62 net::HttpByteRange* byte_range,
63 int64_t* content_size);
64
65 // Helper method to map from a net error to an http status code.
66 static net::HttpStatusCode NetErrorToHttpStatusCode(int error_code);
67
54 protected: 68 protected:
55 ~BlobURLRequestJob() override; 69 ~BlobURLRequestJob() override;
56 70
57 private: 71 private:
58 typedef std::map<size_t, FileStreamReader*> IndexToReaderMap; 72 typedef std::map<size_t, FileStreamReader*> IndexToReaderMap;
59 73
60 // For preparing for read: get the size, apply the range and perform seek. 74 // For preparing for read: get the size, apply the range and perform seek.
61 void DidStart(); 75 void DidStart();
62 void DidCalculateSize(int result); 76 void DidCalculateSize(int result);
63 void DidReadMetadata(BlobReader::Status result); 77 void DidReadMetadata(BlobReader::Status result);
(...skipping 13 matching lines...) Expand all
77 std::unique_ptr<net::HttpResponseInfo> response_info_; 91 std::unique_ptr<net::HttpResponseInfo> response_info_;
78 92
79 base::WeakPtrFactory<BlobURLRequestJob> weak_factory_; 93 base::WeakPtrFactory<BlobURLRequestJob> weak_factory_;
80 94
81 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob); 95 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob);
82 }; 96 };
83 97
84 } // namespace storage 98 } // namespace storage
85 99
86 #endif // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_ 100 #endif // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_
OLDNEW
« no previous file with comments | « storage/browser/BUILD.gn ('k') | storage/browser/blob/blob_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698