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

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

Powered by Google App Engine
This is Rietveld 408576698