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

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

Issue 27168: IPC messages and changes to ResourceLoaderBridge to support resource loading for media (Closed)
Patch Set: add mac/linux build and fixed unit test failures Created 11 years, 9 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
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10
11 #if defined(OS_POSIX)
12 #include <unistd.h>
13 #endif
14
10 #include "base/message_loop.h" 15 #include "base/message_loop.h"
11 #include "base/pickle.h" 16 #include "base/pickle.h"
12 #include "base/ref_counted.h" 17 #include "base/ref_counted.h"
13 #include "base/string_util.h" 18 #include "base/string_util.h"
14 #include "base/time.h" 19 #include "base/time.h"
15 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
16 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
17 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
18 #include "net/disk_cache/disk_cache.h" 23 #include "net/disk_cache/disk_cache.h"
19 #include "net/http/http_network_layer.h" 24 #include "net/http/http_network_layer.h"
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 if (cache_->mode() == PLAYBACK) 605 if (cache_->mode() == PLAYBACK)
601 effective_load_flags_ |= LOAD_ONLY_FROM_CACHE; 606 effective_load_flags_ |= LOAD_ONLY_FROM_CACHE;
602 607
603 // When in record mode, we want to NEVER load from the cache. 608 // When in record mode, we want to NEVER load from the cache.
604 // The reason for this is beacuse we save the Set-Cookie headers 609 // The reason for this is beacuse we save the Set-Cookie headers
605 // (intentionally). If we read from the cache, we replay them 610 // (intentionally). If we read from the cache, we replay them
606 // prematurely. 611 // prematurely.
607 if (cache_->mode() == RECORD) 612 if (cache_->mode() == RECORD)
608 effective_load_flags_ |= LOAD_BYPASS_CACHE; 613 effective_load_flags_ |= LOAD_BYPASS_CACHE;
609 614
615 // If HttpCache has type MEDIA make sure LOAD_ENABLE_DOWNLOAD_FILE is set,
616 // otherwise make sure LOAD_ENABLE_DOWNLOAD_FILE is not set when HttpCache
617 // has type other than MEDIA.
618 if (cache_->type() == HttpCache::MEDIA) {
619 DCHECK(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE);
620 } else {
621 DCHECK(!(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE));
622 }
623
610 // Some headers imply load flags. The order here is significant. 624 // Some headers imply load flags. The order here is significant.
611 // 625 //
612 // LOAD_DISABLE_CACHE : no cache read or write 626 // LOAD_DISABLE_CACHE : no cache read or write
613 // LOAD_BYPASS_CACHE : no cache read 627 // LOAD_BYPASS_CACHE : no cache read
614 // LOAD_VALIDATE_CACHE : no cache read unless validation 628 // LOAD_VALIDATE_CACHE : no cache read unless validation
615 // 629 //
616 // The former modes trump latter modes, so if we find a matching header we 630 // The former modes trump latter modes, so if we find a matching header we
617 // can stop iterating kSpecialHeaders. 631 // can stop iterating kSpecialHeaders.
618 // 632 //
619 static const struct { 633 static const struct {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 } 803 }
790 804
791 int HttpCache::Transaction::ReadResponseInfoFromEntry() { 805 int HttpCache::Transaction::ReadResponseInfoFromEntry() {
792 DCHECK(entry_); 806 DCHECK(entry_);
793 807
794 if (!HttpCache::ReadResponseInfo(entry_->disk_entry, &response_)) 808 if (!HttpCache::ReadResponseInfo(entry_->disk_entry, &response_))
795 return ERR_FAILED; 809 return ERR_FAILED;
796 810
797 // If the cache object is used for media file, we want the file handle of 811 // If the cache object is used for media file, we want the file handle of
798 // response data. 812 // response data.
799 if (cache_->type() == HttpCache::MEDIA) 813 if (cache_->type() == HttpCache::MEDIA) {
800 response_.response_data_file = 814 response_.response_data_file =
801 entry_->disk_entry->GetPlatformFile(kResponseContentIndex); 815 entry_->disk_entry->GetPlatformFile(kResponseContentIndex);
816 }
802 817
803 return OK; 818 return OK;
804 } 819 }
805 820
806 void HttpCache::Transaction::WriteToEntry(int index, int offset, 821 void HttpCache::Transaction::WriteToEntry(int index, int offset,
807 IOBuffer* data, int data_len) { 822 IOBuffer* data, int data_len) {
808 if (!entry_) 823 if (!entry_)
809 return; 824 return;
810 825
811 int rv = entry_->disk_entry->WriteData(index, offset, data, data_len, NULL, 826 int rv = entry_->disk_entry->WriteData(index, offset, data, data_len, NULL,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 877
863 // If the cache is for media files, we try to prepare the response data 878 // If the cache is for media files, we try to prepare the response data
864 // file as an external file and truncate it afterwards. 879 // file as an external file and truncate it afterwards.
865 // Recipient of ResponseInfo should judge from |response_.response_data_file| 880 // Recipient of ResponseInfo should judge from |response_.response_data_file|
866 // to tell whether an external file of response data is available for reading 881 // to tell whether an external file of response data is available for reading
867 // or not. 882 // or not.
868 // TODO(hclam): we should prepare the target stream as extern file only 883 // TODO(hclam): we should prepare the target stream as extern file only
869 // if we get a valid response from server, i.e. 200. We don't want empty 884 // if we get a valid response from server, i.e. 200. We don't want empty
870 // cache files for redirection or external files for erroneous requests. 885 // cache files for redirection or external files for erroneous requests.
871 response_.response_data_file = base::kInvalidPlatformFileValue; 886 response_.response_data_file = base::kInvalidPlatformFileValue;
872 if (cache_->type() == HttpCache::MEDIA) 887 if (cache_->type() == HttpCache::MEDIA) {
873 response_.response_data_file = 888 response_.response_data_file =
874 entry_->disk_entry->UseExternalFile(kResponseContentIndex); 889 entry_->disk_entry->UseExternalFile(kResponseContentIndex);
890 }
875 891
876 // Truncate the stream. 892 // Truncate the stream.
877 WriteToEntry(kResponseContentIndex, 0, NULL, 0); 893 WriteToEntry(kResponseContentIndex, 0, NULL, 0);
878 } 894 }
879 895
880 void HttpCache::Transaction::DoneWritingToEntry(bool success) { 896 void HttpCache::Transaction::DoneWritingToEntry(bool success) {
881 if (!entry_) 897 if (!entry_)
882 return; 898 return;
883 899
884 if (cache_->mode() == RECORD) 900 if (cache_->mode() == RECORD)
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 return; // have to wait 1468 return; // have to wait
1453 1469
1454 entry->pending_queue.erase(entry->pending_queue.begin()); 1470 entry->pending_queue.erase(entry->pending_queue.begin());
1455 1471
1456 AddTransactionToEntry(entry, next); 1472 AddTransactionToEntry(entry, next);
1457 } 1473 }
1458 1474
1459 //----------------------------------------------------------------------------- 1475 //-----------------------------------------------------------------------------
1460 1476
1461 } // namespace net 1477 } // namespace net
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698