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

Side by Side Diff: net/http/http_cache_transaction.cc

Issue 8569005: HTTP Cache: Implement StopCaching(), to avoid caching (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « no previous file | net/http/http_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/http/http_cache_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 // We don't need to track this operation for anything. 177 // We don't need to track this operation for anything.
178 // It could be possible to check if there is something already written and 178 // It could be possible to check if there is something already written and
179 // avoid writing again (it should be the same, right?), but let's allow the 179 // avoid writing again (it should be the same, right?), but let's allow the
180 // caller to "update" the contents with something new. 180 // caller to "update" the contents with something new.
181 return entry_->disk_entry->WriteData(kMetadataIndex, 0, buf, buf_len, 181 return entry_->disk_entry->WriteData(kMetadataIndex, 0, buf, buf_len,
182 callback, true); 182 callback, true);
183 } 183 }
184 184
185 bool HttpCache::Transaction::AddTruncatedFlag() { 185 bool HttpCache::Transaction::AddTruncatedFlag() {
186 DCHECK(mode_ & WRITE); 186 DCHECK(mode_ & WRITE || mode_ == NONE);
187 187
188 // Don't set the flag for sparse entries. 188 // Don't set the flag for sparse entries.
189 if (partial_.get() && !truncated_) 189 if (partial_.get() && !truncated_)
190 return true; 190 return true;
191 191
192 if (!CanResume(true)) 192 if (!CanResume(true))
193 return false; 193 return false;
194 194
195 // We may have received the whole resource already. 195 // We may have received the whole resource already.
196 if (done_reading_) 196 if (done_reading_)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 355 }
356 356
357 if (rv == ERR_IO_PENDING) { 357 if (rv == ERR_IO_PENDING) {
358 DCHECK(!callback_); 358 DCHECK(!callback_);
359 callback_ = callback; 359 callback_ = callback;
360 } 360 }
361 return rv; 361 return rv;
362 } 362 }
363 363
364 void HttpCache::Transaction::StopCaching() { 364 void HttpCache::Transaction::StopCaching() {
365 // We really don't know where we are now. Hopefully there is no operation in
366 // progress, but nothing really prevents this method to be called after we
367 // returned ERR_IO_PENDING. We cannot attempt to truncate the entry at this
368 // point because we need the state machine for that (and even if we are really
369 // free, that would be an asynchronous operation). In other words, keep the
370 // entry how it is (it will be marked as truncated at destruction), and let
371 // the next piece of code that executes know that we are now reading directly
372 // from the net.
373 if (cache_ && entry_ && (mode_ & WRITE))
374 mode_ = NONE;
365 } 375 }
366 376
367 void HttpCache::Transaction::DoneReading() { 377 void HttpCache::Transaction::DoneReading() {
368 if (cache_ && entry_) { 378 if (cache_ && entry_) {
369 DCHECK(reading_); 379 DCHECK(reading_);
370 DCHECK_NE(mode_, UPDATE); 380 DCHECK_NE(mode_, UPDATE);
371 if (mode_ & WRITE) 381 if (mode_ & WRITE)
372 DoneWritingToEntry(true); 382 DoneWritingToEntry(true);
373 } 383 }
374 } 384 }
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 next_state_ = STATE_NETWORK_READ_COMPLETE; 797 next_state_ = STATE_NETWORK_READ_COMPLETE;
788 return network_trans_->Read(read_buf_, io_buf_len_, &io_callback_); 798 return network_trans_->Read(read_buf_, io_buf_len_, &io_callback_);
789 } 799 }
790 800
791 int HttpCache::Transaction::DoNetworkReadComplete(int result) { 801 int HttpCache::Transaction::DoNetworkReadComplete(int result) {
792 DCHECK(mode_ & WRITE || mode_ == NONE); 802 DCHECK(mode_ & WRITE || mode_ == NONE);
793 803
794 if (!cache_) 804 if (!cache_)
795 return ERR_UNEXPECTED; 805 return ERR_UNEXPECTED;
796 806
797 // If there is an error and we are saving the data, just tell the user about 807 // If there is an error or we aren't saving the data, we are done; just wait
798 // it and wait until the destructor runs to see if we can keep the data. 808 // until the destructor runs to see if we can keep the data.
799 if (mode_ != NONE && result < 0) 809 if (mode_ == NONE || result < 0)
800 return result; 810 return result;
801 811
802 next_state_ = STATE_CACHE_WRITE_DATA; 812 next_state_ = STATE_CACHE_WRITE_DATA;
803 return result; 813 return result;
804 } 814 }
805 815
806 int HttpCache::Transaction::DoInitEntry() { 816 int HttpCache::Transaction::DoInitEntry() {
807 DCHECK(!new_entry_); 817 DCHECK(!new_entry_);
808 818
809 if (!cache_) 819 if (!cache_)
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 return false; 2068 return false;
2059 2069
2060 return true; 2070 return true;
2061 } 2071 }
2062 2072
2063 void HttpCache::Transaction::OnIOComplete(int result) { 2073 void HttpCache::Transaction::OnIOComplete(int result) {
2064 DoLoop(result); 2074 DoLoop(result);
2065 } 2075 }
2066 2076
2067 } // namespace net 2077 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698