OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "webkit/fileapi/file_system_url_request_job.h" | 5 #include "webkit/fileapi/file_system_url_request_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util_proxy.h" | 10 #include "base/file_util_proxy.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 std::string cache_control(net::HttpRequestHeaders::kCacheControl); | 48 std::string cache_control(net::HttpRequestHeaders::kCacheControl); |
49 cache_control.append(": no-cache"); | 49 cache_control.append(": no-cache"); |
50 headers->AddHeader(cache_control); | 50 headers->AddHeader(cache_control); |
51 | 51 |
52 return headers; | 52 return headers; |
53 } | 53 } |
54 | 54 |
55 class FileSystemURLRequestJob::CallbackDispatcher | 55 class FileSystemURLRequestJob::CallbackDispatcher |
56 : public FileSystemCallbackDispatcher { | 56 : public FileSystemCallbackDispatcher { |
57 public: | 57 public: |
58 explicit CallbackDispatcher(FileSystemURLRequestJob* job) | 58 // An instance of this class must be created by Create() |
59 : job_(job) { | 59 // (so that we do not leak ownerships). |
60 DCHECK(job_); | 60 static scoped_ptr<FileSystemCallbackDispatcher> Create( |
| 61 FileSystemURLRequestJob* job) { |
| 62 return scoped_ptr<FileSystemCallbackDispatcher>( |
| 63 new CallbackDispatcher(job)); |
61 } | 64 } |
62 | 65 |
63 // fileapi::FileSystemCallbackDispatcher overrides. | 66 // fileapi::FileSystemCallbackDispatcher overrides. |
64 virtual void DidSucceed() OVERRIDE { | 67 virtual void DidSucceed() OVERRIDE { |
65 NOTREACHED(); | 68 NOTREACHED(); |
66 } | 69 } |
67 | 70 |
68 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info, | 71 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info, |
69 const FilePath& platform_path) OVERRIDE { | 72 const FilePath& platform_path) OVERRIDE { |
70 job_->DidGetMetadata(file_info, platform_path); | 73 job_->DidGetMetadata(file_info, platform_path); |
(...skipping 15 matching lines...) Expand all Loading... |
86 } | 89 } |
87 | 90 |
88 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | 91 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { |
89 int rv = net::ERR_FILE_NOT_FOUND; | 92 int rv = net::ERR_FILE_NOT_FOUND; |
90 if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL) | 93 if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL) |
91 rv = net::ERR_INVALID_URL; | 94 rv = net::ERR_INVALID_URL; |
92 job_->NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 95 job_->NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
93 } | 96 } |
94 | 97 |
95 private: | 98 private: |
| 99 explicit CallbackDispatcher(FileSystemURLRequestJob* job) : job_(job) { |
| 100 DCHECK(job_); |
| 101 } |
| 102 |
96 // TODO(adamk): Get rid of the need for refcounting here by | 103 // TODO(adamk): Get rid of the need for refcounting here by |
97 // allowing FileSystemOperations to be cancelled. | 104 // allowing FileSystemOperations to be cancelled. |
98 scoped_refptr<FileSystemURLRequestJob> job_; | 105 scoped_refptr<FileSystemURLRequestJob> job_; |
99 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); | 106 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); |
100 }; | 107 }; |
101 | 108 |
102 FileSystemURLRequestJob::FileSystemURLRequestJob( | 109 FileSystemURLRequestJob::FileSystemURLRequestJob( |
103 URLRequest* request, FileSystemContext* file_system_context, | 110 URLRequest* request, FileSystemContext* file_system_context, |
104 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) | 111 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) |
105 : URLRequestJob(request), | 112 : URLRequestJob(request), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 213 } |
207 | 214 |
208 int FileSystemURLRequestJob::GetResponseCode() const { | 215 int FileSystemURLRequestJob::GetResponseCode() const { |
209 if (response_info_.get()) | 216 if (response_info_.get()) |
210 return 200; | 217 return 200; |
211 return URLRequestJob::GetResponseCode(); | 218 return URLRequestJob::GetResponseCode(); |
212 } | 219 } |
213 | 220 |
214 void FileSystemURLRequestJob::StartAsync() { | 221 void FileSystemURLRequestJob::StartAsync() { |
215 if (request_) { | 222 if (request_) { |
216 (new FileSystemOperation(new CallbackDispatcher(this), | 223 (new FileSystemOperation(CallbackDispatcher::Create(this), |
217 file_thread_proxy_, | 224 file_thread_proxy_, |
218 file_system_context_) | 225 file_system_context_) |
219 )->GetMetadata(request_->url()); | 226 )->GetMetadata(request_->url()); |
220 } | 227 } |
221 } | 228 } |
222 | 229 |
223 void FileSystemURLRequestJob::DidGetMetadata( | 230 void FileSystemURLRequestJob::DidGetMetadata( |
224 const base::PlatformFileInfo& file_info, | 231 const base::PlatformFileInfo& file_info, |
225 const FilePath& platform_path) { | 232 const FilePath& platform_path) { |
226 // We may have been orphaned... | 233 // We may have been orphaned... |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 313 } |
307 | 314 |
308 return false; | 315 return false; |
309 } | 316 } |
310 | 317 |
311 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 318 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
312 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 319 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
313 } | 320 } |
314 | 321 |
315 } // namespace fileapi | 322 } // namespace fileapi |
OLD | NEW |