Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / fileapi / external_file_url_request_job.h
bloba026e439b5e39b644ee45293cba0973447fbf710
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/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/fileapi/file_stream_reader.h"
18 #include "storage/browser/fileapi/file_system_url.h"
20 namespace net {
21 class IOBuffer;
22 class NetworkDelegate;
23 class URLRequest;
24 } // namespace net
26 namespace chromeos {
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 {
35 public:
36 // Scope of isolated file system.
37 class IsolatedFileSystemScope {
38 public:
39 explicit IsolatedFileSystemScope(const std::string& file_system_id);
40 ~IsolatedFileSystemScope();
42 private:
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(
50 net::Error,
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 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
62 void Start() override;
63 void Kill() override;
64 bool GetMimeType(std::string* mime_type) const override;
65 bool IsRedirectResponse(GURL* location, int* http_status_code) override;
66 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override;
68 protected:
69 ~ExternalFileURLRequestJob() override;
71 private:
72 // Called from an internal helper class defined in drive_url_request_job.cc,
73 // which is running on the UI thread.
74 void OnHelperResultObtained(
75 net::Error error,
76 const scoped_refptr<storage::FileSystemContext>& file_system_context,
77 scoped_ptr<IsolatedFileSystemScope> isolated_file_system_scope,
78 const storage::FileSystemURL& file_system_url,
79 const std::string& mime_type);
81 // Called from FileSystemBackend::GetRedirectURLForContents.
82 void OnRedirectURLObtained(const GURL& redirect_url);
84 // Called from DriveURLRequestJob::OnFileInfoObtained.
85 void OnFileInfoObtained(base::File::Error result,
86 const base::File::Info& file_info);
88 // Called when DriveFileStreamReader::Read is completed.
89 void OnReadCompleted(int read_result);
91 void* const profile_id_;
93 // The range of the file to be returned.
94 net::HttpByteRange byte_range_;
95 int64 remaining_bytes_;
97 scoped_refptr<storage::FileSystemContext> file_system_context_;
98 scoped_ptr<IsolatedFileSystemScope> isolated_file_system_scope_;
99 storage::FileSystemURL file_system_url_;
100 std::string mime_type_;
101 scoped_ptr<storage::FileStreamReader> stream_reader_;
102 GURL redirect_url_;
104 // This should remain the last member so it'll be destroyed first and
105 // invalidate its weak pointers before other members are destroyed.
106 base::WeakPtrFactory<ExternalFileURLRequestJob> weak_ptr_factory_;
107 DISALLOW_COPY_AND_ASSIGN(ExternalFileURLRequestJob);
110 } // namespace chromeos
112 #endif // CHROME_BROWSER_CHROMEOS_FILEAPI_EXTERNAL_FILE_URL_REQUEST_JOB_H_