Commit 75ade89a authored by nharper's avatar nharper Committed by Commit bot

Combine ChannelIDService::RequestHandle and ChannelIDServiceRequest classes

BUG=486265

Review URL: https://codereview.chromium.org/1149083013

Cr-Commit-Position: refs/heads/master@{#333770}
parent 89cda377
...@@ -48,7 +48,7 @@ void MessagePropertyProvider::GetChannelID(Profile* profile, ...@@ -48,7 +48,7 @@ void MessagePropertyProvider::GetChannelID(Profile* profile,
// MessagePropertyProvider::GetChannelID. // MessagePropertyProvider::GetChannelID.
struct MessagePropertyProvider::GetChannelIDOutput { struct MessagePropertyProvider::GetChannelIDOutput {
scoped_ptr<crypto::ECPrivateKey> channel_id_key; scoped_ptr<crypto::ECPrivateKey> channel_id_key;
net::ChannelIDService::RequestHandle request_handle; net::ChannelIDService::Request request;
}; };
// static // static
...@@ -67,9 +67,8 @@ void MessagePropertyProvider::GetChannelIDOnIOThread( ...@@ -67,9 +67,8 @@ void MessagePropertyProvider::GetChannelIDOnIOThread(
original_task_runner, original_task_runner,
base::Owned(output), base::Owned(output),
reply); reply);
int status = channel_id_service->GetChannelID(host, &output->channel_id_key, int status = channel_id_service->GetChannelID(
net_completion_callback, host, &output->channel_id_key, net_completion_callback, &output->request);
&output->request_handle);
if (status == net::ERR_IO_PENDING) if (status == net::ERR_IO_PENDING)
return; return;
GotChannelID(original_task_runner, output, reply, status); GotChannelID(original_task_runner, output, reply, status);
......
...@@ -974,13 +974,13 @@ class ExternallyConnectableMessagingWithTlsChannelIdTest : ...@@ -974,13 +974,13 @@ class ExternallyConnectableMessagingWithTlsChannelIdTest :
scoped_refptr<net::URLRequestContextGetter> request_context_getter( scoped_refptr<net::URLRequestContextGetter> request_context_getter(
profile()->GetRequestContext()); profile()->GetRequestContext());
scoped_ptr<crypto::ECPrivateKey> channel_id_key; scoped_ptr<crypto::ECPrivateKey> channel_id_key;
net::ChannelIDService::RequestHandle request_handle; net::ChannelIDService::Request request;
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE, content::BrowserThread::IO, FROM_HERE,
base::Bind(&ExternallyConnectableMessagingWithTlsChannelIdTest:: base::Bind(&ExternallyConnectableMessagingWithTlsChannelIdTest::
CreateDomainBoundCertOnIOThread, CreateDomainBoundCertOnIOThread,
base::Unretained(this), base::Unretained(&channel_id_key), base::Unretained(this), base::Unretained(&channel_id_key),
base::Unretained(&request_handle), request_context_getter)); base::Unretained(&request), request_context_getter));
tls_channel_id_created_.Wait(); tls_channel_id_created_.Wait();
// Create the expected value. // Create the expected value.
std::vector<uint8> spki_vector; std::vector<uint8> spki_vector;
...@@ -998,7 +998,7 @@ class ExternallyConnectableMessagingWithTlsChannelIdTest : ...@@ -998,7 +998,7 @@ class ExternallyConnectableMessagingWithTlsChannelIdTest :
private: private:
void CreateDomainBoundCertOnIOThread( void CreateDomainBoundCertOnIOThread(
scoped_ptr<crypto::ECPrivateKey>* channel_id_key, scoped_ptr<crypto::ECPrivateKey>* channel_id_key,
net::ChannelIDService::RequestHandle* request_handle, net::ChannelIDService::Request* request,
scoped_refptr<net::URLRequestContextGetter> request_context_getter) { scoped_refptr<net::URLRequestContextGetter> request_context_getter) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
net::ChannelIDService* channel_id_service = net::ChannelIDService* channel_id_service =
...@@ -1009,7 +1009,7 @@ class ExternallyConnectableMessagingWithTlsChannelIdTest : ...@@ -1009,7 +1009,7 @@ class ExternallyConnectableMessagingWithTlsChannelIdTest :
base::Bind(&ExternallyConnectableMessagingWithTlsChannelIdTest:: base::Bind(&ExternallyConnectableMessagingWithTlsChannelIdTest::
GotDomainBoundCert, GotDomainBoundCert,
base::Unretained(this)), base::Unretained(this)),
request_handle); request);
if (status == net::ERR_IO_PENDING) if (status == net::ERR_IO_PENDING)
return; return;
GotDomainBoundCert(status); GotDomainBoundCert(status);
......
...@@ -89,7 +89,7 @@ class ChannelIDSourceChromium::Job { ...@@ -89,7 +89,7 @@ class ChannelIDSourceChromium::Job {
ChannelIDService* const channel_id_service_; ChannelIDService* const channel_id_service_;
scoped_ptr<crypto::ECPrivateKey> channel_id_crypto_key_; scoped_ptr<crypto::ECPrivateKey> channel_id_crypto_key_;
ChannelIDService::RequestHandle channel_id_request_handle_; ChannelIDService::Request channel_id_request_;
// |hostname| specifies the hostname for which we need a channel ID. // |hostname| specifies the hostname for which we need a channel ID.
std::string hostname_; std::string hostname_;
...@@ -181,7 +181,7 @@ int ChannelIDSourceChromium::Job::DoGetChannelIDKey(int result) { ...@@ -181,7 +181,7 @@ int ChannelIDSourceChromium::Job::DoGetChannelIDKey(int result) {
hostname_, &channel_id_crypto_key_, hostname_, &channel_id_crypto_key_,
base::Bind(&ChannelIDSourceChromium::Job::OnIOComplete, base::Bind(&ChannelIDSourceChromium::Job::OnIOComplete,
base::Unretained(this)), base::Unretained(this)),
&channel_id_request_handle_); &channel_id_request_);
} }
int ChannelIDSourceChromium::Job::DoGetChannelIDKeyComplete(int result) { int ChannelIDSourceChromium::Job::DoGetChannelIDKeyComplete(int result) {
......
...@@ -699,7 +699,7 @@ class SSLClientSocketNSS::Core : public base::RefCountedThreadSafe<Core> { ...@@ -699,7 +699,7 @@ class SSLClientSocketNSS::Core : public base::RefCountedThreadSafe<Core> {
// The service for retrieving Channel ID keys. May be NULL. // The service for retrieving Channel ID keys. May be NULL.
ChannelIDService* channel_id_service_; ChannelIDService* channel_id_service_;
ChannelIDService::RequestHandle channel_id_request_handle_; ChannelIDService::Request channel_id_request_;
// The information about NSS task runner. // The information about NSS task runner.
int unhandled_buffer_size_; int unhandled_buffer_size_;
...@@ -954,7 +954,7 @@ void SSLClientSocketNSS::Core::Detach() { ...@@ -954,7 +954,7 @@ void SSLClientSocketNSS::Core::Detach() {
network_handshake_state_.Reset(); network_handshake_state_.Reset();
channel_id_request_handle_.Cancel(); channel_id_request_.Cancel();
} }
int SSLClientSocketNSS::Core::Read(IOBuffer* buf, int buf_len, int SSLClientSocketNSS::Core::Read(IOBuffer* buf, int buf_len,
...@@ -2213,7 +2213,7 @@ int SSLClientSocketNSS::Core::DoGetChannelID(const std::string& host) { ...@@ -2213,7 +2213,7 @@ int SSLClientSocketNSS::Core::DoGetChannelID(const std::string& host) {
int rv = channel_id_service_->GetOrCreateChannelID( int rv = channel_id_service_->GetOrCreateChannelID(
host, &channel_id_key_, host, &channel_id_key_,
base::Bind(&Core::OnGetChannelIDComplete, base::Unretained(this)), base::Bind(&Core::OnGetChannelIDComplete, base::Unretained(this)),
&channel_id_request_handle_); &channel_id_request_);
if (rv != ERR_IO_PENDING && !OnNSSTaskRunner()) { if (rv != ERR_IO_PENDING && !OnNSSTaskRunner()) {
nss_task_runner_->PostTask( nss_task_runner_->PostTask(
......
...@@ -513,7 +513,7 @@ void SSLClientSocketOpenSSL::Disconnect() { ...@@ -513,7 +513,7 @@ void SSLClientSocketOpenSSL::Disconnect() {
channel_id_sent_ = false; channel_id_sent_ = false;
handshake_completed_ = false; handshake_completed_ = false;
certificate_verified_ = false; certificate_verified_ = false;
channel_id_request_handle_.Cancel(); channel_id_request_.Cancel();
ssl_failure_state_ = SSL_FAILURE_NONE; ssl_failure_state_ = SSL_FAILURE_NONE;
} }
...@@ -1031,7 +1031,7 @@ int SSLClientSocketOpenSSL::DoChannelIDLookup() { ...@@ -1031,7 +1031,7 @@ int SSLClientSocketOpenSSL::DoChannelIDLookup() {
host_and_port_.host(), &channel_id_key_, host_and_port_.host(), &channel_id_key_,
base::Bind(&SSLClientSocketOpenSSL::OnHandshakeIOComplete, base::Bind(&SSLClientSocketOpenSSL::OnHandshakeIOComplete,
base::Unretained(this)), base::Unretained(this)),
&channel_id_request_handle_); &channel_id_request_);
} }
int SSLClientSocketOpenSSL::DoChannelIDLookupComplete(int result) { int SSLClientSocketOpenSSL::DoChannelIDLookupComplete(int result) {
......
...@@ -303,7 +303,7 @@ class SSLClientSocketOpenSSL : public SSLClientSocket { ...@@ -303,7 +303,7 @@ class SSLClientSocketOpenSSL : public SSLClientSocket {
// True if the initial handshake's certificate has been verified. // True if the initial handshake's certificate has been verified.
bool certificate_verified_; bool certificate_verified_;
// The request handle for |channel_id_service_|. // The request handle for |channel_id_service_|.
ChannelIDService::RequestHandle channel_id_request_handle_; ChannelIDService::Request channel_id_request_;
SSLFailureState ssl_failure_state_; SSLFailureState ssl_failure_state_;
TransportSecurityState* transport_security_state_; TransportSecurityState* transport_security_state_;
......
This diff is collapsed.
...@@ -29,7 +29,6 @@ class ECPrivateKey; ...@@ -29,7 +29,6 @@ class ECPrivateKey;
namespace net { namespace net {
class ChannelIDServiceJob; class ChannelIDServiceJob;
class ChannelIDServiceRequest;
class ChannelIDServiceWorker; class ChannelIDServiceWorker;
// A class for creating and fetching Channel IDs. // A class for creating and fetching Channel IDs.
...@@ -39,29 +38,34 @@ class ChannelIDServiceWorker; ...@@ -39,29 +38,34 @@ class ChannelIDServiceWorker;
class NET_EXPORT ChannelIDService class NET_EXPORT ChannelIDService
: NON_EXPORTED_BASE(public base::NonThreadSafe) { : NON_EXPORTED_BASE(public base::NonThreadSafe) {
public: public:
class NET_EXPORT RequestHandle { class NET_EXPORT Request {
public: public:
RequestHandle(); Request();
~RequestHandle(); ~Request();
// Cancel the request. Does nothing if the request finished or was already // Cancel the request. Does nothing if the request finished or was already
// cancelled. // cancelled.
void Cancel(); void Cancel();
bool is_active() const { return request_ != NULL; } bool is_active() const { return !callback_.is_null(); }
private: private:
friend class ChannelIDService; friend class ChannelIDService;
friend class ChannelIDServiceJob;
void RequestStarted(ChannelIDService* service, void RequestStarted(ChannelIDService* service,
ChannelIDServiceRequest* request, base::TimeTicks request_start,
const CompletionCallback& callback); const CompletionCallback& callback,
scoped_ptr<crypto::ECPrivateKey>* key,
ChannelIDServiceJob* job);
void OnRequestComplete(int result); void Post(int error, scoped_ptr<crypto::ECPrivateKey> key);
ChannelIDService* service_; ChannelIDService* service_;
ChannelIDServiceRequest* request_; base::TimeTicks request_start_;
CompletionCallback callback_; CompletionCallback callback_;
scoped_ptr<crypto::ECPrivateKey>* key_;
ChannelIDServiceJob* job_;
}; };
// Password used on EncryptedPrivateKeyInfo data stored in EC private_key // Password used on EncryptedPrivateKeyInfo data stored in EC private_key
...@@ -94,13 +98,11 @@ class NET_EXPORT ChannelIDService ...@@ -94,13 +98,11 @@ class NET_EXPORT ChannelIDService
// could not be completed immediately, in which case the result code will // could not be completed immediately, in which case the result code will
// be passed to the callback when available. // be passed to the callback when available.
// //
// |*out_req| will be initialized with a handle to the async request. This // |*out_req| will be initialized with a handle to the async request.
// RequestHandle object must be cancelled or destroyed before the
// ChannelIDService is destroyed.
int GetOrCreateChannelID(const std::string& host, int GetOrCreateChannelID(const std::string& host,
scoped_ptr<crypto::ECPrivateKey>* key, scoped_ptr<crypto::ECPrivateKey>* key,
const CompletionCallback& callback, const CompletionCallback& callback,
RequestHandle* out_req); Request* out_req);
// Fetches the channel ID for the specified host if one exists. // Fetches the channel ID for the specified host if one exists.
// Returns OK if successful, ERR_FILE_NOT_FOUND if none exists, or an error // Returns OK if successful, ERR_FILE_NOT_FOUND if none exists, or an error
...@@ -116,13 +118,11 @@ class NET_EXPORT ChannelIDService ...@@ -116,13 +118,11 @@ class NET_EXPORT ChannelIDService
// request arrives for the same domain, the GetChannelID request will // request arrives for the same domain, the GetChannelID request will
// not complete until a new channel ID is created. // not complete until a new channel ID is created.
// //
// |*out_req| will be initialized with a handle to the async request. This // |*out_req| will be initialized with a handle to the async request.
// RequestHandle object must be cancelled or destroyed before the
// ChannelIDService is destroyed.
int GetChannelID(const std::string& host, int GetChannelID(const std::string& host,
scoped_ptr<crypto::ECPrivateKey>* key, scoped_ptr<crypto::ECPrivateKey>* key,
const CompletionCallback& callback, const CompletionCallback& callback,
RequestHandle* out_req); Request* out_req);
// Returns the backing ChannelIDStore. // Returns the backing ChannelIDStore.
ChannelIDStore* GetChannelIDStore(); ChannelIDStore* GetChannelIDStore();
...@@ -135,11 +135,6 @@ class NET_EXPORT ChannelIDService ...@@ -135,11 +135,6 @@ class NET_EXPORT ChannelIDService
uint64 workers_created() const { return workers_created_; } uint64 workers_created() const { return workers_created_; }
private: private:
// Cancels the specified request. |req| is the handle stored by
// GetChannelID(). After a request is canceled, its completion
// callback will not be called.
void CancelRequest(ChannelIDServiceRequest* req);
void GotChannelID(int err, void GotChannelID(int err,
const std::string& server_identifier, const std::string& server_identifier,
scoped_ptr<crypto::ECPrivateKey> key); scoped_ptr<crypto::ECPrivateKey> key);
...@@ -159,7 +154,7 @@ class NET_EXPORT ChannelIDService ...@@ -159,7 +154,7 @@ class NET_EXPORT ChannelIDService
scoped_ptr<crypto::ECPrivateKey>* key, scoped_ptr<crypto::ECPrivateKey>* key,
bool create_if_missing, bool create_if_missing,
const CompletionCallback& callback, const CompletionCallback& callback,
RequestHandle* out_req); Request* out_req);
// Looks for the channel ID for |domain| in this service's store. // Looks for the channel ID for |domain| in this service's store.
// Returns OK if it can be found synchronously, ERR_IO_PENDING if the // Returns OK if it can be found synchronously, ERR_IO_PENDING if the
...@@ -170,7 +165,7 @@ class NET_EXPORT ChannelIDService ...@@ -170,7 +165,7 @@ class NET_EXPORT ChannelIDService
scoped_ptr<crypto::ECPrivateKey>* key, scoped_ptr<crypto::ECPrivateKey>* key,
bool create_if_missing, bool create_if_missing,
const CompletionCallback& callback, const CompletionCallback& callback,
RequestHandle* out_req); Request* out_req);
scoped_ptr<ChannelIDStore> channel_id_store_; scoped_ptr<ChannelIDStore> channel_id_store_;
scoped_refptr<base::TaskRunner> task_runner_; scoped_refptr<base::TaskRunner> task_runner_;
......
This diff is collapsed.
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