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/appcache/appcache_response.h" | 5 #include "webkit/appcache/appcache_response.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 241 } |
242 | 242 |
243 void AppCacheResponseReader::OpenEntryIfNeededAndContinue() { | 243 void AppCacheResponseReader::OpenEntryIfNeededAndContinue() { |
244 int rv; | 244 int rv; |
245 AppCacheDiskCacheInterface::Entry** entry_ptr = NULL; | 245 AppCacheDiskCacheInterface::Entry** entry_ptr = NULL; |
246 if (entry_) { | 246 if (entry_) { |
247 rv = net::OK; | 247 rv = net::OK; |
248 } else if (!disk_cache_) { | 248 } else if (!disk_cache_) { |
249 rv = net::ERR_FAILED; | 249 rv = net::ERR_FAILED; |
250 } else { | 250 } else { |
251 entry_ptr = new(AppCacheDiskCacheInterface::Entry*); | 251 entry_ptr = new AppCacheDiskCacheInterface::Entry*; |
252 open_callback_ = | 252 open_callback_ = |
253 base::Bind(&AppCacheResponseReader::OnOpenEntryComplete, | 253 base::Bind(&AppCacheResponseReader::OnOpenEntryComplete, |
254 weak_factory_.GetWeakPtr(), base::Owned(entry_ptr)); | 254 weak_factory_.GetWeakPtr(), base::Owned(entry_ptr)); |
255 rv = disk_cache_->OpenEntry(response_id_, entry_ptr, open_callback_); | 255 rv = disk_cache_->OpenEntry(response_id_, entry_ptr, open_callback_); |
256 } | 256 } |
257 | 257 |
258 if (rv != net::ERR_IO_PENDING) | 258 if (rv != net::ERR_IO_PENDING) |
259 OnOpenEntryComplete(entry_ptr, rv); | 259 OnOpenEntryComplete(entry_ptr, rv); |
260 } | 260 } |
261 | 261 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 int rv; | 361 int rv; |
362 AppCacheDiskCacheInterface::Entry** entry_ptr = NULL; | 362 AppCacheDiskCacheInterface::Entry** entry_ptr = NULL; |
363 if (entry_) { | 363 if (entry_) { |
364 creation_phase_ = NO_ATTEMPT; | 364 creation_phase_ = NO_ATTEMPT; |
365 rv = net::OK; | 365 rv = net::OK; |
366 } else if (!disk_cache_) { | 366 } else if (!disk_cache_) { |
367 creation_phase_ = NO_ATTEMPT; | 367 creation_phase_ = NO_ATTEMPT; |
368 rv = net::ERR_FAILED; | 368 rv = net::ERR_FAILED; |
369 } else { | 369 } else { |
370 creation_phase_ = INITIAL_ATTEMPT; | 370 creation_phase_ = INITIAL_ATTEMPT; |
371 entry_ptr = new(AppCacheDiskCacheInterface::Entry*); | 371 entry_ptr = new AppCacheDiskCacheInterface::Entry*; |
372 create_callback_ = | 372 create_callback_ = |
373 base::Bind(&AppCacheResponseWriter::OnCreateEntryComplete, | 373 base::Bind(&AppCacheResponseWriter::OnCreateEntryComplete, |
374 base::Unretained(this), base::Owned(entry_ptr)); | 374 weak_factory_.GetWeakPtr(), base::Owned(entry_ptr)); |
375 rv = disk_cache_->CreateEntry(response_id_, entry_ptr, create_callback_); | 375 rv = disk_cache_->CreateEntry(response_id_, entry_ptr, create_callback_); |
376 } | 376 } |
377 if (rv != net::ERR_IO_PENDING) | 377 if (rv != net::ERR_IO_PENDING) |
378 OnCreateEntryComplete(entry_ptr, rv); | 378 OnCreateEntryComplete(entry_ptr, rv); |
379 } | 379 } |
380 | 380 |
381 void AppCacheResponseWriter::OnCreateEntryComplete( | 381 void AppCacheResponseWriter::OnCreateEntryComplete( |
382 AppCacheDiskCacheInterface::Entry** entry, int rv) { | 382 AppCacheDiskCacheInterface::Entry** entry, int rv) { |
383 DCHECK(info_buffer_.get() || buffer_.get()); | 383 DCHECK(info_buffer_.get() || buffer_.get()); |
384 | 384 |
385 AppCacheDiskCacheInterface::Entry** entry_ptr = NULL; | |
386 | |
387 if (creation_phase_ == INITIAL_ATTEMPT) { | 385 if (creation_phase_ == INITIAL_ATTEMPT) { |
388 if (rv != net::OK) { | 386 if (rv != net::OK) { |
389 // We may try to overwrite existing entries. | 387 // We may try to overwrite existing entries. |
390 creation_phase_ = DOOM_EXISTING; | 388 creation_phase_ = DOOM_EXISTING; |
391 rv = disk_cache_->DoomEntry(response_id_, create_callback_); | 389 rv = disk_cache_->DoomEntry(response_id_, create_callback_); |
392 if (rv != net::ERR_IO_PENDING) | 390 if (rv != net::ERR_IO_PENDING) |
393 OnCreateEntryComplete(NULL, rv); | 391 OnCreateEntryComplete(NULL, rv); |
394 return; | 392 return; |
395 } | 393 } |
396 } else if (creation_phase_ == DOOM_EXISTING) { | 394 } else if (creation_phase_ == DOOM_EXISTING) { |
397 creation_phase_ = SECOND_ATTEMPT; | 395 creation_phase_ = SECOND_ATTEMPT; |
398 entry_ptr = new(AppCacheDiskCacheInterface::Entry*); | 396 AppCacheDiskCacheInterface::Entry** entry_ptr = |
| 397 new AppCacheDiskCacheInterface::Entry*; |
399 create_callback_ = | 398 create_callback_ = |
400 base::Bind(&AppCacheResponseWriter::OnCreateEntryComplete, | 399 base::Bind(&AppCacheResponseWriter::OnCreateEntryComplete, |
401 base::Unretained(this), base::Owned(entry_ptr)); | 400 weak_factory_.GetWeakPtr(), base::Owned(entry_ptr)); |
402 rv = disk_cache_->CreateEntry(response_id_, entry_ptr, create_callback_); | 401 rv = disk_cache_->CreateEntry(response_id_, entry_ptr, create_callback_); |
403 if (rv != net::ERR_IO_PENDING) | 402 if (rv != net::ERR_IO_PENDING) |
404 OnCreateEntryComplete(entry_ptr, rv); | 403 OnCreateEntryComplete(entry_ptr, rv); |
405 return; | 404 return; |
406 } | 405 } |
407 | 406 |
408 if (!create_callback_.is_null()) { | 407 if (!create_callback_.is_null()) { |
409 if (rv == net::OK) | 408 if (rv == net::OK) |
410 entry_ = *entry; | 409 entry_ = *entry; |
411 | 410 |
412 create_callback_.Reset(); | 411 create_callback_.Reset(); |
413 } | 412 } |
414 | 413 |
415 if (info_buffer_) | 414 if (info_buffer_) |
416 ContinueWriteInfo(); | 415 ContinueWriteInfo(); |
417 else | 416 else |
418 ContinueWriteData(); | 417 ContinueWriteData(); |
419 } | 418 } |
420 | 419 |
421 } // namespace appcache | 420 } // namespace appcache |
OLD | NEW |