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_
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"
33 // A request job that handles reading content URIs
34 class CONTENT_EXPORT URLRequestContentJob
: public net::URLRequestJob
{
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
;
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
;
51 ~URLRequestContentJob() override
;
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
{
59 // Flag showing whether the content URI exists.
61 // Size of the content URI.
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_
;
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_