blob: 21baa2cea9d214ecd737adff10a3035fe5e04062 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_
#define STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_
#include <map>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "net/http/http_byte_range.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_request_job.h"
#include "storage/browser/storage_browser_export.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace net {
class DrainableIOBuffer;
class IOBuffer;
}
namespace storage {
class BlobDataHandle;
class BlobReader;
class FileStreamReader;
class FileSystemContext;
// A request job that handles reading blob URLs.
class STORAGE_EXPORT BlobURLRequestJob
: public net::URLRequestJob {
public:
BlobURLRequestJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate,
BlobDataHandle* blob_handle,
storage::FileSystemContext* file_system_context,
base::SingleThreadTaskRunner* resolving_thread_task_runner);
// net::URLRequestJob methods.
void Start() override;
void Kill() override;
bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override;
bool GetMimeType(std::string* mime_type) const override;
void GetResponseInfo(net::HttpResponseInfo* info) override;
int GetResponseCode() const override;
void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
protected:
~BlobURLRequestJob() override;
private:
typedef std::map<size_t, FileStreamReader*> IndexToReaderMap;
// For preparing for read: get the size, apply the range and perform seek.
void DidStart();
void DidCalculateSize(int result);
void DidReadRawData(int result);
void NotifyFailure(int);
void HeadersCompleted(net::HttpStatusCode status_code);
// Is set when NotifyFailure() is called and reset when DidStart is called.
bool error_;
bool byte_range_set_;
net::HttpByteRange byte_range_;
scoped_ptr<BlobDataHandle> blob_handle_;
scoped_ptr<BlobReader> blob_reader_;
scoped_ptr<net::HttpResponseInfo> response_info_;
base::WeakPtrFactory<BlobURLRequestJob> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJob);
};
} // namespace storage
#endif // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_H_
|