Commit 14589e9c authored by fdoray's avatar fdoray Committed by Commit bot

Use TaskScheduler instead of WorkerPool in client_cert_store_chromeos.cc.

This CL replaces base::WorkerPool::PostTask() with
base::PostTaskWithTraits(). The following traits are used:

Priority: Inherited (default)
  The priority is inherited from the calling context (i.e. TaskTraits
  are initialized with the priority of the current task).

Shutdown behavior: CONTINUE_ON_SHUTDOWN
  Tasks posted with this mode which have not started executing before
  shutdown is initiated will never run. Tasks with this mode running at
  shutdown will be ignored (the worker will not be joined).

With File IO:
  The task waits on synchronous file IO operations.

With Wait:
  The task waits on things other than synchronous file IO
  operations (e.g. WaitableEvent, ConditionVariable, join a thread,
  join a process, blocking system call that doesn't involve
  interactions with the file system).

BUG=659191

Review-Url: https://codereview.chromium.org/2533473002
Cr-Commit-Position: refs/heads/master@{#436087}
parent 96de1925
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/location.h" #include "base/location.h"
#include "base/threading/worker_pool.h" #include "base/task_scheduler/post_task.h"
#include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h"
#include "crypto/nss_crypto_module_delegate.h" #include "crypto/nss_crypto_module_delegate.h"
#include "net/ssl/ssl_cert_request_info.h" #include "net/ssl/ssl_cert_request_info.h"
...@@ -81,18 +81,14 @@ void ClientCertStoreChromeOS::GotAdditionalCerts( ...@@ -81,18 +81,14 @@ void ClientCertStoreChromeOS::GotAdditionalCerts(
password_delegate.reset( password_delegate.reset(
password_delegate_factory_.Run(request->host_and_port)); password_delegate_factory_.Run(request->host_and_port));
} }
if (base::WorkerPool::PostTaskAndReply( base::PostTaskWithTraitsAndReply(
FROM_HERE, FROM_HERE,
base::Bind(&ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread, base::TaskTraits().WithWait().WithFileIO().WithShutdownBehavior(
base::Unretained(this), base::Passed(&password_delegate), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
request, additional_certs, selected_certs), base::Bind(&ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread,
callback, true)) { base::Unretained(this), base::Passed(&password_delegate),
return; request, additional_certs, selected_certs),
} callback);
// If the task could not be posted, behave as if there were no certificates
// which requires to clear |selected_certs|.
selected_certs->clear();
callback.Run();
} }
void ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread( void ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread(
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "chrome/browser/chromeos/net/client_cert_store_chromeos.h" #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h"
#include <memory>
#include <string> #include <string>
#include "base/callback.h" #include "base/callback.h"
...@@ -15,6 +14,7 @@ ...@@ -15,6 +14,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_scheduler.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h"
#include "crypto/scoped_test_nss_db.h" #include "crypto/scoped_test_nss_db.h"
...@@ -78,7 +78,7 @@ class TestCertFilter : public ClientCertStoreChromeOS::CertFilter { ...@@ -78,7 +78,7 @@ class TestCertFilter : public ClientCertStoreChromeOS::CertFilter {
class ClientCertStoreChromeOSTest : public ::testing::Test { class ClientCertStoreChromeOSTest : public ::testing::Test {
public: public:
ClientCertStoreChromeOSTest() : message_loop_(new base::MessageLoopForIO()) {} ClientCertStoreChromeOSTest() {}
scoped_refptr<net::X509Certificate> ImportCertToSlot( scoped_refptr<net::X509Certificate> ImportCertToSlot(
const std::string& cert_filename, const std::string& cert_filename,
...@@ -89,7 +89,8 @@ class ClientCertStoreChromeOSTest : public ::testing::Test { ...@@ -89,7 +89,8 @@ class ClientCertStoreChromeOSTest : public ::testing::Test {
} }
private: private:
std::unique_ptr<base::MessageLoop> message_loop_; base::test::ScopedTaskScheduler scoped_task_scheduler_;
base::MessageLoopForIO message_loop_;
}; };
// Ensure that cert requests, that are started before the filter is initialized, // Ensure that cert requests, that are started before the filter is initialized,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment