summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-06 03:26:41 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-06 03:26:41 +0000
commitfd4882e6faab19e1de6d791acebfa3b34faf5701 (patch)
tree2fa95bddd8b6189d0dd7b850d24da0b7ab382e28
parent12e8fecd3923d3ace7fe3f505ba3fa490b5417c1 (diff)
downloadchromium_src-fd4882e6faab19e1de6d791acebfa3b34faf5701.zip
chromium_src-fd4882e6faab19e1de6d791acebfa3b34faf5701.tar.gz
chromium_src-fd4882e6faab19e1de6d791acebfa3b34faf5701.tar.bz2
AppCache quota tracking groundwork, store response sizes in the SQL database.
TEST=updated existing unittests BUG=none Review URL: http://codereview.chromium.org/523046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35609 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/appcache/appcache.cc10
-rw-r--r--webkit/appcache/appcache.h5
-rw-r--r--webkit/appcache/appcache_database.cc30
-rw-r--r--webkit/appcache/appcache_database.h2
-rw-r--r--webkit/appcache/appcache_database_unittest.cc9
-rw-r--r--webkit/appcache/appcache_entry.h14
-rw-r--r--webkit/appcache/appcache_response.cc2
-rw-r--r--webkit/appcache/appcache_response.h6
-rw-r--r--webkit/appcache/appcache_response_unittest.cc35
-rw-r--r--webkit/appcache/appcache_storage.h8
-rw-r--r--webkit/appcache/appcache_storage_impl_unittest.cc6
-rw-r--r--webkit/appcache/appcache_unittest.cc5
-rw-r--r--webkit/appcache/appcache_update_job.cc25
13 files changed, 128 insertions, 29 deletions
diff --git a/webkit/appcache/appcache.cc b/webkit/appcache/appcache.cc
index ec00cc4..e1819d4 100644
--- a/webkit/appcache/appcache.cc
+++ b/webkit/appcache/appcache.cc
@@ -44,13 +44,15 @@ void AppCache::AddEntry(const GURL& url, const AppCacheEntry& entry) {
entries_.insert(EntryMap::value_type(url, entry));
}
-void AppCache::AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry) {
+bool AppCache::AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry) {
std::pair<EntryMap::iterator, bool> ret =
entries_.insert(EntryMap::value_type(url, entry));
// Entry already exists. Merge the types of the new and existing entries.
if (!ret.second)
ret.first->second.add_types(entry.types());
+
+ return ret.second;
}
AppCacheEntry* AppCache::GetEntry(const GURL& url) {
@@ -90,7 +92,8 @@ void AppCache::InitializeWithDatabaseRecords(
for (size_t i = 0; i < entries.size(); ++i) {
const AppCacheDatabase::EntryRecord& entry = entries.at(i);
- AddEntry(entry.url, AppCacheEntry(entry.flags, entry.response_id));
+ AddEntry(entry.url, AppCacheEntry(entry.flags, entry.response_id,
+ entry.response_size));
}
for (size_t i = 0; i < fallbacks.size(); ++i) {
@@ -124,6 +127,7 @@ void AppCache::ToDatabaseRecords(
cache_record->group_id = group->group_id();
cache_record->online_wildcard = online_whitelist_all_;
cache_record->update_time = update_time_;
+ cache_record->cache_size = 0;
for (EntryMap::const_iterator iter = entries_.begin();
iter != entries_.end(); ++iter) {
@@ -133,6 +137,8 @@ void AppCache::ToDatabaseRecords(
record.cache_id = cache_id_;
record.flags = iter->second.types();
record.response_id = iter->second.response_id();
+ record.response_size = iter->second.response_size();
+ cache_record->cache_size += record.response_size;
}
GURL origin = group->manifest_url().GetOrigin();
diff --git a/webkit/appcache/appcache.h b/webkit/appcache/appcache.h
index c4446f9..d99393f 100644
--- a/webkit/appcache/appcache.h
+++ b/webkit/appcache/appcache.h
@@ -47,8 +47,9 @@ class AppCache : public base::RefCounted<AppCache> {
void AddEntry(const GURL& url, const AppCacheEntry& entry);
// Adds a new entry or modifies an existing entry by merging the types
- // of the new entry with the existing entry.
- void AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry);
+ // of the new entry with the existing entry. Returns true if a new entry
+ // is added, false if the flags are merged into an existing entry.
+ bool AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry);
// Do not store the returned object as it could be deleted anytime.
AppCacheEntry* GetEntry(const GURL& url);
diff --git a/webkit/appcache/appcache_database.cc b/webkit/appcache/appcache_database.cc
index fd2a9e9..606d6c1 100644
--- a/webkit/appcache/appcache_database.cc
+++ b/webkit/appcache/appcache_database.cc
@@ -38,13 +38,15 @@ const struct {
"(cache_id INTEGER PRIMARY KEY,"
" group_id INTEGER,"
" online_wildcard INTEGER CHECK(online_wildcard IN (0, 1)),"
- " update_time INTEGER)" },
+ " update_time INTEGER,"
+ " cache_size INTEGER)" }, // intentionally not normalized
{ kEntriesTable,
"(cache_id INTEGER,"
" url TEXT,"
" flags INTEGER,"
- " response_id INTEGER)" },
+ " response_id INTEGER,"
+ " response_size INTEGER)" },
{ kFallbackNameSpacesTable,
"(cache_id INTEGER,"
@@ -315,7 +317,7 @@ bool AppCacheDatabase::FindCache(int64 cache_id, CacheRecord* record) {
return false;
const char* kSql =
- "SELECT cache_id, group_id, online_wildcard, update_time"
+ "SELECT cache_id, group_id, online_wildcard, update_time, cache_size"
" FROM Caches WHERE cache_id = ?";
sql::Statement statement;
@@ -336,7 +338,7 @@ bool AppCacheDatabase::FindCacheForGroup(int64 group_id, CacheRecord* record) {
return false;
const char* kSql =
- "SELECT cache_id, group_id, online_wildcard, update_time"
+ "SELECT cache_id, group_id, online_wildcard, update_time, cache_size"
" FROM Caches WHERE group_id = ?";
sql::Statement statement;
@@ -357,8 +359,8 @@ bool AppCacheDatabase::InsertCache(const CacheRecord* record) {
const char* kSql =
"INSERT INTO Caches (cache_id, group_id, online_wildcard,"
- " update_time)"
- " VALUES(?, ?, ?, ?)";
+ " update_time, cache_size)"
+ " VALUES(?, ?, ?, ?, ?)";
sql::Statement statement;
if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement))
@@ -374,6 +376,8 @@ bool AppCacheDatabase::InsertCache(const CacheRecord* record) {
statement.BindInt64(3,
(record->update_time - base::TimeTicks()).InMicroseconds());
+ statement.BindInt64(4, record->cache_size);
+
return statement.Run();
}
@@ -399,7 +403,7 @@ bool AppCacheDatabase::FindEntriesForCache(
return false;
const char* kSql =
- "SELECT cache_id, url, flags, response_id FROM Entries"
+ "SELECT cache_id, url, flags, response_id, response_size FROM Entries"
" WHERE cache_id = ?";
sql::Statement statement;
@@ -423,7 +427,7 @@ bool AppCacheDatabase::FindEntriesForUrl(
return false;
const char* kSql =
- "SELECT cache_id, url, flags, response_id FROM Entries"
+ "SELECT cache_id, url, flags, response_id, response_size FROM Entries"
" WHERE url = ?";
sql::Statement statement;
@@ -448,7 +452,7 @@ bool AppCacheDatabase::FindEntry(
return false;
const char* kSql =
- "SELECT cache_id, url, flags, response_id FROM Entries"
+ "SELECT cache_id, url, flags, response_id, response_size FROM Entries"
" WHERE cache_id = ? AND url = ?";
sql::Statement statement;
@@ -471,8 +475,8 @@ bool AppCacheDatabase::InsertEntry(const EntryRecord* record) {
return false;
const char* kSql =
- "INSERT INTO Entries (cache_id, url, flags, response_id)"
- " VALUES(?, ?, ?, ?)";
+ "INSERT INTO Entries (cache_id, url, flags, response_id, response_size)"
+ " VALUES(?, ?, ?, ?, ?)";
sql::Statement statement;
if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement))
@@ -482,6 +486,7 @@ bool AppCacheDatabase::InsertEntry(const EntryRecord* record) {
statement.BindString(1, record->url.spec());
statement.BindInt(2, record->flags);
statement.BindInt64(3, record->response_id);
+ statement.BindInt64(4, record->response_size);
return statement.Run();
}
@@ -728,6 +733,8 @@ void AppCacheDatabase::ReadCacheRecord(
// as an intermediary step.
record->update_time = base::TimeTicks() +
base::TimeDelta::FromMicroseconds(statement.ColumnInt64(3));
+
+ record->cache_size = statement.ColumnInt64(4);
}
void AppCacheDatabase::ReadEntryRecord(
@@ -736,6 +743,7 @@ void AppCacheDatabase::ReadEntryRecord(
record->url = GURL(statement.ColumnString(1));
record->flags = statement.ColumnInt(2);
record->response_id = statement.ColumnInt64(3);
+ record->response_size = statement.ColumnInt64(4);
}
void AppCacheDatabase::ReadFallbackNameSpaceRecord(
diff --git a/webkit/appcache/appcache_database.h b/webkit/appcache/appcache_database.h
index 89ff701..968a188 100644
--- a/webkit/appcache/appcache_database.h
+++ b/webkit/appcache/appcache_database.h
@@ -37,6 +37,7 @@ class AppCacheDatabase {
int64 group_id;
bool online_wildcard;
base::TimeTicks update_time;
+ int64 cache_size; // the sum of all response sizes in this cache
};
struct EntryRecord {
@@ -44,6 +45,7 @@ class AppCacheDatabase {
GURL url;
int flags;
int64 response_id;
+ int64 response_size;
};
struct FallbackNameSpaceRecord {
diff --git a/webkit/appcache/appcache_database_unittest.cc b/webkit/appcache/appcache_database_unittest.cc
index 62ff4ca..baaeb16 100644
--- a/webkit/appcache/appcache_database_unittest.cc
+++ b/webkit/appcache/appcache_database_unittest.cc
@@ -89,6 +89,7 @@ TEST(AppCacheDatabaseTest, EntryRecords) {
entry.url = GURL("http://blah/1");
entry.flags = AppCacheEntry::MASTER;
entry.response_id = 1;
+ entry.response_size = 100;
EXPECT_TRUE(db.InsertEntry(&entry));
EXPECT_FALSE(db.InsertEntry(&entry));
@@ -96,12 +97,14 @@ TEST(AppCacheDatabaseTest, EntryRecords) {
entry.url = GURL("http://blah/2");
entry.flags = AppCacheEntry::EXPLICIT;
entry.response_id = 2;
+ entry.response_size = 200;
EXPECT_TRUE(db.InsertEntry(&entry));
entry.cache_id = 2;
entry.url = GURL("http://blah/3");
entry.flags = AppCacheEntry::MANIFEST;
entry.response_id = 3;
+ entry.response_size = 300;
EXPECT_TRUE(db.InsertEntry(&entry));
std::vector<AppCacheDatabase::EntryRecord> found;
@@ -112,6 +115,7 @@ TEST(AppCacheDatabaseTest, EntryRecords) {
EXPECT_EQ(GURL("http://blah/1"), found[0].url);
EXPECT_EQ(AppCacheEntry::MASTER, found[0].flags);
EXPECT_EQ(1, found[0].response_id);
+ EXPECT_EQ(100, found[0].response_size);
found.clear();
EXPECT_TRUE(db.AddEntryFlags(GURL("http://blah/1"), 1,
@@ -127,10 +131,12 @@ TEST(AppCacheDatabaseTest, EntryRecords) {
EXPECT_EQ(GURL("http://blah/2"), found[0].url);
EXPECT_EQ(AppCacheEntry::EXPLICIT, found[0].flags);
EXPECT_EQ(2, found[0].response_id);
+ EXPECT_EQ(200, found[0].response_size);
EXPECT_EQ(2, found[1].cache_id);
EXPECT_EQ(GURL("http://blah/3"), found[1].url);
EXPECT_EQ(AppCacheEntry::MANIFEST, found[1].flags);
EXPECT_EQ(3, found[1].response_id);
+ EXPECT_EQ(300, found[1].response_size);
found.clear();
EXPECT_TRUE(db.DeleteEntriesForCache(2));
@@ -159,6 +165,7 @@ TEST(AppCacheDatabaseTest, CacheRecords) {
record.group_id = 1;
record.online_wildcard = true;
record.update_time = kZeroTimeTicks;
+ record.cache_size = 100;
EXPECT_TRUE(db.InsertCache(&record));
EXPECT_FALSE(db.InsertCache(&record));
@@ -168,6 +175,7 @@ TEST(AppCacheDatabaseTest, CacheRecords) {
EXPECT_EQ(1, record.group_id);
EXPECT_TRUE(record.online_wildcard);
EXPECT_TRUE(kZeroTimeTicks == record.update_time);
+ EXPECT_EQ(100, record.cache_size);
record = kZeroRecord;
EXPECT_TRUE(db.FindCacheForGroup(1, &record));
@@ -175,6 +183,7 @@ TEST(AppCacheDatabaseTest, CacheRecords) {
EXPECT_EQ(1, record.group_id);
EXPECT_TRUE(record.online_wildcard);
EXPECT_TRUE(kZeroTimeTicks == record.update_time);
+ EXPECT_EQ(100, record.cache_size);
EXPECT_TRUE(db.DeleteCache(1));
EXPECT_FALSE(db.FindCache(1, &record));
diff --git a/webkit/appcache/appcache_entry.h b/webkit/appcache/appcache_entry.h
index ac67ac3..71239e2 100644
--- a/webkit/appcache/appcache_entry.h
+++ b/webkit/appcache/appcache_entry.h
@@ -24,13 +24,17 @@ class AppCacheEntry {
FALLBACK = 1 << 4,
};
- AppCacheEntry() : types_(0), response_id_(kNoResponseId) {}
+ AppCacheEntry()
+ : types_(0), response_id_(kNoResponseId), response_size_(0) {}
explicit AppCacheEntry(int type)
- : types_(type), response_id_(kNoResponseId) {}
+ : types_(type), response_id_(kNoResponseId), response_size_(0) {}
AppCacheEntry(int type, int64 response_id)
- : types_(type), response_id_(response_id) {}
+ : types_(type), response_id_(response_id), response_size_(0) {}
+
+ AppCacheEntry(int type, int64 response_id, int64 response_size)
+ : types_(type), response_id_(response_id), response_size_(response_size) {}
int types() const { return types_; }
void add_types(int added_types) { types_ |= added_types; }
@@ -44,9 +48,13 @@ class AppCacheEntry {
void set_response_id(int64 id) { response_id_ = id; }
bool has_response_id() const { return response_id_ != kNoResponseId; }
+ int64 response_size() const { return response_size_; }
+ void set_response_size(int64 size) { response_size_ = size; }
+
private:
int types_;
int64 response_id_;
+ int64 response_size_;
};
} // namespace appcache
diff --git a/webkit/appcache/appcache_response.cc b/webkit/appcache/appcache_response.cc
index 09894a2..5f92439 100644
--- a/webkit/appcache/appcache_response.cc
+++ b/webkit/appcache/appcache_response.cc
@@ -256,6 +256,8 @@ void AppCacheResponseWriter::OnIOComplete(int result) {
DCHECK(write_amount_ == result);
if (!info_buffer_.get())
write_position_ += result;
+ else
+ info_size_ = result;
}
InvokeUserCompletionCallback(result);
}
diff --git a/webkit/appcache/appcache_response.h b/webkit/appcache/appcache_response.h
index 419e739..f8ffcc6 100644
--- a/webkit/appcache/appcache_response.h
+++ b/webkit/appcache/appcache_response.h
@@ -184,6 +184,9 @@ class AppCacheResponseWriter : public AppCacheResponseIO {
// Returns true if there is a write pending.
bool IsWritePending() { return IsIOPending(); }
+ // Returns the amount written, info and data.
+ int64 amount_written() { return info_size_ + write_position_; }
+
private:
friend class AppCacheStorageImpl;
friend class MockAppCacheStorage;
@@ -191,11 +194,12 @@ class AppCacheResponseWriter : public AppCacheResponseIO {
// Should only be constructed by the storage class.
AppCacheResponseWriter(int64 response_id, disk_cache::Backend* disk_cache)
: AppCacheResponseIO(response_id, disk_cache),
- write_position_(0), write_amount_(0) {}
+ info_size_(0), write_position_(0), write_amount_(0) {}
virtual void OnIOComplete(int result);
bool CreateEntryIfNeeded();
+ int info_size_;
int write_position_;
int write_amount_;
};
diff --git a/webkit/appcache/appcache_response_unittest.cc b/webkit/appcache/appcache_response_unittest.cc
index 824e73c..2989592 100644
--- a/webkit/appcache/appcache_response_unittest.cc
+++ b/webkit/appcache/appcache_response_unittest.cc
@@ -371,6 +371,37 @@ class AppCacheResponseTest : public testing::Test {
TestFinished();
}
+ // AmountWritten ----------------------------------------------------
+
+ void AmountWritten() {
+ static const char kHttpHeaders[] =
+ "HTTP/1.0 200 OK\0\0";
+ std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders));
+ net::HttpResponseInfo* head = MakeHttpResponseInfo(raw_headers);
+ int expected_amount_written =
+ GetHttpResponseInfoSize(head) + kNumBlocks * kBlockSize;
+
+ // Push tasks in reverse order.
+ PushNextTask(method_factory_.NewRunnableMethod(
+ &AppCacheResponseTest::Verify_AmountWritten, expected_amount_written));
+ for (int i = 0; i < kNumBlocks; ++i) {
+ PushNextTask(method_factory_.NewRunnableMethod(
+ &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
+ }
+ PushNextTask(method_factory_.NewRunnableMethod(
+ &AppCacheResponseTest::WriteResponseHead, head));
+
+ writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
+ written_response_id_ = writer_->response_id();
+ ScheduleNextTask();
+ }
+
+ void Verify_AmountWritten(int expected_amount_written) {
+ EXPECT_EQ(expected_amount_written, writer_->amount_written());
+ TestFinished();
+ }
+
+
// WriteThenVariouslyReadResponse -------------------------------------------
void WriteThenVariouslyReadResponse() {
@@ -658,6 +689,10 @@ TEST_F(AppCacheResponseTest, LoadResponseInfo_Hit) {
RunTestOnIOThread(&AppCacheResponseTest::LoadResponseInfo_Hit);
}
+TEST_F(AppCacheResponseTest, AmountWritten) {
+ RunTestOnIOThread(&AppCacheResponseTest::AmountWritten);
+}
+
TEST_F(AppCacheResponseTest, WriteThenVariouslyReadResponse) {
RunTestOnIOThread(&AppCacheResponseTest::WriteThenVariouslyReadResponse);
}
diff --git a/webkit/appcache/appcache_storage.h b/webkit/appcache/appcache_storage.h
index aa09eb6..7c31ca5 100644
--- a/webkit/appcache/appcache_storage.h
+++ b/webkit/appcache/appcache_storage.h
@@ -140,10 +140,16 @@ class AppCacheStorage {
virtual AppCacheResponseWriter* CreateResponseWriter(
const GURL& manifest_url) = 0;
- // Schedules the deletion of many responses.
+ // Schedules the imminent deletion of many responses.
virtual void DoomResponses(
const GURL& manifest_url, const std::vector<int64>& response_ids) = 0;
+ // Schedules the imminent deletion of a single response.
+ void DoomResponse(const GURL& manifest_url, int64 response_id) {
+ std::vector<int64> response_ids(1, response_id);
+ DoomResponses(manifest_url, response_ids);
+ }
+
// Generates unique storage ids for different object types.
int64 NewCacheId() {
return ++last_cache_id_;
diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc
index 1db4aa8..cbb366a 100644
--- a/webkit/appcache/appcache_storage_impl_unittest.cc
+++ b/webkit/appcache/appcache_storage_impl_unittest.cc
@@ -458,7 +458,7 @@ class AppCacheStorageImplTest : public testing::Test {
// Change the cache.
base::TimeTicks now = base::TimeTicks::Now();
- cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER));
+ cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 100));
cache_->set_update_time(now);
PushNextTask(method_factory_.NewRunnableMethod(
@@ -482,6 +482,7 @@ class AppCacheStorageImplTest : public testing::Test {
EXPECT_EQ(1, cache_record.group_id);
EXPECT_FALSE(cache_record.online_wildcard);
EXPECT_TRUE(expected_update_time == cache_record.update_time);
+ EXPECT_EQ(100, cache_record.cache_size);
std::vector<AppCacheDatabase::EntryRecord> entry_records;
EXPECT_TRUE(database()->FindEntriesForCache(1, &entry_records));
@@ -489,7 +490,8 @@ class AppCacheStorageImplTest : public testing::Test {
EXPECT_EQ(1 , entry_records[0].cache_id);
EXPECT_EQ(kEntryUrl, entry_records[0].url);
EXPECT_EQ(AppCacheEntry::MASTER, entry_records[0].flags);
- EXPECT_EQ(0, entry_records[0].response_id);
+ EXPECT_EQ(1, entry_records[0].response_id);
+ EXPECT_EQ(100, entry_records[0].response_size);
TestFinished();
}
diff --git a/webkit/appcache/appcache_unittest.cc b/webkit/appcache/appcache_unittest.cc
index 9f41cd0e7..6177d13 100644
--- a/webkit/appcache/appcache_unittest.cc
+++ b/webkit/appcache/appcache_unittest.cc
@@ -43,11 +43,12 @@ TEST(AppCacheTest, AddModifyEntry) {
const GURL kUrl2("http://bar.com");
AppCacheEntry entry2(AppCacheEntry::FALLBACK);
- cache->AddOrModifyEntry(kUrl2, entry2);
+ EXPECT_TRUE(cache->AddOrModifyEntry(kUrl2, entry2));
EXPECT_EQ(entry2.types(), cache->GetEntry(kUrl2)->types());
+ // Expected to return false when an existing entry is modified.
AppCacheEntry entry3(AppCacheEntry::EXPLICIT);
- cache->AddOrModifyEntry(kUrl1, entry3);
+ EXPECT_FALSE(cache->AddOrModifyEntry(kUrl1, entry3));
EXPECT_EQ((AppCacheEntry::MASTER | AppCacheEntry::EXPLICIT),
cache->GetEntry(kUrl1)->types());
EXPECT_EQ(entry2.types(), cache->GetEntry(kUrl2)->types()); // unchanged
diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc
index 04c409e..a1f4ec5 100644
--- a/webkit/appcache/appcache_update_job.cc
+++ b/webkit/appcache/appcache_update_job.cc
@@ -539,8 +539,10 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLRequest* request) {
static_cast<UpdateJobInfo*>(request->GetUserData(this));
DCHECK(info->response_writer_.get());
entry.set_response_id(info->response_writer_->response_id());
+ entry.set_response_size(info->response_writer_->amount_written());
- inprogress_cache_->AddOrModifyEntry(url, entry);
+ if (!inprogress_cache_->AddOrModifyEntry(url, entry))
+ service_->storage()->DoomResponse(manifest_url_, entry.response_id());
// Foreign entries will be detected during cache selection.
// Note: 6.9.4, step 17.9 possible optimization: if resource is HTML or XML
@@ -567,6 +569,7 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLRequest* request) {
AppCacheEntry* copy = cache->GetEntry(url);
if (copy) {
entry.set_response_id(copy->response_id());
+ entry.set_response_size(copy->response_size());
inprogress_cache_->AddOrModifyEntry(url, entry);
}
}
@@ -607,8 +610,12 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLRequest* request) {
group_->newest_complete_cache();
DCHECK(info->response_writer_.get());
AppCacheEntry master_entry(AppCacheEntry::MASTER,
- info->response_writer_->response_id());
- cache->AddOrModifyEntry(url, master_entry);
+ info->response_writer_->response_id(),
+ info->response_writer_->amount_written());
+ if (!cache->AddOrModifyEntry(url, master_entry)) {
+ service_->storage()->DoomResponse(
+ manifest_url_, master_entry.response_id());
+ }
// In no-update case, associate host with the newest cache.
if (!inprogress_cache_) {
@@ -701,8 +708,10 @@ void AppCacheUpdateJob::OnManifestInfoWriteComplete(int result) {
void AppCacheUpdateJob::OnManifestDataWriteComplete(int result) {
if (result > 0) {
AppCacheEntry entry(AppCacheEntry::MANIFEST,
- manifest_response_writer_->response_id());
- inprogress_cache_->AddOrModifyEntry(manifest_url_, entry);
+ manifest_response_writer_->response_id(),
+ manifest_response_writer_->amount_written());
+ if (!inprogress_cache_->AddOrModifyEntry(manifest_url_, entry))
+ service_->storage()->DoomResponse(manifest_url_, entry.response_id());
CompleteInprogressCache();
} else {
// Treat storage failure as if refetch of manifest failed.
@@ -1096,10 +1105,16 @@ void AppCacheUpdateJob::OnResponseInfoLoaded(
http_info->headers->EnumerateHeader(&iter, name, &value)) {
LoadFromNewestCacheFailed(url);
} else {
+ DCHECK(group_->newest_complete_cache());
+ AppCacheEntry* copy_me = group_->newest_complete_cache()->GetEntry(url);
+ DCHECK(copy_me);
+ DCHECK(copy_me->response_id() == response_id);
+
AppCache::EntryMap::iterator it = url_file_list_.find(url);
DCHECK(it != url_file_list_.end());
AppCacheEntry& entry = it->second;
entry.set_response_id(response_id);
+ entry.set_response_size(copy_me->response_size());
inprogress_cache_->AddOrModifyEntry(url, entry);
++url_fetches_completed_;
}