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

Side by Side Diff: chrome/browser/chromeos/fileapi/external_file_url_request_job.cc

Issue 580023003: Rename the drive: scheme with the externalfile: scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/drive/drive_url_request_job.h" 5 #include "chrome/browser/chromeos/fileapi/external_file_url_request_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chromeos/drive/file_system_util.h" 15 #include "chrome/browser/chromeos/drive/file_system_util.h"
16 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h"
16 #include "chrome/browser/extensions/api/file_handlers/mime_util.h" 17 #include "chrome/browser/extensions/api/file_handlers/mime_util.h"
17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/storage_partition.h" 21 #include "content/public/browser/storage_partition.h"
21 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
22 #include "net/http/http_byte_range.h" 23 #include "net/http/http_byte_range.h"
23 #include "net/http/http_request_headers.h" 24 #include "net/http/http_request_headers.h"
24 #include "net/http/http_response_info.h" 25 #include "net/http/http_response_info.h"
25 #include "net/http/http_util.h" 26 #include "net/http/http_util.h"
26 #include "net/url_request/url_request.h" 27 #include "net/url_request/url_request.h"
27 #include "net/url_request/url_request_status.h" 28 #include "net/url_request/url_request_status.h"
28 #include "storage/browser/fileapi/file_system_backend.h" 29 #include "storage/browser/fileapi/file_system_backend.h"
29 #include "storage/browser/fileapi/file_system_context.h" 30 #include "storage/browser/fileapi/file_system_context.h"
30 #include "storage/browser/fileapi/file_system_operation_runner.h" 31 #include "storage/browser/fileapi/file_system_operation_runner.h"
31 32
32 using content::BrowserThread; 33 using content::BrowserThread;
33 34
34 namespace drive { 35 namespace chromeos {
35 namespace { 36 namespace {
36 37
37 struct MimeTypeReplacement { 38 struct MimeTypeReplacement {
38 const char* original_type; 39 const char* original_type;
39 const char* new_type; 40 const char* new_type;
40 }; 41 };
41 42
42 const MimeTypeReplacement kMimeTypeReplacements[] = { 43 const MimeTypeReplacement kMimeTypeReplacements[] = {
43 {"message/rfc822", "multipart/related"} // Fixes MHTML 44 {"message/rfc822", "multipart/related"} // Fixes MHTML
44 }; 45 };
45 46
46 // Check if the |url| points a valid location or not. 47 // Check if the |url| points a valid location or not.
47 bool IsValidURL(const storage::FileSystemURL& url) { 48 bool IsValidURL(const storage::FileSystemURL& url) {
48 switch (url.type()) { 49 switch (url.type()) {
49 case storage::kFileSystemTypeDrive: { 50 case storage::kFileSystemTypeDrive: {
50 const base::FilePath my_drive_path = util::GetDriveMyDriveRootPath(); 51 const base::FilePath my_drive_path =
52 drive::util::GetDriveMyDriveRootPath();
51 const base::FilePath drive_other_path = 53 const base::FilePath drive_other_path =
52 util::GetDriveGrandRootPath().Append(util::kDriveOtherDirName); 54 drive::util::GetDriveGrandRootPath().Append(
55 drive::util::kDriveOtherDirName);
53 const base::FilePath url_drive_path = 56 const base::FilePath url_drive_path =
54 util::ExtractDrivePathFromFileSystemUrl(url); 57 drive::util::ExtractDrivePathFromFileSystemUrl(url);
55 return my_drive_path == url_drive_path || 58 return my_drive_path == url_drive_path ||
56 my_drive_path.IsParent(url_drive_path) || 59 my_drive_path.IsParent(url_drive_path) ||
57 drive_other_path.IsParent(url_drive_path); 60 drive_other_path.IsParent(url_drive_path);
58 } 61 }
59 default: 62 default:
60 return false; 63 return false;
61 } 64 }
62 } 65 }
63 66
64 // Delegate for obtaining FileSystemContext, FileSystemURL, and mime type on 67 // Delegate for obtaining FileSystemContext, FileSystemURL, and mime type on
65 // the UI thread. 68 // the UI thread.
66 class GetFileSystemContextDelegate { 69 class GetFileSystemContextDelegate {
67 public: 70 public:
68 GetFileSystemContextDelegate( 71 GetFileSystemContextDelegate(
69 void* profile_id, 72 void* profile_id,
70 const GURL& url, 73 const GURL& url,
71 const DriveURLRequestJob::DelegateCallback& callback) 74 const ExternalFileURLRequestJob::DelegateCallback& callback)
72 : profile_id_(profile_id), url_(url), callback_(callback) { 75 : profile_id_(profile_id), url_(url), callback_(callback) {
73 DCHECK_CURRENTLY_ON(BrowserThread::IO); 76 DCHECK_CURRENTLY_ON(BrowserThread::IO);
74 BrowserThread::PostTask( 77 BrowserThread::PostTask(
75 BrowserThread::UI, 78 BrowserThread::UI,
76 FROM_HERE, 79 FROM_HERE,
77 base::Bind(&GetFileSystemContextDelegate::RunOnUIThread, 80 base::Bind(&GetFileSystemContextDelegate::RunOnUIThread,
78 base::Unretained(this))); 81 base::Unretained(this)));
79 } 82 }
80 83
81 private: 84 private:
82 void RunOnUIThread() { 85 void RunOnUIThread() {
83 DCHECK_CURRENTLY_ON(BrowserThread::UI); 86 DCHECK_CURRENTLY_ON(BrowserThread::UI);
84 Profile* const profile = reinterpret_cast<Profile*>(profile_id_); 87 Profile* const profile = reinterpret_cast<Profile*>(profile_id_);
85 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) { 88 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
86 ReplyResult(net::ERR_FAILED); 89 ReplyResult(net::ERR_FAILED);
87 return; 90 return;
88 } 91 }
89 content::StoragePartition* const storage = 92 content::StoragePartition* const storage =
90 content::BrowserContext::GetStoragePartitionForSite(profile, url_); 93 content::BrowserContext::GetStoragePartitionForSite(profile, url_);
91 DCHECK(storage); 94 DCHECK(storage);
92 95
93 scoped_refptr<storage::FileSystemContext> context = 96 scoped_refptr<storage::FileSystemContext> context =
94 storage->GetFileSystemContext(); 97 storage->GetFileSystemContext();
95 DCHECK(context.get()); 98 DCHECK(context.get());
96 99
97 // Obtain the absolute path in the file system. 100 // Obtain the absolute path in the file system.
98 base::FilePath path = drive::util::GetDriveMountPointPath(profile); 101 base::FilePath path = drive::util::GetDriveMountPointPath(profile);
99 drive::util::GetDriveGrandRootPath().AppendRelativePath( 102 drive::util::GetDriveGrandRootPath().AppendRelativePath(
100 util::DriveURLToFilePath(url_), &path); 103 ExternalFileURLToFilePath(url_), &path);
101 104
102 storage::ExternalFileSystemBackend* const backend = 105 storage::ExternalFileSystemBackend* const backend =
103 context->external_backend(); 106 context->external_backend();
104 DCHECK(backend); 107 DCHECK(backend);
105 108
106 // Obtain the virtual path. 109 // Obtain the virtual path.
107 base::FilePath virtual_path; 110 base::FilePath virtual_path;
108 if (!backend->GetVirtualPath(path, &virtual_path)) { 111 if (!backend->GetVirtualPath(path, &virtual_path)) {
109 ReplyResult(net::ERR_FILE_NOT_FOUND); 112 ReplyResult(net::ERR_FILE_NOT_FOUND);
110 return; 113 return;
111 } 114 }
112 115
113 // Obtain the file system URL. 116 // Obtain the file system URL.
114 // TODO(hirono): After removing MHTML support, stop to use the special 117 // TODO(hirono): After removing MHTML support, stop to use the special
118
115 // drive: scheme and use filesystem: URL directly. crbug.com/415455 119 // drive: scheme and use filesystem: URL directly. crbug.com/415455
116 file_system_url_ = context->CreateCrackedFileSystemURL( 120 file_system_url_ = context->CreateCrackedFileSystemURL(
117 GURL(std::string(chrome::kDriveScheme) + ":"), 121 GURL(std::string(chrome::kExternalFileScheme) + ":"),
118 storage::kFileSystemTypeExternal, 122 storage::kFileSystemTypeExternal,
119 virtual_path); 123 virtual_path);
120 if (!IsValidURL(file_system_url_)) { 124 if (!IsValidURL(file_system_url_)) {
121 ReplyResult(net::ERR_INVALID_URL); 125 ReplyResult(net::ERR_INVALID_URL);
122 return; 126 return;
123 } 127 }
124 128
125 file_system_context_ = context; 129 file_system_context_ = context;
126 130
127 extensions::app_file_handler_util::GetMimeTypeForLocalPath( 131 extensions::app_file_handler_util::GetMimeTypeForLocalPath(
(...skipping 11 matching lines...) Expand all
139 mime_type_ = kMimeTypeReplacements[i].new_type; 143 mime_type_ = kMimeTypeReplacements[i].new_type;
140 break; 144 break;
141 } 145 }
142 } 146 }
143 ReplyResult(net::OK); 147 ReplyResult(net::OK);
144 } 148 }
145 149
146 void ReplyResult(net::Error error) { 150 void ReplyResult(net::Error error) {
147 DCHECK_CURRENTLY_ON(BrowserThread::UI); 151 DCHECK_CURRENTLY_ON(BrowserThread::UI);
148 152
149 BrowserThread::PostTask( 153 BrowserThread::PostTask(BrowserThread::IO,
150 BrowserThread::IO, 154 FROM_HERE,
151 FROM_HERE, 155 base::Bind(callback_,
152 base::Bind(callback_, 156 error,
153 error, 157 file_system_context_,
154 file_system_context_, 158 file_system_url_,
155 file_system_url_, 159 mime_type_));
156 mime_type_));
157 delete this; 160 delete this;
158 } 161 }
159 162
160 void* const profile_id_; 163 void* const profile_id_;
161 const GURL url_; 164 const GURL url_;
162 const DriveURLRequestJob::DelegateCallback callback_; 165 const ExternalFileURLRequestJob::DelegateCallback callback_;
163 scoped_refptr<storage::FileSystemContext> file_system_context_; 166 scoped_refptr<storage::FileSystemContext> file_system_context_;
164 storage::FileSystemURL file_system_url_; 167 storage::FileSystemURL file_system_url_;
165 std::string mime_type_; 168 std::string mime_type_;
166 169
167 DISALLOW_COPY_AND_ASSIGN(GetFileSystemContextDelegate); 170 DISALLOW_COPY_AND_ASSIGN(GetFileSystemContextDelegate);
168 }; 171 };
169 172
170 } // namespace 173 } // namespace
171 174
172 DriveURLRequestJob::DriveURLRequestJob(void* profile_id, 175 ExternalFileURLRequestJob::ExternalFileURLRequestJob(
173 net::URLRequest* request, 176 void* profile_id,
174 net::NetworkDelegate* network_delegate) 177 net::URLRequest* request,
178 net::NetworkDelegate* network_delegate)
175 : net::URLRequestJob(request, network_delegate), 179 : net::URLRequestJob(request, network_delegate),
176 profile_id_(profile_id), 180 profile_id_(profile_id),
177 remaining_bytes_(0), 181 remaining_bytes_(0),
178 weak_ptr_factory_(this) { 182 weak_ptr_factory_(this) {
179 } 183 }
180 184
181 void DriveURLRequestJob::SetExtraRequestHeaders( 185 void ExternalFileURLRequestJob::SetExtraRequestHeaders(
182 const net::HttpRequestHeaders& headers) { 186 const net::HttpRequestHeaders& headers) {
183 std::string range_header; 187 std::string range_header;
184 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { 188 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) {
185 // Note: We only support single range requests. 189 // Note: We only support single range requests.
186 std::vector<net::HttpByteRange> ranges; 190 std::vector<net::HttpByteRange> ranges;
187 if (net::HttpUtil::ParseRangeHeader(range_header, &ranges) && 191 if (net::HttpUtil::ParseRangeHeader(range_header, &ranges) &&
188 ranges.size() == 1) { 192 ranges.size() == 1) {
189 byte_range_ = ranges[0]; 193 byte_range_ = ranges[0];
190 } else { 194 } else {
191 // Failed to parse Range: header, so notify the error. 195 // Failed to parse Range: header, so notify the error.
192 NotifyDone( 196 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED,
193 net::URLRequestStatus(net::URLRequestStatus::FAILED, 197 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
194 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
195 } 198 }
196 } 199 }
197 } 200 }
198 201
199 void DriveURLRequestJob::Start() { 202 void ExternalFileURLRequestJob::Start() {
200 DVLOG(1) << "Starting request"; 203 DVLOG(1) << "Starting request";
201 DCHECK_CURRENTLY_ON(BrowserThread::IO); 204 DCHECK_CURRENTLY_ON(BrowserThread::IO);
202 DCHECK(!stream_reader_); 205 DCHECK(!stream_reader_);
203 206
204 // We only support GET request. 207 // We only support GET request.
205 if (request()->method() != "GET") { 208 if (request()->method() != "GET") {
206 LOG(WARNING) << "Failed to start request: " 209 LOG(WARNING) << "Failed to start request: " << request()->method()
207 << request()->method() << " method is not supported"; 210 << " method is not supported";
208 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 211 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
209 net::ERR_METHOD_NOT_SUPPORTED)); 212 net::ERR_METHOD_NOT_SUPPORTED));
210 return; 213 return;
211 } 214 }
212 215
213 // Check if the scheme is correct. 216 // Check if the scheme is correct.
214 if (!request()->url().SchemeIs(chrome::kDriveScheme)) { 217 if (!request()->url().SchemeIs(chrome::kExternalFileScheme)) {
215 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 218 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
216 net::ERR_INVALID_URL)); 219 net::ERR_INVALID_URL));
217 return; 220 return;
218 } 221 }
219 222
220 // Owned by itself. 223 // Owned by itself.
221 new GetFileSystemContextDelegate( 224 new GetFileSystemContextDelegate(
222 profile_id_, 225 profile_id_,
223 request()->url(), 226 request()->url(),
224 base::Bind(&DriveURLRequestJob::OnDelegateResultObtained, 227 base::Bind(&ExternalFileURLRequestJob::OnDelegateResultObtained,
225 weak_ptr_factory_.GetWeakPtr())); 228 weak_ptr_factory_.GetWeakPtr()));
226 } 229 }
227 230
228 void DriveURLRequestJob::OnDelegateResultObtained( 231 void ExternalFileURLRequestJob::OnDelegateResultObtained(
229 net::Error error, 232 net::Error error,
230 const scoped_refptr<storage::FileSystemContext>& file_system_context, 233 const scoped_refptr<storage::FileSystemContext>& file_system_context,
231 const storage::FileSystemURL& file_system_url, 234 const storage::FileSystemURL& file_system_url,
232 const std::string& mime_type) { 235 const std::string& mime_type) {
233 DCHECK_CURRENTLY_ON(BrowserThread::IO); 236 DCHECK_CURRENTLY_ON(BrowserThread::IO);
234 237
235 if (error != net::OK) { 238 if (error != net::OK) {
236 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 239 NotifyStartError(
237 error)); 240 net::URLRequestStatus(net::URLRequestStatus::FAILED, error));
238 return; 241 return;
239 } 242 }
240 243
241 DCHECK(file_system_context.get()); 244 DCHECK(file_system_context.get());
242 file_system_context_ = file_system_context; 245 file_system_context_ = file_system_context;
243 file_system_url_ = file_system_url; 246 file_system_url_ = file_system_url;
244 mime_type_ = mime_type; 247 mime_type_ = mime_type;
245 248
246 // Check if the entry has a redirect URL. 249 // Check if the entry has a redirect URL.
247 file_system_context_->external_backend()->GetRedirectURLForContents( 250 file_system_context_->external_backend()->GetRedirectURLForContents(
248 file_system_url_, 251 file_system_url_,
249 base::Bind(&DriveURLRequestJob::OnRedirectURLObtained, 252 base::Bind(&ExternalFileURLRequestJob::OnRedirectURLObtained,
250 weak_ptr_factory_.GetWeakPtr())); 253 weak_ptr_factory_.GetWeakPtr()));
251 } 254 }
252 255
253 void DriveURLRequestJob::OnRedirectURLObtained(const GURL& redirect_url) { 256 void ExternalFileURLRequestJob::OnRedirectURLObtained(
257 const GURL& redirect_url) {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
255 redirect_url_ = redirect_url; 259 redirect_url_ = redirect_url;
256 if (!redirect_url_.is_empty()) { 260 if (!redirect_url_.is_empty()) {
257 NotifyHeadersComplete(); 261 NotifyHeadersComplete();
258 return; 262 return;
259 } 263 }
260 264
261 // Obtain file system context. 265 // Obtain file system context.
262 file_system_context_->operation_runner()->GetMetadata( 266 file_system_context_->operation_runner()->GetMetadata(
263 file_system_url_, 267 file_system_url_,
264 base::Bind(&DriveURLRequestJob::OnFileInfoObtained, 268 base::Bind(&ExternalFileURLRequestJob::OnFileInfoObtained,
265 weak_ptr_factory_.GetWeakPtr())); 269 weak_ptr_factory_.GetWeakPtr()));
266 } 270 }
267 271
268 void DriveURLRequestJob::OnFileInfoObtained(base::File::Error result, 272 void ExternalFileURLRequestJob::OnFileInfoObtained(
269 const base::File::Info& file_info) { 273 base::File::Error result,
274 const base::File::Info& file_info) {
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
271 276
272 if (result == base::File::FILE_ERROR_NOT_FOUND) { 277 if (result == base::File::FILE_ERROR_NOT_FOUND) {
273 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 278 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
274 net::ERR_FILE_NOT_FOUND)); 279 net::ERR_FILE_NOT_FOUND));
275 return; 280 return;
276 } 281 }
277 282
278 if (result != base::File::FILE_OK || file_info.is_directory) { 283 if (result != base::File::FILE_OK || file_info.is_directory) {
279 NotifyStartError( 284 NotifyStartError(
(...skipping 17 matching lines...) Expand all
297 file_system_url_, offset, size, base::Time()); 302 file_system_url_, offset, size, base::Time());
298 if (!stream_reader_) { 303 if (!stream_reader_) {
299 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 304 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
300 net::ERR_FILE_NOT_FOUND)); 305 net::ERR_FILE_NOT_FOUND));
301 return; 306 return;
302 } 307 }
303 308
304 NotifyHeadersComplete(); 309 NotifyHeadersComplete();
305 } 310 }
306 311
307 void DriveURLRequestJob::Kill() { 312 void ExternalFileURLRequestJob::Kill() {
308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
309 314
310 stream_reader_.reset(); 315 stream_reader_.reset();
311 file_system_context_ = NULL; 316 file_system_context_ = NULL;
312 net::URLRequestJob::Kill(); 317 net::URLRequestJob::Kill();
313 weak_ptr_factory_.InvalidateWeakPtrs(); 318 weak_ptr_factory_.InvalidateWeakPtrs();
314 } 319 }
315 320
316 bool DriveURLRequestJob::GetMimeType(std::string* mime_type) const { 321 bool ExternalFileURLRequestJob::GetMimeType(std::string* mime_type) const {
317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
318 mime_type->assign(mime_type_); 323 mime_type->assign(mime_type_);
319 return !mime_type->empty(); 324 return !mime_type->empty();
320 } 325 }
321 326
322 bool DriveURLRequestJob::IsRedirectResponse( 327 bool ExternalFileURLRequestJob::IsRedirectResponse(GURL* location,
323 GURL* location, int* http_status_code) { 328 int* http_status_code) {
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
325 if (redirect_url_.is_empty()) 330 if (redirect_url_.is_empty())
326 return false; 331 return false;
327 332
328 // Redirect a hosted document. 333 // Redirect a hosted document.
329 *location = redirect_url_; 334 *location = redirect_url_;
330 const int kHttpFound = 302; 335 const int kHttpFound = 302;
331 *http_status_code = kHttpFound; 336 *http_status_code = kHttpFound;
332 return true; 337 return true;
333 } 338 }
334 339
335 bool DriveURLRequestJob::ReadRawData( 340 bool ExternalFileURLRequestJob::ReadRawData(net::IOBuffer* buf,
336 net::IOBuffer* buf, int buf_size, int* bytes_read) { 341 int buf_size,
342 int* bytes_read) {
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
338 DCHECK(stream_reader_); 344 DCHECK(stream_reader_);
339 345
340 if (remaining_bytes_ == 0) { 346 if (remaining_bytes_ == 0) {
341 *bytes_read = 0; 347 *bytes_read = 0;
342 return true; 348 return true;
343 } 349 }
344 350
345 const int result = stream_reader_->Read( 351 const int result = stream_reader_->Read(
346 buf, 352 buf,
347 std::min(static_cast<int64>(buf_size), remaining_bytes_), 353 std::min(static_cast<int64>(buf_size), remaining_bytes_),
348 base::Bind(&DriveURLRequestJob::OnReadCompleted, 354 base::Bind(&ExternalFileURLRequestJob::OnReadCompleted,
349 weak_ptr_factory_.GetWeakPtr())); 355 weak_ptr_factory_.GetWeakPtr()));
350 356
351 if (result == net::ERR_IO_PENDING) { 357 if (result == net::ERR_IO_PENDING) {
352 // The data is not yet available. 358 // The data is not yet available.
353 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); 359 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
354 return false; 360 return false;
355 } 361 }
356 if (result < 0) { 362 if (result < 0) {
357 // An error occurs. 363 // An error occurs.
358 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result)); 364 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
359 return false; 365 return false;
360 } 366 }
361 367
362 // Reading has been finished immediately. 368 // Reading has been finished immediately.
363 *bytes_read = result; 369 *bytes_read = result;
364 remaining_bytes_ -= result; 370 remaining_bytes_ -= result;
365 return true; 371 return true;
366 } 372 }
367 373
368 DriveURLRequestJob::~DriveURLRequestJob() { 374 ExternalFileURLRequestJob::~ExternalFileURLRequestJob() {
369 } 375 }
370 376
371 void DriveURLRequestJob::OnReadCompleted(int read_result) { 377 void ExternalFileURLRequestJob::OnReadCompleted(int read_result) {
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
373 379
374 if (read_result < 0) { 380 if (read_result < 0) {
375 DCHECK_NE(read_result, net::ERR_IO_PENDING); 381 DCHECK_NE(read_result, net::ERR_IO_PENDING);
376 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, 382 NotifyDone(
377 read_result)); 383 net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result));
378 } 384 }
379 385
380 remaining_bytes_ -= read_result; 386 remaining_bytes_ -= read_result;
381 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status. 387 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status.
382 NotifyReadComplete(read_result); 388 NotifyReadComplete(read_result);
383 } 389 }
384 390
385 } // namespace drive 391 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698