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

Unified Diff: net/base/keygen_handler_unittest.cc

Issue 8734017: base::Bind: More random cleanups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac build fix 2. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/mach_broker_mac.cc ('k') | net/curvecp/client_packetizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/keygen_handler_unittest.cc
diff --git a/net/base/keygen_handler_unittest.cc b/net/base/keygen_handler_unittest.cc
index e10a160f8ca6f0ad712cd80ed52a1c73514653ab..b553411f4578d74864588817a66cf20da8b2c059 100644
--- a/net/base/keygen_handler_unittest.cc
+++ b/net/base/keygen_handler_unittest.cc
@@ -6,14 +6,15 @@
#include <string>
-#include "build/build_config.h"
#include "base/base64.h"
+#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/task.h"
#include "base/threading/worker_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/synchronization/waitable_event.h"
+#include "build/build_config.h"
#include "crypto/nss_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -81,41 +82,27 @@ TEST_F(KeygenHandlerTest, SmokeTest) {
AssertValidSignedPublicKeyAndChallenge(result, "some challenge");
}
-class ConcurrencyTestTask : public Task {
- public:
- ConcurrencyTestTask(base::WaitableEvent* event,
- const std::string& challenge, std::string* result)
- : event_(event),
- challenge_(challenge),
- result_(result) {
- }
-
- virtual void Run() {
- // We allow Singleton use on the worker thread here since we use a
- // WaitableEvent to synchronize, so it's safe.
- base::ThreadRestrictions::ScopedAllowSingleton scoped_allow_singleton;
- KeygenHandler handler(768, "some challenge",
- GURL("http://www.example.com"));
- handler.set_stores_key(false); // Don't leave the key-pair behind.
- *result_ = handler.GenKeyAndSignChallenge();
- event_->Signal();
+void ConcurrencyTestCallback(base::WaitableEvent* event,
+ const std::string& challenge,
+ std::string* result) {
+ // We allow Singleton use on the worker thread here since we use a
+ // WaitableEvent to synchronize, so it's safe.
+ base::ThreadRestrictions::ScopedAllowSingleton scoped_allow_singleton;
+ KeygenHandler handler(768, challenge, GURL("http://www.example.com"));
+ handler.set_stores_key(false); // Don't leave the key-pair behind.
+ *result = handler.GenKeyAndSignChallenge();
+ event->Signal();
#if defined(USE_NSS)
- // Detach the thread from NSPR.
- // Calling NSS functions attaches the thread to NSPR, which stores
- // the NSPR thread ID in thread-specific data.
- // The threads in our thread pool terminate after we have called
- // PR_Cleanup. Unless we detach them from NSPR, net_unittests gets
- // segfaults on shutdown when the threads' thread-specific data
- // destructors run.
- PR_DetachThread();
+ // Detach the thread from NSPR.
+ // Calling NSS functions attaches the thread to NSPR, which stores
+ // the NSPR thread ID in thread-specific data.
+ // The threads in our thread pool terminate after we have called
+ // PR_Cleanup. Unless we detach them from NSPR, net_unittests gets
+ // segfaults on shutdown when the threads' thread-specific data
+ // destructors run.
+ PR_DetachThread();
#endif
- }
-
- private:
- base::WaitableEvent* event_;
- std::string challenge_;
- std::string* result_;
-};
+}
// We asynchronously generate the keys so as not to hang up the IO thread. This
// test tries to catch concurrency problems in the keygen implementation.
@@ -127,7 +114,8 @@ TEST_F(KeygenHandlerTest, ConcurrencyTest) {
events[i] = new base::WaitableEvent(false, false);
base::WorkerPool::PostTask(
FROM_HERE,
- new ConcurrencyTestTask(events[i], "some challenge", &results[i]),
+ base::Bind(ConcurrencyTestCallback, events[i], "some challenge",
+ &results[i]),
true);
}
« no previous file with comments | « content/browser/mach_broker_mac.cc ('k') | net/curvecp/client_packetizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698