OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
15 #include "chrome/browser/chromeos/drive/file_errors.h" | 13 #include "chrome/browser/chromeos/drive/file_errors.h" |
14 #include "net/base/net_errors.h" | |
16 #include "net/http/http_byte_range.h" | 15 #include "net/http/http_byte_range.h" |
17 #include "net/url_request/url_request_job.h" | 16 #include "net/url_request/url_request_job.h" |
18 | 17 #include "storage/browser/blob/file_stream_reader.h" |
19 namespace base { | 18 #include "storage/browser/fileapi/file_system_url.h" |
20 class SequencedTaskRunner; | |
21 } // namespace | |
22 | 19 |
23 namespace net { | 20 namespace net { |
24 class IOBuffer; | 21 class IOBuffer; |
25 class NetworkDelegate; | 22 class NetworkDelegate; |
26 class URLRequest; | 23 class URLRequest; |
27 } // namespace net | 24 } // namespace net |
28 | 25 |
29 namespace drive { | 26 namespace drive { |
30 | 27 |
31 class DriveFileStreamReader; | |
32 class FileSystemInterface; | |
33 class ResourceEntry; | |
34 | |
35 // DriveURLRequestJob is the gateway between network-level drive:... | 28 // DriveURLRequestJob is the gateway between network-level drive:... |
36 // requests for drive resources and FileSystem. It exposes content URLs | 29 // requests for drive resources and FileSystem. It exposes content URLs |
37 // formatted as drive:<drive-file-path>. | 30 // formatted as drive:<drive-file-path>. |
38 // The methods should be run on IO thread, and the operations to communicate | 31 // The methods should be run on IO thread. |
39 // with a locally cached file will run on |file_task_runner|. | |
40 class DriveURLRequestJob : public net::URLRequestJob { | 32 class DriveURLRequestJob : public net::URLRequestJob { |
41 public: | 33 public: |
34 typedef base::Callback< | |
35 void(net::Error, | |
36 const scoped_refptr<storage::FileSystemContext>& file_system_context, | |
37 const storage::FileSystemURL& file_system_url, | |
38 const std::string& mime_type)> HelperCallback; | |
kinaba
2014/09/24 02:11:13
"Helper" here and below (OnHelperResultObtained) i
hirono
2014/09/24 03:40:17
Done.
| |
42 | 39 |
43 // Callback to return the FileSystemInterface instance. This is an | 40 DriveURLRequestJob(void* profile_id, |
44 // injecting point for testing. | |
45 // Note that the callback will be copied between threads (IO and UI), and | |
46 // will be called on UI thread. | |
47 typedef base::Callback<FileSystemInterface*()> FileSystemGetter; | |
48 | |
49 DriveURLRequestJob(const FileSystemGetter& file_system_getter, | |
50 base::SequencedTaskRunner* file_task_runner, | |
51 net::URLRequest* request, | 41 net::URLRequest* request, |
52 net::NetworkDelegate* network_delegate); | 42 net::NetworkDelegate* network_delegate); |
53 | 43 |
54 // net::URLRequestJob overrides: | 44 // net::URLRequestJob overrides: |
55 virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) | 45 virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) |
56 OVERRIDE; | 46 OVERRIDE; |
57 virtual void Start() OVERRIDE; | 47 virtual void Start() OVERRIDE; |
58 virtual void Kill() OVERRIDE; | 48 virtual void Kill() OVERRIDE; |
59 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 49 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
60 virtual bool IsRedirectResponse( | 50 virtual bool IsRedirectResponse( |
61 GURL* location, int* http_status_code) OVERRIDE; | 51 GURL* location, int* http_status_code) OVERRIDE; |
62 virtual bool ReadRawData( | 52 virtual bool ReadRawData( |
63 net::IOBuffer* buf, int buf_size, int* bytes_read) OVERRIDE; | 53 net::IOBuffer* buf, int buf_size, int* bytes_read) OVERRIDE; |
64 | 54 |
65 protected: | 55 protected: |
66 virtual ~DriveURLRequestJob(); | 56 virtual ~DriveURLRequestJob(); |
67 | 57 |
68 private: | 58 private: |
69 // Called when the initialization of DriveFileStreamReader is completed. | 59 // Called from a helper on the UI thread. |
70 void OnDriveFileStreamReaderInitialized( | 60 void OnHelperResultObtained( |
71 int error, scoped_ptr<ResourceEntry> entry); | 61 net::Error error, |
62 const scoped_refptr<storage::FileSystemContext>& file_system_context, | |
63 const storage::FileSystemURL& file_system_url, | |
64 const std::string& mime_type); | |
65 | |
66 // Called from FileSystemBackend::GetRedirectURLForContents. | |
67 void OnRedirectURLObtained(const GURL& redirect_url); | |
68 | |
69 // Called from DriveURLRequestJob::OnFileInfoObtained. | |
70 void OnFileInfoObtained(base::File::Error result, | |
71 const base::File::Info& file_info); | |
72 | 72 |
73 // Called when DriveFileStreamReader::Read is completed. | 73 // Called when DriveFileStreamReader::Read is completed. |
74 void OnReadCompleted(int read_result); | 74 void OnReadCompleted(int read_result); |
75 | 75 |
76 const FileSystemGetter file_system_getter_; | 76 void* const profile_id_; |
77 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | |
78 | 77 |
79 // The range of the file to be returned. | 78 // The range of the file to be returned. |
80 net::HttpByteRange byte_range_; | 79 net::HttpByteRange byte_range_; |
80 int64 remaining_bytes_; | |
81 | 81 |
82 scoped_ptr<DriveFileStreamReader> stream_reader_; | 82 scoped_refptr<storage::FileSystemContext> file_system_context_; |
83 scoped_ptr<ResourceEntry> entry_; | 83 storage::FileSystemURL file_system_url_; |
84 std::string mime_type_; | |
85 scoped_ptr<storage::FileStreamReader> stream_reader_; | |
86 GURL redirect_url_; | |
84 | 87 |
85 // This should remain the last member so it'll be destroyed first and | 88 // This should remain the last member so it'll be destroyed first and |
86 // invalidate its weak pointers before other members are destroyed. | 89 // invalidate its weak pointers before other members are destroyed. |
87 base::WeakPtrFactory<DriveURLRequestJob> weak_ptr_factory_; | 90 base::WeakPtrFactory<DriveURLRequestJob> weak_ptr_factory_; |
88 DISALLOW_COPY_AND_ASSIGN(DriveURLRequestJob); | 91 DISALLOW_COPY_AND_ASSIGN(DriveURLRequestJob); |
89 }; | 92 }; |
90 | 93 |
91 } // namespace drive | 94 } // namespace drive |
92 | 95 |
93 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ | 96 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ |
OLD | NEW |