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/browser/fileapi/file_system_url_request_job.h" | 5 #include "webkit/browser/fileapi/file_system_url_request_job.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 std::string cache_control(net::HttpRequestHeaders::kCacheControl); | 50 std::string cache_control(net::HttpRequestHeaders::kCacheControl); |
51 cache_control.append(": no-cache"); | 51 cache_control.append(": no-cache"); |
52 headers->AddHeader(cache_control); | 52 headers->AddHeader(cache_control); |
53 | 53 |
54 return headers; | 54 return headers; |
55 } | 55 } |
56 | 56 |
57 FileSystemURLRequestJob::FileSystemURLRequestJob( | 57 FileSystemURLRequestJob::FileSystemURLRequestJob( |
58 URLRequest* request, | 58 URLRequest* request, |
59 NetworkDelegate* network_delegate, | 59 NetworkDelegate* network_delegate, |
60 const std::string& storage_domain, | |
61 FileSystemContext* file_system_context) | 60 FileSystemContext* file_system_context) |
62 : URLRequestJob(request, network_delegate), | 61 : URLRequestJob(request, network_delegate), |
63 storage_domain_(storage_domain), | |
64 file_system_context_(file_system_context), | 62 file_system_context_(file_system_context), |
65 is_directory_(false), | 63 is_directory_(false), |
66 remaining_bytes_(0), | 64 remaining_bytes_(0), |
67 weak_factory_(this) { | 65 weak_factory_(this) { |
68 } | 66 } |
69 | 67 |
70 FileSystemURLRequestJob::~FileSystemURLRequestJob() {} | 68 FileSystemURLRequestJob::~FileSystemURLRequestJob() {} |
71 | 69 |
72 void FileSystemURLRequestJob::Start() { | 70 void FileSystemURLRequestJob::Start() { |
73 base::MessageLoop::current()->PostTask( | 71 base::MessageLoop::current()->PostTask( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (response_info_) | 150 if (response_info_) |
153 return 200; | 151 return 200; |
154 return URLRequestJob::GetResponseCode(); | 152 return URLRequestJob::GetResponseCode(); |
155 } | 153 } |
156 | 154 |
157 void FileSystemURLRequestJob::StartAsync() { | 155 void FileSystemURLRequestJob::StartAsync() { |
158 if (!request_) | 156 if (!request_) |
159 return; | 157 return; |
160 DCHECK(!reader_.get()); | 158 DCHECK(!reader_.get()); |
161 url_ = file_system_context_->CrackURL(request_->url()); | 159 url_ = file_system_context_->CrackURL(request_->url()); |
162 if (!url_.is_valid()) { | |
163 file_system_context_->AttemptAutoMountForURLRequest( | |
164 request_, | |
165 storage_domain_, | |
166 base::Bind(&FileSystemURLRequestJob::DidAttemptAutoMount, | |
167 weak_factory_.GetWeakPtr())); | |
168 return; | |
169 } | |
170 if (!file_system_context_->CanServeURLRequest(url_)) { | 160 if (!file_system_context_->CanServeURLRequest(url_)) { |
171 // In incognito mode the API is not usable and there should be no data. | 161 // In incognito mode the API is not usable and there should be no data. |
172 NotifyFailed(net::ERR_FILE_NOT_FOUND); | 162 NotifyFailed(net::ERR_FILE_NOT_FOUND); |
173 return; | 163 return; |
174 } | 164 } |
175 file_system_context_->operation_runner()->GetMetadata( | 165 file_system_context_->operation_runner()->GetMetadata( |
176 url_, | 166 url_, |
177 base::Bind(&FileSystemURLRequestJob::DidGetMetadata, | 167 base::Bind(&FileSystemURLRequestJob::DidGetMetadata, |
178 weak_factory_.GetWeakPtr())); | 168 weak_factory_.GetWeakPtr())); |
179 } | 169 } |
180 | 170 |
181 void FileSystemURLRequestJob::DidAttemptAutoMount(base::File::Error result) { | |
182 if (result >= 0 && | |
183 file_system_context_->CrackURL(request_->url()).is_valid()) { | |
184 StartAsync(); | |
185 } else { | |
186 NotifyFailed(net::ERR_FILE_NOT_FOUND); | |
187 } | |
188 } | |
189 | |
190 void FileSystemURLRequestJob::DidGetMetadata( | 171 void FileSystemURLRequestJob::DidGetMetadata( |
191 base::File::Error error_code, | 172 base::File::Error error_code, |
192 const base::File::Info& file_info) { | 173 const base::File::Info& file_info) { |
193 if (error_code != base::File::FILE_OK) { | 174 if (error_code != base::File::FILE_OK) { |
194 NotifyFailed(error_code == base::File::FILE_ERROR_INVALID_URL ? | 175 NotifyFailed(error_code == base::File::FILE_ERROR_INVALID_URL ? |
195 net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND); | 176 net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND); |
196 return; | 177 return; |
197 } | 178 } |
198 | 179 |
199 // We may have been orphaned... | 180 // We may have been orphaned... |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 236 } |
256 | 237 |
257 return false; | 238 return false; |
258 } | 239 } |
259 | 240 |
260 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 241 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
261 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 242 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
262 } | 243 } |
263 | 244 |
264 } // namespace fileapi | 245 } // namespace fileapi |
OLD | NEW |