Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / content / browser / android / url_request_content_job.h
blob5d3d9336acc44e2f6367bb6e653fa4cd652fb108
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_ANDROID_URL_REQUEST_CONTENT_JOB_H_
6 #define CONTENT_BROWSER_ANDROID_URL_REQUEST_CONTENT_JOB_H_
8 #include <string>
9 #include <vector>
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/common/content_export.h"
15 #include "net/http/http_byte_range.h"
16 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_job.h"
19 namespace base {
20 class TaskRunner;
23 namespace file_util {
24 struct FileInfo;
27 namespace net {
28 class FileStream;
31 namespace content {
33 // A request job that handles reading content URIs
34 class CONTENT_EXPORT URLRequestContentJob : public net::URLRequestJob {
35 public:
36 URLRequestContentJob(
37 net::URLRequest* request,
38 net::NetworkDelegate* network_delegate,
39 const base::FilePath& content_path,
40 const scoped_refptr<base::TaskRunner>& content_task_runner);
42 // net::URLRequestJob:
43 void Start() override;
44 void Kill() override;
45 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override;
46 bool IsRedirectResponse(GURL* location, int* http_status_code) override;
47 bool GetMimeType(std::string* mime_type) const override;
48 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
50 protected:
51 ~URLRequestContentJob() override;
53 private:
54 // Meta information about the content URI. It's used as a member in the
55 // URLRequestContentJob and also passed between threads because disk access is
56 // necessary to obtain it.
57 struct ContentMetaInfo {
58 ContentMetaInfo();
59 // Flag showing whether the content URI exists.
60 bool content_exists;
61 // Size of the content URI.
62 int64 content_size;
63 // Mime type associated with the content URI.
64 std::string mime_type;
67 // Fetches content URI info on a background thread.
68 static void FetchMetaInfo(const base::FilePath& content_path,
69 ContentMetaInfo* meta_info);
71 // Callback after fetching content URI info on a background thread.
72 void DidFetchMetaInfo(const ContentMetaInfo* meta_info);
74 // Callback after opening content URI on a background thread.
75 void DidOpen(int result);
77 // Callback after seeking to the beginning of |byte_range_| in the content URI
78 // on a background thread.
79 void DidSeek(int64 result);
81 // Callback after data is asynchronously read from the content URI into |buf|.
82 void DidRead(scoped_refptr<net::IOBuffer> buf, int result);
84 // The full path of the content URI.
85 base::FilePath content_path_;
87 scoped_ptr<net::FileStream> stream_;
88 ContentMetaInfo meta_info_;
89 const scoped_refptr<base::TaskRunner> content_task_runner_;
91 net::HttpByteRange byte_range_;
92 int64 remaining_bytes_;
94 bool io_pending_;
96 base::WeakPtrFactory<URLRequestContentJob> weak_ptr_factory_;
98 DISALLOW_COPY_AND_ASSIGN(URLRequestContentJob);
101 } // namespace content
103 #endif // CONTENT_BROWSER_ANDROID_URL_REQUEST_CONTENT_JOB_H_