| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 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" | |
| 19 | |
| 20 namespace net { | |
| 21 class IOBuffer; | |
| 22 class NetworkDelegate; | |
| 23 class URLRequest; | |
| 24 } // namespace net | |
| 25 | |
| 26 namespace drive { | |
| 27 | |
| 28 // DriveURLRequestJob 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 class DriveURLRequestJob : public net::URLRequestJob { | |
| 33 public: | |
| 34 // Callback to take results from an internal helper defined in | |
| 35 // drive_url_request_job.cc. | |
| 36 typedef base::Callback< | |
| 37 void(net::Error, | |
| 38 const scoped_refptr<storage::FileSystemContext>& file_system_context, | |
| 39 const storage::FileSystemURL& file_system_url, | |
| 40 const std::string& mime_type)> HelperCallback; | |
| 41 | |
| 42 DriveURLRequestJob(void* profile_id, | |
| 43 net::URLRequest* request, | |
| 44 net::NetworkDelegate* network_delegate); | |
| 45 | |
| 46 // net::URLRequestJob overrides: | |
| 47 virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) | |
| 48 OVERRIDE; | |
| 49 virtual void Start() OVERRIDE; | |
| 50 virtual void Kill() OVERRIDE; | |
| 51 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | |
| 52 virtual bool IsRedirectResponse( | |
| 53 GURL* location, int* http_status_code) OVERRIDE; | |
| 54 virtual bool ReadRawData( | |
| 55 net::IOBuffer* buf, int buf_size, int* bytes_read) OVERRIDE; | |
| 56 | |
| 57 protected: | |
| 58 virtual ~DriveURLRequestJob(); | |
| 59 | |
| 60 private: | |
| 61 // Called from an internal helper class defined in drive_url_request_job.cc, | |
| 62 // which is running on the UI thread. | |
| 63 void OnHelperResultObtained( | |
| 64 net::Error error, | |
| 65 const scoped_refptr<storage::FileSystemContext>& file_system_context, | |
| 66 const storage::FileSystemURL& file_system_url, | |
| 67 const std::string& mime_type); | |
| 68 | |
| 69 // Called from FileSystemBackend::GetRedirectURLForContents. | |
| 70 void OnRedirectURLObtained(const GURL& redirect_url); | |
| 71 | |
| 72 // Called from DriveURLRequestJob::OnFileInfoObtained. | |
| 73 void OnFileInfoObtained(base::File::Error result, | |
| 74 const base::File::Info& file_info); | |
| 75 | |
| 76 // Called when DriveFileStreamReader::Read is completed. | |
| 77 void OnReadCompleted(int read_result); | |
| 78 | |
| 79 void* const profile_id_; | |
| 80 | |
| 81 // The range of the file to be returned. | |
| 82 net::HttpByteRange byte_range_; | |
| 83 int64 remaining_bytes_; | |
| 84 | |
| 85 scoped_refptr<storage::FileSystemContext> file_system_context_; | |
| 86 storage::FileSystemURL file_system_url_; | |
| 87 std::string mime_type_; | |
| 88 scoped_ptr<storage::FileStreamReader> stream_reader_; | |
| 89 GURL redirect_url_; | |
| 90 | |
| 91 // This should remain the last member so it'll be destroyed first and | |
| 92 // invalidate its weak pointers before other members are destroyed. | |
| 93 base::WeakPtrFactory<DriveURLRequestJob> weak_ptr_factory_; | |
| 94 DISALLOW_COPY_AND_ASSIGN(DriveURLRequestJob); | |
| 95 }; | |
| 96 | |
| 97 } // namespace drive | |
| 98 | |
| 99 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_URL_REQUEST_JOB_H_ | |
| OLD | NEW |