1 // Copyright 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 CHROME_BROWSER_CHROMEOS_FILEAPI_EXTERNAL_FILE_URL_REQUEST_JOB_H_
6 #define CHROME_BROWSER_CHROMEOS_FILEAPI_EXTERNAL_FILE_URL_REQUEST_JOB_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/chromeos/drive/file_errors.h"
14 #include "net/base/net_errors.h"
15 #include "net/http/http_byte_range.h"
16 #include "net/url_request/url_request_job.h"
17 #include "storage/browser/blob/file_stream_reader.h"
18 #include "storage/browser/fileapi/file_system_url.h"
22 class NetworkDelegate
;
28 // ExternalFileURLRequestJob is the gateway between network-level drive:...
29 // requests for drive resources and FileSystem. It exposes content URLs
30 // formatted as drive:<drive-file-path>.
31 // The methods should be run on IO thread.
32 // TODO(hirono): After removing MHTML support, stop to use the special
33 // externalfile: scheme and use filesystem: URL directly. crbug.com/415455
34 class ExternalFileURLRequestJob
: public net::URLRequestJob
{
36 // Scope of isolated file system.
37 class IsolatedFileSystemScope
{
39 explicit IsolatedFileSystemScope(const std::string
& file_system_id
);
40 ~IsolatedFileSystemScope();
43 std::string file_system_id_
;
44 DISALLOW_COPY_AND_ASSIGN(IsolatedFileSystemScope
);
47 // Callback to take results from an internal helper defined in
48 // drive_url_request_job.cc.
49 typedef base::Callback
<void(
51 const scoped_refptr
<storage::FileSystemContext
>& file_system_context
,
52 scoped_ptr
<IsolatedFileSystemScope
> isolated_file_system_scope
,
53 const storage::FileSystemURL
& file_system_url
,
54 const std::string
& mime_type
)> HelperCallback
;
56 ExternalFileURLRequestJob(void* profile_id
,
57 net::URLRequest
* request
,
58 net::NetworkDelegate
* network_delegate
);
60 // net::URLRequestJob overrides:
61 virtual void SetExtraRequestHeaders(
62 const net::HttpRequestHeaders
& headers
) override
;
63 virtual void Start() override
;
64 virtual void Kill() override
;
65 virtual bool GetMimeType(std::string
* mime_type
) const override
;
66 virtual bool IsRedirectResponse(GURL
* location
,
67 int* http_status_code
) override
;
68 virtual bool ReadRawData(net::IOBuffer
* buf
,
70 int* bytes_read
) override
;
73 virtual ~ExternalFileURLRequestJob();
76 // Called from an internal helper class defined in drive_url_request_job.cc,
77 // which is running on the UI thread.
78 void OnHelperResultObtained(
80 const scoped_refptr
<storage::FileSystemContext
>& file_system_context
,
81 scoped_ptr
<IsolatedFileSystemScope
> isolated_file_system_scope
,
82 const storage::FileSystemURL
& file_system_url
,
83 const std::string
& mime_type
);
85 // Called from FileSystemBackend::GetRedirectURLForContents.
86 void OnRedirectURLObtained(const GURL
& redirect_url
);
88 // Called from DriveURLRequestJob::OnFileInfoObtained.
89 void OnFileInfoObtained(base::File::Error result
,
90 const base::File::Info
& file_info
);
92 // Called when DriveFileStreamReader::Read is completed.
93 void OnReadCompleted(int read_result
);
95 void* const profile_id_
;
97 // The range of the file to be returned.
98 net::HttpByteRange byte_range_
;
99 int64 remaining_bytes_
;
101 scoped_refptr
<storage::FileSystemContext
> file_system_context_
;
102 scoped_ptr
<IsolatedFileSystemScope
> isolated_file_system_scope_
;
103 storage::FileSystemURL file_system_url_
;
104 std::string mime_type_
;
105 scoped_ptr
<storage::FileStreamReader
> stream_reader_
;
108 // This should remain the last member so it'll be destroyed first and
109 // invalidate its weak pointers before other members are destroyed.
110 base::WeakPtrFactory
<ExternalFileURLRequestJob
> weak_ptr_factory_
;
111 DISALLOW_COPY_AND_ASSIGN(ExternalFileURLRequestJob
);
114 } // namespace chromeos
116 #endif // CHROME_BROWSER_CHROMEOS_FILEAPI_EXTERNAL_FILE_URL_REQUEST_JOB_H_