diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 20:46:07 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 20:46:07 +0000 |
commit | 888fecc63c1020cbc3564e3b9308bc721d842149 (patch) | |
tree | ceff15d0169061ec3dc4daddb56bd23d9f2aafa8 /net | |
parent | 1e6060485c2f0ef8e275caa8c3c3b5e8f67e33cc (diff) | |
download | chromium_src-888fecc63c1020cbc3564e3b9308bc721d842149.zip chromium_src-888fecc63c1020cbc3564e3b9308bc721d842149.tar.gz chromium_src-888fecc63c1020cbc3564e3b9308bc721d842149.tar.bz2 |
base::Bind: Convert view_http_cache_job_factory.cc.
Had to convert ViewCacheHelper at the same time.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8680015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/url_request/view_cache_helper.cc | 18 | ||||
-rw-r--r-- | net/url_request/view_cache_helper.h | 8 | ||||
-rw-r--r-- | net/url_request/view_cache_helper_unittest.cc | 21 |
3 files changed, 23 insertions, 24 deletions
diff --git a/net/url_request/view_cache_helper.cc b/net/url_request/view_cache_helper.cc index 677e038..e0f6456 100644 --- a/net/url_request/view_cache_helper.cc +++ b/net/url_request/view_cache_helper.cc @@ -45,7 +45,6 @@ ViewCacheHelper::ViewCacheHelper() buf_len_(0), index_(0), data_(NULL), - callback_(NULL), next_state_(STATE_NONE), ALLOW_THIS_IN_INITIALIZER_LIST( cache_callback_(this, &ViewCacheHelper::OnIOComplete)), @@ -65,14 +64,14 @@ ViewCacheHelper::~ViewCacheHelper() { int ViewCacheHelper::GetEntryInfoHTML(const std::string& key, const URLRequestContext* context, std::string* out, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { return GetInfoHTML(key, context, std::string(), out, callback); } int ViewCacheHelper::GetContentsHTML(const URLRequestContext* context, const std::string& url_prefix, std::string* out, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { return GetInfoHTML(std::string(), context, url_prefix, out, callback); } @@ -121,8 +120,8 @@ int ViewCacheHelper::GetInfoHTML(const std::string& key, const URLRequestContext* context, const std::string& url_prefix, std::string* out, - OldCompletionCallback* callback) { - DCHECK(!callback_); + const CompletionCallback& callback) { + DCHECK(callback_.is_null()); DCHECK(context); key_ = key; context_ = context; @@ -139,18 +138,17 @@ int ViewCacheHelper::GetInfoHTML(const std::string& key, void ViewCacheHelper::DoCallback(int rv) { DCHECK_NE(ERR_IO_PENDING, rv); - DCHECK(callback_); + DCHECK(!callback_.is_null()); - OldCompletionCallback* c = callback_; - callback_ = NULL; - c->Run(rv); + callback_.Run(rv); + callback_.Reset(); } void ViewCacheHelper::HandleResult(int rv) { DCHECK_NE(ERR_IO_PENDING, rv); DCHECK_NE(ERR_FAILED, rv); context_ = NULL; - if (callback_) + if (!callback_.is_null()) DoCallback(rv); } diff --git a/net/url_request/view_cache_helper.h b/net/url_request/view_cache_helper.h index 7471ca5..f6f7cc4 100644 --- a/net/url_request/view_cache_helper.h +++ b/net/url_request/view_cache_helper.h @@ -33,7 +33,7 @@ class NET_EXPORT ViewCacheHelper { int GetEntryInfoHTML(const std::string& key, const URLRequestContext* context, std::string* out, - OldCompletionCallback* callback); + const CompletionCallback& callback); // Formats the cache contents as HTML. Returns a net error code. // If this method returns ERR_IO_PENDING, |callback| will be notified when the @@ -43,7 +43,7 @@ class NET_EXPORT ViewCacheHelper { int GetContentsHTML(const URLRequestContext* context, const std::string& url_prefix, std::string* out, - OldCompletionCallback* callback); + const CompletionCallback& callback); // Lower-level helper to produce a textual representation of binary data. // The results are appended to |result| and can be used in HTML pages @@ -70,7 +70,7 @@ class NET_EXPORT ViewCacheHelper { const URLRequestContext* context, const std::string& url_prefix, std::string* out, - OldCompletionCallback* callback); + const CompletionCallback& callback); // This is a helper function used to trigger a completion callback. It may // only be called if callback_ is non-null. @@ -110,7 +110,7 @@ class NET_EXPORT ViewCacheHelper { std::string key_; std::string url_prefix_; std::string* data_; - OldCompletionCallback* callback_; + CompletionCallback callback_; State next_state_; diff --git a/net/url_request/view_cache_helper_unittest.cc b/net/url_request/view_cache_helper_unittest.cc index a0c3d1e..17bad61 100644 --- a/net/url_request/view_cache_helper_unittest.cc +++ b/net/url_request/view_cache_helper_unittest.cc @@ -103,9 +103,9 @@ TEST(ViewCacheHelper, EmptyCache) { scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); ViewCacheHelper helper; - TestOldCompletionCallback cb; + TestCompletionCallback cb; std::string prefix, data; - int rv = helper.GetContentsHTML(context, prefix, &data, &cb); + int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_FALSE(data.empty()); } @@ -117,8 +117,8 @@ TEST(ViewCacheHelper, ListContents) { FillCache(context); std::string prefix, data; - TestOldCompletionCallback cb; - int rv = helper.GetContentsHTML(context, prefix, &data, &cb); + TestCompletionCallback cb; + int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_EQ(0U, data.find("<html>")); @@ -139,8 +139,8 @@ TEST(ViewCacheHelper, DumpEntry) { FillCache(context); std::string data; - TestOldCompletionCallback cb; - int rv = helper.GetEntryInfoHTML("second", context, &data, &cb); + TestCompletionCallback cb; + int rv = helper.GetEntryInfoHTML("second", context, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_EQ(0U, data.find("<html>")); @@ -165,8 +165,8 @@ TEST(ViewCacheHelper, Prefix) { std::string key, data; std::string prefix("prefix:"); - TestOldCompletionCallback cb; - int rv = helper.GetContentsHTML(context, prefix, &data, &cb); + TestCompletionCallback cb; + int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_EQ(0U, data.find("<html>")); @@ -197,8 +197,9 @@ TEST(ViewCacheHelper, TruncatedFlag) { entry->Close(); std::string data; - rv = helper.GetEntryInfoHTML(key, context, &data, &cb); - EXPECT_EQ(OK, cb.GetResult(rv)); + TestCompletionCallback cb1; + rv = helper.GetEntryInfoHTML(key, context, &data, cb1.callback()); + EXPECT_EQ(OK, cb1.GetResult(rv)); EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); } |