Skip to content

Commit

Permalink
Add some unimplemented methods from my last CL.
Browse files Browse the repository at this point in the history
TEST=yes, appcache_storage_unittest.cc
BUG=none

Review URL: http://codereview.chromium.org/266042

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28772 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
michaeln@google.com committed Oct 13, 2009
1 parent fd9c35f commit d144b05
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions webkit/appcache/appcache_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/ref_counted.h"
#include "net/base/completion_callback.h"
#include "net/http/http_response_info.h"
#include "webkit/appcache/appcache_interfaces.h"
#include "webkit/appcache/appcache_service.h"
#include "webkit/appcache/appcache_storage.h"

Expand All @@ -19,14 +20,13 @@ namespace disk_cache {
class Backend;
};


namespace appcache {

// Response info for a particular response id. Instances are tracked in
// the working set.
class AppCacheResponseInfo
: public base::RefCounted<AppCacheResponseInfo> {

public:
// AppCacheResponseInfo takes ownership of the http_info.
AppCacheResponseInfo(AppCacheService* service, int64 response_id,
net::HttpResponseInfo* http_info)
Expand Down
30 changes: 30 additions & 0 deletions webkit/appcache/appcache_storage_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "webkit/appcache/appcache.h"
#include "webkit/appcache/appcache_group.h"
#include "webkit/appcache/appcache_storage.h"
#include "webkit/appcache/appcache_response.h"
#include "webkit/appcache/mock_appcache_service.h"

namespace appcache {
Expand All @@ -16,8 +17,14 @@ class AppCacheStorageTest : public testing::Test {
TEST(AppCacheStorageTest, AddRemoveCache) {
MockAppCacheService service;
scoped_refptr<AppCache> cache = new AppCache(&service, 111);

EXPECT_EQ(cache.get(),
service.storage()->working_set()->GetCache(111));

service.storage()->working_set()->RemoveCache(cache);

EXPECT_TRUE(!service.storage()->working_set()->GetCache(111));

// Removing non-existing cache from service should not fail.
MockAppCacheService dummy;
dummy.storage()->working_set()->RemoveCache(cache);
Expand All @@ -27,11 +34,34 @@ TEST(AppCacheStorageTest, AddRemoveGroup) {
MockAppCacheService service;
scoped_refptr<AppCacheGroup> group =
new AppCacheGroup(&service, GURL::EmptyGURL());

EXPECT_EQ(group.get(),
service.storage()->working_set()->GetGroup(GURL::EmptyGURL()));

service.storage()->working_set()->RemoveGroup(group);

EXPECT_TRUE(!service.storage()->working_set()->GetGroup(GURL::EmptyGURL()));

// Removing non-existing group from service should not fail.
MockAppCacheService dummy;
dummy.storage()->working_set()->RemoveGroup(group);
}

TEST(AppCacheStorageTest, AddRemoveResponseInfo) {
MockAppCacheService service;
scoped_refptr<AppCacheResponseInfo> info =
new AppCacheResponseInfo(&service, 111, new net::HttpResponseInfo);

EXPECT_EQ(info.get(),
service.storage()->working_set()->GetResponseInfo(111));

service.storage()->working_set()->RemoveResponseInfo(info);

EXPECT_TRUE(!service.storage()->working_set()->GetResponseInfo(111));

// Removing non-existing info from service should not fail.
MockAppCacheService dummy;
dummy.storage()->working_set()->RemoveResponseInfo(info);
}

} // namespace appcache
11 changes: 11 additions & 0 deletions webkit/appcache/appcache_working_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/logging.h"
#include "webkit/appcache/appcache.h"
#include "webkit/appcache/appcache_group.h"
#include "webkit/appcache/appcache_response.h"

namespace appcache {

Expand Down Expand Up @@ -35,4 +36,14 @@ void AppCacheWorkingSet::RemoveGroup(AppCacheGroup* group) {
groups_.erase(group->manifest_url());
}

void AppCacheWorkingSet::AddResponseInfo(AppCacheResponseInfo* info) {
int64 response_id = info->response_id();
DCHECK(response_infos_.find(response_id) == response_infos_.end());
response_infos_.insert(ResponseInfoMap::value_type(response_id, info));
}

void AppCacheWorkingSet::RemoveResponseInfo(AppCacheResponseInfo* info) {
response_infos_.erase(info->response_id());
}

} // namespace

0 comments on commit d144b05

Please sign in to comment.