Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: webkit/fileapi/file_system_url_request_job.cc

Issue 6864040: Fixed file/directory url resolution for external mount point provider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util_proxy.h" 8 #include "base/file_util_proxy.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // Tell WebKit never to cache this content. 44 // Tell WebKit never to cache this content.
45 std::string cache_control(net::HttpRequestHeaders::kCacheControl); 45 std::string cache_control(net::HttpRequestHeaders::kCacheControl);
46 cache_control.append(": no-cache"); 46 cache_control.append(": no-cache");
47 headers->AddHeader(cache_control); 47 headers->AddHeader(cache_control);
48 48
49 return headers; 49 return headers;
50 } 50 }
51 51
52 FileSystemURLRequestJob::FileSystemURLRequestJob( 52 FileSystemURLRequestJob::FileSystemURLRequestJob(
53 URLRequest* request, FileSystemPathManager* path_manager, 53 URLRequest* request, FileSystemContext* file_system_context,
54 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) 54 scoped_refptr<base::MessageLoopProxy> file_thread_proxy)
55 : URLRequestJob(request), 55 : FileSystemURLRequestJobBase(request, file_system_context,
56 path_manager_(path_manager), 56 file_thread_proxy),
57 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
58 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
57 ALLOW_THIS_IN_INITIALIZER_LIST( 59 ALLOW_THIS_IN_INITIALIZER_LIST(
58 io_callback_(this, &FileSystemURLRequestJob::DidRead)), 60 io_callback_(this, &FileSystemURLRequestJob::DidRead)),
59 stream_(NULL), 61 stream_(NULL),
60 is_directory_(false), 62 is_directory_(false),
61 remaining_bytes_(0), 63 remaining_bytes_(0) {
62 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
63 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
64 file_thread_proxy_(file_thread_proxy) {
65 } 64 }
66 65
67 FileSystemURLRequestJob::~FileSystemURLRequestJob() { 66 FileSystemURLRequestJob::~FileSystemURLRequestJob() {
68 // Since we use the two-arg constructor of FileStream, we need to call Close() 67 // Since we use the two-arg constructor of FileStream, we need to call Close()
69 // manually: ~FileStream won't call it for us. 68 // manually: ~FileStream won't call it for us.
70 if (stream_ != NULL) 69 if (stream_ != NULL)
71 stream_->Close(); 70 stream_->Close();
72 } 71 }
73 72
74 void FileSystemURLRequestJob::Start() { 73 void FileSystemURLRequestJob::Start() {
75 MessageLoop::current()->PostTask(FROM_HERE, 74 MessageLoop::current()->PostTask(FROM_HERE,
76 method_factory_.NewRunnableMethod( 75 method_factory_.NewRunnableMethod(
77 &FileSystemURLRequestJob::StartAsync)); 76 &FileSystemURLRequestJob::StartAsync));
78 } 77 }
79 78
80 void FileSystemURLRequestJob::Kill() { 79 void FileSystemURLRequestJob::Kill() {
81 if (stream_ != NULL) { 80 if (stream_ != NULL) {
82 stream_->Close(); 81 stream_->Close();
83 stream_.reset(NULL); 82 stream_.reset(NULL);
84 } 83 }
85
86 URLRequestJob::Kill(); 84 URLRequestJob::Kill();
87 callback_factory_.RevokeAll(); 85 callback_factory_.RevokeAll();
88 } 86 }
89 87
90 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, 88 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
91 int *bytes_read) { 89 int *bytes_read) {
92 DCHECK_NE(dest_size, 0); 90 DCHECK_NE(dest_size, 0);
93 DCHECK(bytes_read); 91 DCHECK(bytes_read);
94 DCHECK_GE(remaining_bytes_, 0); 92 DCHECK_GE(remaining_bytes_, 0);
95 93
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 else { 139 else {
142 // We don't support multiple range requests in one single URL request. 140 // We don't support multiple range requests in one single URL request.
143 // TODO(adamk): decide whether we want to support multiple range 141 // TODO(adamk): decide whether we want to support multiple range
144 // requests. 142 // requests.
145 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 143 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
146 } 144 }
147 } 145 }
148 } 146 }
149 } 147 }
150 148
149 void FileSystemURLRequestJob::DidGetLocalPath(const FilePath& local_path) {
150 absolute_file_path_ = local_path;
151 base::FileUtilProxy::GetFileInfo(file_thread_proxy_, absolute_file_path_,
152 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidResolve));
153 }
154
151 void FileSystemURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { 155 void FileSystemURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) {
152 if (response_info_.get()) 156 if (response_info_.get())
153 *info = *response_info_; 157 *info = *response_info_;
154 } 158 }
155 159
156 int FileSystemURLRequestJob::GetResponseCode() const { 160 int FileSystemURLRequestJob::GetResponseCode() const {
157 if (response_info_.get()) 161 if (response_info_.get())
158 return 200; 162 return 200;
159 return URLRequestJob::GetResponseCode(); 163 return URLRequestJob::GetResponseCode();
160 } 164 }
161 165
162 void FileSystemURLRequestJob::StartAsync() {
163 GURL origin_url;
164 FileSystemType type;
165 if (!CrackFileSystemURL(request_->url(), &origin_url, &type,
166 &relative_file_path_)) {
167 NotifyFailed(net::ERR_INVALID_URL);
168 return;
169 }
170
171 path_manager_->GetFileSystemRootPath(
172 origin_url, type, false, // create
173 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidGetRootPath));
174 }
175
176 void FileSystemURLRequestJob::DidGetRootPath(bool success,
177 const FilePath& root_path,
178 const std::string& name) {
179 if (!success) {
180 NotifyFailed(net::ERR_FILE_NOT_FOUND);
181 return;
182 }
183
184 absolute_file_path_ = root_path.Append(relative_file_path_);
185
186 base::FileUtilProxy::GetFileInfo(file_thread_proxy_, absolute_file_path_,
187 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidResolve));
188 }
189
190 void FileSystemURLRequestJob::DidResolve(base::PlatformFileError error_code, 166 void FileSystemURLRequestJob::DidResolve(base::PlatformFileError error_code,
191 const base::PlatformFileInfo& file_info) { 167 const base::PlatformFileInfo& file_info) {
192 // We may have been orphaned... 168 // We may have been orphaned...
193 if (!request_) 169 if (!request_)
194 return; 170 return;
195 171
196 // We use FileSystemURLRequestJob to handle files as well as directories 172 // We use FileSystemURLRequestJob to handle files as well as directories
197 // without trailing slash. 173 // without trailing slash.
198 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, 174 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise,
199 // we will append trailing slash and redirect to FileDirJob. 175 // we will append trailing slash and redirect to FileDirJob.
(...skipping 24 matching lines...) Expand all
224 NotifyFailed(error_code); 200 NotifyFailed(error_code);
225 return; 201 return;
226 } 202 }
227 203
228 stream_.reset(new net::FileStream(file.ReleaseValue(), kFileFlags)); 204 stream_.reset(new net::FileStream(file.ReleaseValue(), kFileFlags));
229 205
230 remaining_bytes_ = byte_range_.last_byte_position() - 206 remaining_bytes_ = byte_range_.last_byte_position() -
231 byte_range_.first_byte_position() + 1; 207 byte_range_.first_byte_position() + 1;
232 DCHECK_GE(remaining_bytes_, 0); 208 DCHECK_GE(remaining_bytes_, 0);
233 209
210 // TODO(adamk): Please remove this ScopedAllowIO once we support async seek on
211 // FileStream.
212 base::ThreadRestrictions::ScopedAllowIO allow_io;
234 // Do the seek at the beginning of the request. 213 // Do the seek at the beginning of the request.
235 if (remaining_bytes_ > 0 && 214 if (remaining_bytes_ > 0 &&
236 byte_range_.first_byte_position() != 0 && 215 byte_range_.first_byte_position() != 0 &&
237 byte_range_.first_byte_position() != 216 byte_range_.first_byte_position() !=
238 stream_->Seek(net::FROM_BEGIN, byte_range_.first_byte_position())) { 217 stream_->Seek(net::FROM_BEGIN, byte_range_.first_byte_position())) {
239 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 218 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
240 return; 219 return;
241 } 220 }
242 221
243 set_expected_content_size(remaining_bytes_); 222 set_expected_content_size(remaining_bytes_);
(...skipping 27 matching lines...) Expand all
271 GURL::Replacements replacements; 250 GURL::Replacements replacements;
272 replacements.SetPathStr(new_path); 251 replacements.SetPathStr(new_path);
273 *location = request_->url().ReplaceComponents(replacements); 252 *location = request_->url().ReplaceComponents(replacements);
274 *http_status_code = 301; // simulate a permanent redirect 253 *http_status_code = 301; // simulate a permanent redirect
275 return true; 254 return true;
276 } 255 }
277 256
278 return false; 257 return false;
279 } 258 }
280 259
281 void FileSystemURLRequestJob::NotifyFailed(int rv) {
282 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
283 }
284
285 } // namespace fileapi 260 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698