diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-10 22:09:58 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-10 22:09:58 +0000 |
commit | 2de5530222ed163c8c2f3ebae925b3673fb3ec76 (patch) | |
tree | 627b59a6fdb49bfc7511263abb3189223578f76e /webkit/appcache | |
parent | 3054f1ba755f9919a55789a6a204ee5169e02640 (diff) | |
download | chromium_src-2de5530222ed163c8c2f3ebae925b3673fb3ec76.zip chromium_src-2de5530222ed163c8c2f3ebae925b3673fb3ec76.tar.gz chromium_src-2de5530222ed163c8c2f3ebae925b3673fb3ec76.tar.bz2 |
base::Bind: Cleanup in test_shell.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8215002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104796 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_backend_impl.cc | 6 | ||||
-rw-r--r-- | webkit/appcache/appcache_backend_impl.h | 6 | ||||
-rw-r--r-- | webkit/appcache/appcache_host.cc | 75 | ||||
-rw-r--r-- | webkit/appcache/appcache_host.h | 27 | ||||
-rw-r--r-- | webkit/appcache/appcache_host_unittest.cc | 38 |
5 files changed, 72 insertions, 80 deletions
diff --git a/webkit/appcache/appcache_backend_impl.cc b/webkit/appcache/appcache_backend_impl.cc index 44b3c47..9b132f4 100644 --- a/webkit/appcache/appcache_backend_impl.cc +++ b/webkit/appcache/appcache_backend_impl.cc @@ -110,7 +110,7 @@ bool AppCacheBackendImpl::MarkAsForeignEntry( } bool AppCacheBackendImpl::GetStatusWithCallback( - int host_id, GetStatusCallback* callback, void* callback_param) { + int host_id, const GetStatusCallback& callback, void* callback_param) { AppCacheHost* host = GetHost(host_id); if (!host) return false; @@ -120,7 +120,7 @@ bool AppCacheBackendImpl::GetStatusWithCallback( } bool AppCacheBackendImpl::StartUpdateWithCallback( - int host_id, StartUpdateCallback* callback, void* callback_param) { + int host_id, const StartUpdateCallback& callback, void* callback_param) { AppCacheHost* host = GetHost(host_id); if (!host) return false; @@ -130,7 +130,7 @@ bool AppCacheBackendImpl::StartUpdateWithCallback( } bool AppCacheBackendImpl::SwapCacheWithCallback( - int host_id, SwapCacheCallback* callback, void* callback_param) { + int host_id, const SwapCacheCallback& callback, void* callback_param) { AppCacheHost* host = GetHost(host_id); if (!host) return false; diff --git a/webkit/appcache/appcache_backend_impl.h b/webkit/appcache/appcache_backend_impl.h index 67e7e99..0f81791 100644 --- a/webkit/appcache/appcache_backend_impl.h +++ b/webkit/appcache/appcache_backend_impl.h @@ -41,11 +41,11 @@ class APPCACHE_EXPORT AppCacheBackendImpl { bool SelectCacheForSharedWorker(int host_id, int64 appcache_id); bool MarkAsForeignEntry(int host_id, const GURL& document_url, int64 cache_document_was_loaded_from); - bool GetStatusWithCallback(int host_id, GetStatusCallback* callback, + bool GetStatusWithCallback(int host_id, const GetStatusCallback& callback, void* callback_param); - bool StartUpdateWithCallback(int host_id, StartUpdateCallback* callback, + bool StartUpdateWithCallback(int host_id, const StartUpdateCallback& callback, void* callback_param); - bool SwapCacheWithCallback(int host_id, SwapCacheCallback* callback, + bool SwapCacheWithCallback(int host_id, const SwapCacheCallback& callback, void* callback_param); // Returns a pointer to a registered host. The backend retains ownership. diff --git a/webkit/appcache/appcache_host.cc b/webkit/appcache/appcache_host.cc index ddc9bd2..dd9f9fb 100644 --- a/webkit/appcache/appcache_host.cc +++ b/webkit/appcache/appcache_host.cc @@ -41,8 +41,7 @@ AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, pending_main_resource_cache_id_(kNoCacheId), pending_selected_cache_id_(kNoCacheId), frontend_(frontend), service_(service), - pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), - pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), + pending_callback_param_(NULL), main_resource_was_fallback_(false), main_resource_blocked_(false), associated_cache_info_pending_(false) { } @@ -69,9 +68,9 @@ void AppCacheHost::RemoveObserver(Observer* observer) { void AppCacheHost::SelectCache(const GURL& document_url, const int64 cache_document_was_loaded_from, const GURL& manifest_url) { - DCHECK(!pending_start_update_callback_ && - !pending_swap_cache_callback_ && - !pending_get_status_callback_ && + DCHECK(pending_start_update_callback_.is_null() && + pending_swap_cache_callback_.is_null() && + pending_get_status_callback_.is_null() && !is_selection_pending()); origin_in_use_ = document_url.GetOrigin(); @@ -125,9 +124,9 @@ void AppCacheHost::SelectCache(const GURL& document_url, void AppCacheHost::SelectCacheForWorker(int parent_process_id, int parent_host_id) { - DCHECK(!pending_start_update_callback_ && - !pending_swap_cache_callback_ && - !pending_get_status_callback_ && + DCHECK(pending_start_update_callback_.is_null() && + pending_swap_cache_callback_.is_null() && + pending_get_status_callback_.is_null() && !is_selection_pending()); parent_process_id_ = parent_process_id; @@ -136,9 +135,9 @@ void AppCacheHost::SelectCacheForWorker(int parent_process_id, } void AppCacheHost::SelectCacheForSharedWorker(int64 appcache_id) { - DCHECK(!pending_start_update_callback_ && - !pending_swap_cache_callback_ && - !pending_get_status_callback_ && + DCHECK(pending_start_update_callback_.is_null() && + pending_swap_cache_callback_.is_null() && + pending_get_status_callback_.is_null() && !is_selection_pending()); if (appcache_id != kNoCacheId) { @@ -158,11 +157,11 @@ void AppCacheHost::MarkAsForeignEntry(const GURL& document_url, SelectCache(document_url, kNoCacheId, GURL()); } -void AppCacheHost::GetStatusWithCallback(GetStatusCallback* callback, +void AppCacheHost::GetStatusWithCallback(const GetStatusCallback& callback, void* callback_param) { - DCHECK(!pending_start_update_callback_ && - !pending_swap_cache_callback_ && - !pending_get_status_callback_); + DCHECK(pending_start_update_callback_.is_null() && + pending_swap_cache_callback_.is_null() && + pending_get_status_callback_.is_null()); pending_get_status_callback_ = callback; pending_callback_param_ = callback_param; @@ -173,20 +172,18 @@ void AppCacheHost::GetStatusWithCallback(GetStatusCallback* callback, } void AppCacheHost::DoPendingGetStatus() { - DCHECK(pending_get_status_callback_); + DCHECK_EQ(false, pending_get_status_callback_.is_null()); - pending_get_status_callback_->Run( - GetStatus(), pending_callback_param_); - - pending_get_status_callback_ = NULL; + pending_get_status_callback_.Run(GetStatus(), pending_callback_param_); + pending_get_status_callback_.Reset(); pending_callback_param_ = NULL; } -void AppCacheHost::StartUpdateWithCallback(StartUpdateCallback* callback, +void AppCacheHost::StartUpdateWithCallback(const StartUpdateCallback& callback, void* callback_param) { - DCHECK(!pending_start_update_callback_ && - !pending_swap_cache_callback_ && - !pending_get_status_callback_); + DCHECK(pending_start_update_callback_.is_null() && + pending_swap_cache_callback_.is_null() && + pending_get_status_callback_.is_null()); pending_start_update_callback_ = callback; pending_callback_param_ = callback_param; @@ -197,7 +194,7 @@ void AppCacheHost::StartUpdateWithCallback(StartUpdateCallback* callback, } void AppCacheHost::DoPendingStartUpdate() { - DCHECK(pending_start_update_callback_); + DCHECK_EQ(false, pending_start_update_callback_.is_null()); // 6.9.8 Application cache API bool success = false; @@ -209,18 +206,16 @@ void AppCacheHost::DoPendingStartUpdate() { } } - pending_start_update_callback_->Run( - success, pending_callback_param_); - - pending_start_update_callback_ = NULL; + pending_start_update_callback_.Run(success, pending_callback_param_); + pending_start_update_callback_.Reset(); pending_callback_param_ = NULL; } -void AppCacheHost::SwapCacheWithCallback(SwapCacheCallback* callback, +void AppCacheHost::SwapCacheWithCallback(const SwapCacheCallback& callback, void* callback_param) { - DCHECK(!pending_start_update_callback_ && - !pending_swap_cache_callback_ && - !pending_get_status_callback_); + DCHECK(pending_start_update_callback_.is_null() && + pending_swap_cache_callback_.is_null() && + pending_get_status_callback_.is_null()); pending_swap_cache_callback_ = callback; pending_callback_param_ = callback_param; @@ -231,7 +226,7 @@ void AppCacheHost::SwapCacheWithCallback(SwapCacheCallback* callback, } void AppCacheHost::DoPendingSwapCache() { - DCHECK(pending_swap_cache_callback_); + DCHECK_EQ(false, pending_swap_cache_callback_.is_null()); // 6.9.8 Application cache API bool success = false; @@ -247,10 +242,8 @@ void AppCacheHost::DoPendingSwapCache() { } } - pending_swap_cache_callback_->Run( - success, pending_callback_param_); - - pending_swap_cache_callback_ = NULL; + pending_swap_cache_callback_.Run(success, pending_callback_param_); + pending_swap_cache_callback_.Reset(); pending_callback_param_ = NULL; } @@ -403,11 +396,11 @@ void AppCacheHost::FinishCacheSelection( } // Respond to pending callbacks now that we have a selection. - if (pending_get_status_callback_) + if (!pending_get_status_callback_.is_null()) DoPendingGetStatus(); - else if (pending_start_update_callback_) + else if (!pending_start_update_callback_.is_null()) DoPendingStartUpdate(); - else if (pending_swap_cache_callback_) + else if (!pending_swap_cache_callback_.is_null()) DoPendingSwapCache(); FOR_EACH_OBSERVER(Observer, observers_, OnCacheSelectionComplete(this)); diff --git a/webkit/appcache/appcache_host.h b/webkit/appcache/appcache_host.h index f04b4ef..c94a1b3 100644 --- a/webkit/appcache/appcache_host.h +++ b/webkit/appcache/appcache_host.h @@ -27,9 +27,9 @@ class AppCache; class AppCacheFrontend; class AppCacheRequestHandler; -typedef Callback2<Status, void*>::Type GetStatusCallback; -typedef Callback2<bool, void*>::Type StartUpdateCallback; -typedef Callback2<bool, void*>::Type SwapCacheCallback; +typedef base::Callback<void(Status, void*)> GetStatusCallback; +typedef base::Callback<void(bool, void*)> StartUpdateCallback; +typedef base::Callback<void(bool, void*)> SwapCacheCallback; // Server-side representation of an application cache host. class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate, @@ -65,11 +65,11 @@ class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate, void SelectCacheForSharedWorker(int64 appcache_id); void MarkAsForeignEntry(const GURL& document_url, int64 cache_document_was_loaded_from); - void GetStatusWithCallback(GetStatusCallback* callback, + void GetStatusWithCallback(const GetStatusCallback& callback, void* callback_param); - void StartUpdateWithCallback(StartUpdateCallback* callback, + void StartUpdateWithCallback(const StartUpdateCallback& callback, void* callback_param); - void SwapCacheWithCallback(SwapCacheCallback* callback, + void SwapCacheWithCallback(const SwapCacheCallback& callback, void* callback_param); // Called prior to the main resource load. When the system contains multiple @@ -219,14 +219,13 @@ class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate, // Our central service object. AppCacheService* service_; - // Since these are synchronous scriptable api calls in the client, - // there can only be one type of callback pending. - // Also, we have to wait until we have a cache selection prior - // to responding to these calls, as cache selection involves - // async loading of a cache or a group from storage. - GetStatusCallback* pending_get_status_callback_; - StartUpdateCallback* pending_start_update_callback_; - SwapCacheCallback* pending_swap_cache_callback_; + // Since these are synchronous scriptable API calls in the client, there can + // only be one type of callback pending. Also, we have to wait until we have a + // cache selection prior to responding to these calls, as cache selection + // involves async loading of a cache or a group from storage. + GetStatusCallback pending_get_status_callback_; + StartUpdateCallback pending_start_update_callback_; + SwapCacheCallback pending_swap_cache_callback_; void* pending_callback_param_; // True if a fallback resource was delivered as the main resource. diff --git a/webkit/appcache/appcache_host_unittest.cc b/webkit/appcache/appcache_host_unittest.cc index 4621628..f439059 100644 --- a/webkit/appcache/appcache_host_unittest.cc +++ b/webkit/appcache/appcache_host_unittest.cc @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/memory/scoped_ptr.h" #include "net/url_request/url_request.h" #include "testing/gtest/include/gtest/gtest.h" @@ -19,12 +20,15 @@ namespace appcache { class AppCacheHostTest : public testing::Test { public: AppCacheHostTest() { - get_status_callback_.reset( - NewCallback(this, &AppCacheHostTest::GetStatusCallback)); - start_update_callback_.reset( - NewCallback(this, &AppCacheHostTest::StartUpdateCallback)); - swap_cache_callback_.reset( - NewCallback(this, &AppCacheHostTest::SwapCacheCallback)); + get_status_callback_ = + base::Bind(&AppCacheHostTest::GetStatusCallback, + base::Unretained(this)); + start_update_callback_ = + base::Bind(&AppCacheHostTest::StartUpdateCallback, + base::Unretained(this)); + swap_cache_callback_ = + base::Bind(&AppCacheHostTest::SwapCacheCallback, + base::Unretained(this)); } class MockFrontend : public AppCacheFrontend { @@ -135,9 +139,9 @@ class AppCacheHostTest : public testing::Test { MockFrontend mock_frontend_; // Mock callbacks we expect to receive from the 'host' - scoped_ptr<appcache::GetStatusCallback> get_status_callback_; - scoped_ptr<appcache::StartUpdateCallback> start_update_callback_; - scoped_ptr<appcache::SwapCacheCallback> swap_cache_callback_; + appcache::GetStatusCallback get_status_callback_; + appcache::StartUpdateCallback start_update_callback_; + appcache::SwapCacheCallback swap_cache_callback_; Status last_status_result_; bool last_swap_result_; @@ -157,20 +161,18 @@ TEST_F(AppCacheHostTest, Basic) { // See that the callbacks are delivered immediately // and respond as if there is no cache selected. last_status_result_ = OBSOLETE; - host.GetStatusWithCallback(get_status_callback_.get(), - reinterpret_cast<void*>(1)); + host.GetStatusWithCallback(get_status_callback_, reinterpret_cast<void*>(1)); EXPECT_EQ(UNCACHED, last_status_result_); EXPECT_EQ(reinterpret_cast<void*>(1), last_callback_param_); last_start_result_ = true; - host.StartUpdateWithCallback(start_update_callback_.get(), + host.StartUpdateWithCallback(start_update_callback_, reinterpret_cast<void*>(2)); EXPECT_FALSE(last_start_result_); EXPECT_EQ(reinterpret_cast<void*>(2), last_callback_param_); last_swap_result_ = true; - host.SwapCacheWithCallback(swap_cache_callback_.get(), - reinterpret_cast<void*>(3)); + host.SwapCacheWithCallback(swap_cache_callback_, reinterpret_cast<void*>(3)); EXPECT_FALSE(last_swap_result_); EXPECT_EQ(reinterpret_cast<void*>(3), last_callback_param_); } @@ -283,8 +285,7 @@ TEST_F(AppCacheHostTest, FailedCacheLoad) { // The callback should not occur until we finish cache selection. last_status_result_ = OBSOLETE; last_callback_param_ = reinterpret_cast<void*>(-1); - host.GetStatusWithCallback(get_status_callback_.get(), - reinterpret_cast<void*>(1)); + host.GetStatusWithCallback(get_status_callback_, reinterpret_cast<void*>(1)); EXPECT_EQ(OBSOLETE, last_status_result_); EXPECT_EQ(reinterpret_cast<void*>(-1), last_callback_param_); @@ -315,8 +316,7 @@ TEST_F(AppCacheHostTest, FailedGroupLoad) { // The callback should not occur until we finish cache selection. last_status_result_ = OBSOLETE; last_callback_param_ = reinterpret_cast<void*>(-1); - host.GetStatusWithCallback(get_status_callback_.get(), - reinterpret_cast<void*>(1)); + host.GetStatusWithCallback(get_status_callback_, reinterpret_cast<void*>(1)); EXPECT_EQ(OBSOLETE, last_status_result_); EXPECT_EQ(reinterpret_cast<void*>(-1), last_callback_param_); |