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

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 14 matching lines...) Expand all
25 using net::URLRequestJob; 25 using net::URLRequestJob;
26 using net::URLRequestStatus; 26 using net::URLRequestStatus;
27 27
28 namespace fileapi { 28 namespace fileapi {
29 29
30 static const int kFileFlags = base::PLATFORM_FILE_OPEN | 30 static const int kFileFlags = base::PLATFORM_FILE_OPEN |
31 base::PLATFORM_FILE_READ | 31 base::PLATFORM_FILE_READ |
32 base::PLATFORM_FILE_ASYNC; 32 base::PLATFORM_FILE_ASYNC;
33 33
34 FileSystemURLRequestJob::FileSystemURLRequestJob( 34 FileSystemURLRequestJob::FileSystemURLRequestJob(
35 URLRequest* request, FileSystemPathManager* path_manager, 35 URLRequest* request, FileSystemContext* file_system_context,
36 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) 36 scoped_refptr<base::MessageLoopProxy> file_thread_proxy)
37 : URLRequestJob(request), 37 : FileSystemURLRequestJobBase(request, file_system_context,
38 path_manager_(path_manager), 38 file_thread_proxy),
39 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
40 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
39 ALLOW_THIS_IN_INITIALIZER_LIST( 41 ALLOW_THIS_IN_INITIALIZER_LIST(
40 io_callback_(this, &FileSystemURLRequestJob::DidRead)), 42 io_callback_(this, &FileSystemURLRequestJob::DidRead)),
41 stream_(NULL), 43 stream_(NULL),
42 is_directory_(false), 44 is_directory_(false),
43 remaining_bytes_(0), 45 remaining_bytes_(0) {
44 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
45 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
46 file_thread_proxy_(file_thread_proxy) {
47 } 46 }
48 47
49 FileSystemURLRequestJob::~FileSystemURLRequestJob() { 48 FileSystemURLRequestJob::~FileSystemURLRequestJob() {
50 // Since we use the two-arg constructor of FileStream, we need to call Close() 49 // Since we use the two-arg constructor of FileStream, we need to call Close()
51 // manually: ~FileStream won't call it for us. 50 // manually: ~FileStream won't call it for us.
52 if (stream_ != NULL) 51 if (stream_ != NULL)
53 stream_->Close(); 52 stream_->Close();
54 } 53 }
55 54
56 void FileSystemURLRequestJob::Start() { 55 void FileSystemURLRequestJob::Start() {
57 MessageLoop::current()->PostTask(FROM_HERE, 56 MessageLoop::current()->PostTask(FROM_HERE,
58 method_factory_.NewRunnableMethod( 57 method_factory_.NewRunnableMethod(
59 &FileSystemURLRequestJob::StartAsync)); 58 &FileSystemURLRequestJob::StartAsync));
60 } 59 }
61 60
62 void FileSystemURLRequestJob::Kill() { 61 void FileSystemURLRequestJob::Kill() {
63 if (stream_ != NULL) { 62 if (stream_ != NULL) {
64 stream_->Close(); 63 stream_->Close();
65 stream_.reset(NULL); 64 stream_.reset(NULL);
66 } 65 }
67
68 URLRequestJob::Kill(); 66 URLRequestJob::Kill();
69 callback_factory_.RevokeAll(); 67 callback_factory_.RevokeAll();
70 } 68 }
71 69
72 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, 70 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
73 int *bytes_read) { 71 int *bytes_read) {
74 DCHECK_NE(dest_size, 0); 72 DCHECK_NE(dest_size, 0);
75 DCHECK(bytes_read); 73 DCHECK(bytes_read);
76 DCHECK_GE(remaining_bytes_, 0); 74 DCHECK_GE(remaining_bytes_, 0);
77 75
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 else { 121 else {
124 // We don't support multiple range requests in one single URL request. 122 // We don't support multiple range requests in one single URL request.
125 // TODO(adamk): decide whether we want to support multiple range 123 // TODO(adamk): decide whether we want to support multiple range
126 // requests. 124 // requests.
127 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 125 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
128 } 126 }
129 } 127 }
130 } 128 }
131 } 129 }
132 130
133 void FileSystemURLRequestJob::StartAsync() { 131 void FileSystemURLRequestJob::DidGetLocalPath(const FilePath& local_path) {
134 GURL origin_url; 132 absolute_file_path_ = local_path;
135 FileSystemType type;
136 if (!CrackFileSystemURL(request_->url(), &origin_url, &type,
137 &relative_file_path_)) {
138 NotifyFailed(net::ERR_INVALID_URL);
139 return;
140 }
141
142 path_manager_->GetFileSystemRootPath(
143 origin_url, type, false, // create
144 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidGetRootPath));
145 }
146
147 void FileSystemURLRequestJob::DidGetRootPath(bool success,
148 const FilePath& root_path,
149 const std::string& name) {
150 if (!success) {
151 NotifyFailed(net::ERR_FILE_NOT_FOUND);
152 return;
153 }
154
155 absolute_file_path_ = root_path.Append(relative_file_path_);
156
157 base::FileUtilProxy::GetFileInfo(file_thread_proxy_, absolute_file_path_, 133 base::FileUtilProxy::GetFileInfo(file_thread_proxy_, absolute_file_path_,
158 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidResolve)); 134 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidResolve));
159 } 135 }
160 136
161 void FileSystemURLRequestJob::DidResolve(base::PlatformFileError error_code, 137 void FileSystemURLRequestJob::DidResolve(base::PlatformFileError error_code,
162 const base::PlatformFileInfo& file_info) { 138 const base::PlatformFileInfo& file_info) {
163 // We may have been orphaned... 139 // We may have been orphaned...
164 if (!request_) 140 if (!request_)
165 return; 141 return;
166 142
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 GURL::Replacements replacements; 215 GURL::Replacements replacements;
240 replacements.SetPathStr(new_path); 216 replacements.SetPathStr(new_path);
241 *location = request_->url().ReplaceComponents(replacements); 217 *location = request_->url().ReplaceComponents(replacements);
242 *http_status_code = 301; // simulate a permanent redirect 218 *http_status_code = 301; // simulate a permanent redirect
243 return true; 219 return true;
244 } 220 }
245 221
246 return false; 222 return false;
247 } 223 }
248 224
249 void FileSystemURLRequestJob::NotifyFailed(int rv) {
250 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
251 }
252
253 } // namespace fileapi 225 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698