DiskBasedCertCache method name change + readability fixes.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287464 0039d316-1c4b-4281-b951-d872f2087c98
parent 4a7ce7d3
...@@ -39,7 +39,6 @@ enum CacheResult { ...@@ -39,7 +39,6 @@ enum CacheResult {
DISK_CACHE_HIT, DISK_CACHE_HIT,
DISK_CACHE_ENTRY_CORRUPT, DISK_CACHE_ENTRY_CORRUPT,
DISK_CACHE_ERROR, DISK_CACHE_ERROR,
CACHE_MISS,
CACHE_RESULT_MAX CACHE_RESULT_MAX
}; };
...@@ -50,9 +49,9 @@ void RecordCacheResult(CacheResult result) { ...@@ -50,9 +49,9 @@ void RecordCacheResult(CacheResult result) {
} // namespace } // namespace
// WriteWorkers represent pending Set jobs in the DiskBasedCertCache. Each // WriteWorkers represent pending SetCertificate jobs in the DiskBasedCertCache.
// certificate requested to be cached is assigned a Writeworker on a one-to-one // Each certificate requested to be stored is assigned a WriteWorker.
// basis. The same certificate should not have multiple WriteWorkers at the same // The same certificate should not have multiple WriteWorkers at the same
// time; instead, add a user callback to the existing WriteWorker. // time; instead, add a user callback to the existing WriteWorker.
class DiskBasedCertCache::WriteWorker { class DiskBasedCertCache::WriteWorker {
public: public:
...@@ -112,7 +111,7 @@ class DiskBasedCertCache::WriteWorker { ...@@ -112,7 +111,7 @@ class DiskBasedCertCache::WriteWorker {
bool canceled_; bool canceled_;
disk_cache::Entry* entry_; disk_cache::Entry* entry_;
State state_; State next_state_;
scoped_refptr<IOBuffer> buffer_; scoped_refptr<IOBuffer> buffer_;
int io_buf_len_; int io_buf_len_;
...@@ -131,7 +130,7 @@ DiskBasedCertCache::WriteWorker::WriteWorker( ...@@ -131,7 +130,7 @@ DiskBasedCertCache::WriteWorker::WriteWorker(
key_(key), key_(key),
canceled_(false), canceled_(false),
entry_(NULL), entry_(NULL),
state_(STATE_NONE), next_state_(STATE_NONE),
io_buf_len_(0), io_buf_len_(0),
cleanup_callback_(cleanup_callback), cleanup_callback_(cleanup_callback),
io_callback_( io_callback_(
...@@ -146,8 +145,8 @@ DiskBasedCertCache::WriteWorker::~WriteWorker() { ...@@ -146,8 +145,8 @@ DiskBasedCertCache::WriteWorker::~WriteWorker() {
} }
void DiskBasedCertCache::WriteWorker::Start() { void DiskBasedCertCache::WriteWorker::Start() {
DCHECK_EQ(STATE_NONE, state_); DCHECK_EQ(STATE_NONE, next_state_);
state_ = STATE_CREATE; next_state_ = STATE_CREATE;
int rv = DoLoop(OK); int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING) if (rv == ERR_IO_PENDING)
...@@ -181,9 +180,9 @@ void DiskBasedCertCache::WriteWorker::OnIOComplete(int rv) { ...@@ -181,9 +180,9 @@ void DiskBasedCertCache::WriteWorker::OnIOComplete(int rv) {
int DiskBasedCertCache::WriteWorker::DoLoop(int rv) { int DiskBasedCertCache::WriteWorker::DoLoop(int rv) {
do { do {
State next_state = state_; State state = next_state_;
state_ = STATE_NONE; next_state_ = STATE_NONE;
switch (next_state) { switch (state) {
case STATE_CREATE: case STATE_CREATE:
rv = DoCreate(); rv = DoCreate();
break; break;
...@@ -206,13 +205,13 @@ int DiskBasedCertCache::WriteWorker::DoLoop(int rv) { ...@@ -206,13 +205,13 @@ int DiskBasedCertCache::WriteWorker::DoLoop(int rv) {
NOTREACHED(); NOTREACHED();
break; break;
} }
} while (rv != ERR_IO_PENDING && state_ != STATE_NONE); } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
return rv; return rv;
} }
int DiskBasedCertCache::WriteWorker::DoCreate() { int DiskBasedCertCache::WriteWorker::DoCreate() {
state_ = STATE_CREATE_COMPLETE; next_state_ = STATE_CREATE_COMPLETE;
return backend_->CreateEntry(key_, &entry_, io_callback_); return backend_->CreateEntry(key_, &entry_, io_callback_);
} }
...@@ -222,16 +221,16 @@ int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) { ...@@ -222,16 +221,16 @@ int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) {
// If this occurs, it is necessary to instead open the previously // If this occurs, it is necessary to instead open the previously
// existing entry. // existing entry.
if (rv < 0) { if (rv < 0) {
state_ = STATE_OPEN; next_state_ = STATE_OPEN;
return OK; return OK;
} }
state_ = STATE_WRITE; next_state_ = STATE_WRITE;
return OK; return OK;
} }
int DiskBasedCertCache::WriteWorker::DoOpen() { int DiskBasedCertCache::WriteWorker::DoOpen() {
state_ = STATE_OPEN_COMPLETE; next_state_ = STATE_OPEN_COMPLETE;
return backend_->OpenEntry(key_, &entry_, io_callback_); return backend_->OpenEntry(key_, &entry_, io_callback_);
} }
...@@ -239,7 +238,7 @@ int DiskBasedCertCache::WriteWorker::DoOpenComplete(int rv) { ...@@ -239,7 +238,7 @@ int DiskBasedCertCache::WriteWorker::DoOpenComplete(int rv) {
if (rv < 0) if (rv < 0)
return rv; return rv;
state_ = STATE_WRITE; next_state_ = STATE_WRITE;
return OK; return OK;
} }
...@@ -254,7 +253,7 @@ int DiskBasedCertCache::WriteWorker::DoWrite() { ...@@ -254,7 +253,7 @@ int DiskBasedCertCache::WriteWorker::DoWrite() {
io_buf_len_ = write_data.size(); io_buf_len_ = write_data.size();
memcpy(buffer_->data(), write_data.data(), io_buf_len_); memcpy(buffer_->data(), write_data.data(), io_buf_len_);
state_ = STATE_WRITE_COMPLETE; next_state_ = STATE_WRITE_COMPLETE;
return entry_->WriteData(0 /* index */, return entry_->WriteData(0 /* index */,
0 /* offset */, 0 /* offset */,
...@@ -291,11 +290,11 @@ void DiskBasedCertCache::WriteWorker::RunCallbacks(int rv) { ...@@ -291,11 +290,11 @@ void DiskBasedCertCache::WriteWorker::RunCallbacks(int rv) {
user_callbacks_.clear(); user_callbacks_.clear();
} }
// ReadWorkers represent pending Get jobs in the DiskBasedCertCache. Each // ReadWorkers represent pending GetCertificate jobs in the DiskBasedCertCache.
// certificate requested to be retrieved from the cache is assigned a ReadWorker // Each certificate requested to be retrieved from the cache is assigned a
// on a one-to-one basis. The same |key| should not have multiple ReadWorkers // ReadWorker. The same |key| should not have multiple ReadWorkers at the
// at the same time; instead, call AddCallback to add a user_callback_ to // same time; instead, call AddCallback to add a user callback to the
// the the existing ReadWorker. // existing ReadWorker.
class DiskBasedCertCache::ReadWorker { class DiskBasedCertCache::ReadWorker {
public: public:
// |backend| is the backend to read |certificate| from, using // |backend| is the backend to read |certificate| from, using
...@@ -348,7 +347,7 @@ class DiskBasedCertCache::ReadWorker { ...@@ -348,7 +347,7 @@ class DiskBasedCertCache::ReadWorker {
disk_cache::Entry* entry_; disk_cache::Entry* entry_;
State state_; State next_state_;
scoped_refptr<IOBuffer> buffer_; scoped_refptr<IOBuffer> buffer_;
int io_buf_len_; int io_buf_len_;
...@@ -365,7 +364,7 @@ DiskBasedCertCache::ReadWorker::ReadWorker(disk_cache::Backend* backend, ...@@ -365,7 +364,7 @@ DiskBasedCertCache::ReadWorker::ReadWorker(disk_cache::Backend* backend,
key_(key), key_(key),
canceled_(false), canceled_(false),
entry_(NULL), entry_(NULL),
state_(STATE_NONE), next_state_(STATE_NONE),
io_buf_len_(0), io_buf_len_(0),
cleanup_callback_(cleanup_callback), cleanup_callback_(cleanup_callback),
io_callback_( io_callback_(
...@@ -380,8 +379,8 @@ DiskBasedCertCache::ReadWorker::~ReadWorker() { ...@@ -380,8 +379,8 @@ DiskBasedCertCache::ReadWorker::~ReadWorker() {
} }
void DiskBasedCertCache::ReadWorker::Start() { void DiskBasedCertCache::ReadWorker::Start() {
DCHECK_EQ(STATE_NONE, state_); DCHECK_EQ(STATE_NONE, next_state_);
state_ = STATE_OPEN; next_state_ = STATE_OPEN;
int rv = DoLoop(OK); int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING) if (rv == ERR_IO_PENDING)
...@@ -415,9 +414,9 @@ void DiskBasedCertCache::ReadWorker::OnIOComplete(int rv) { ...@@ -415,9 +414,9 @@ void DiskBasedCertCache::ReadWorker::OnIOComplete(int rv) {
int DiskBasedCertCache::ReadWorker::DoLoop(int rv) { int DiskBasedCertCache::ReadWorker::DoLoop(int rv) {
do { do {
State next_state = state_; State state = next_state_;
state_ = STATE_NONE; next_state_ = STATE_NONE;
switch (next_state) { switch (state) {
case STATE_OPEN: case STATE_OPEN:
rv = DoOpen(); rv = DoOpen();
break; break;
...@@ -434,30 +433,28 @@ int DiskBasedCertCache::ReadWorker::DoLoop(int rv) { ...@@ -434,30 +433,28 @@ int DiskBasedCertCache::ReadWorker::DoLoop(int rv) {
NOTREACHED(); NOTREACHED();
break; break;
} }
} while (rv != ERR_IO_PENDING && state_ != STATE_NONE); } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
return rv; return rv;
} }
int DiskBasedCertCache::ReadWorker::DoOpen() { int DiskBasedCertCache::ReadWorker::DoOpen() {
state_ = STATE_OPEN_COMPLETE; next_state_ = STATE_OPEN_COMPLETE;
return backend_->OpenEntry(key_, &entry_, io_callback_); return backend_->OpenEntry(key_, &entry_, io_callback_);
} }
int DiskBasedCertCache::ReadWorker::DoOpenComplete(int rv) { int DiskBasedCertCache::ReadWorker::DoOpenComplete(int rv) {
if (rv < 0) { if (rv < 0) {
// Errors other than ERR_CACHE_MISS are not recorded as either a hit RecordCacheResult(DISK_CACHE_ERROR);
// or a miss.
RecordCacheResult(rv == ERR_CACHE_MISS ? CACHE_MISS : DISK_CACHE_ERROR);
return rv; return rv;
} }
state_ = STATE_READ; next_state_ = STATE_READ;
return OK; return OK;
} }
int DiskBasedCertCache::ReadWorker::DoRead() { int DiskBasedCertCache::ReadWorker::DoRead() {
state_ = STATE_READ_COMPLETE; next_state_ = STATE_READ_COMPLETE;
io_buf_len_ = entry_->GetDataSize(0 /* index */); io_buf_len_ = entry_->GetDataSize(0 /* index */);
buffer_ = new IOBuffer(io_buf_len_); buffer_ = new IOBuffer(io_buf_len_);
return entry_->ReadData( return entry_->ReadData(
...@@ -525,7 +522,8 @@ DiskBasedCertCache::~DiskBasedCertCache() { ...@@ -525,7 +522,8 @@ DiskBasedCertCache::~DiskBasedCertCache() {
} }
} }
void DiskBasedCertCache::Get(const std::string& key, const GetCallback& cb) { void DiskBasedCertCache::GetCertificate(const std::string& key,
const GetCallback& cb) {
DCHECK(!key.empty()); DCHECK(!key.empty());
// If the handle is already in the MRU cache, just return that (via callback). // If the handle is already in the MRU cache, just return that (via callback).
...@@ -557,8 +555,9 @@ void DiskBasedCertCache::Get(const std::string& key, const GetCallback& cb) { ...@@ -557,8 +555,9 @@ void DiskBasedCertCache::Get(const std::string& key, const GetCallback& cb) {
} }
} }
void DiskBasedCertCache::Set(const X509Certificate::OSCertHandle cert_handle, void DiskBasedCertCache::SetCertificate(
const SetCallback& cb) { const X509Certificate::OSCertHandle cert_handle,
const SetCallback& cb) {
DCHECK(!cb.is_null()); DCHECK(!cb.is_null());
DCHECK(cert_handle); DCHECK(cert_handle);
std::string key = GetCacheKeyForCert(cert_handle); std::string key = GetCacheKeyForCert(cert_handle);
......
...@@ -29,8 +29,8 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache { ...@@ -29,8 +29,8 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache {
GetCallback; GetCallback;
typedef base::Callback<void(const std::string&)> SetCallback; typedef base::Callback<void(const std::string&)> SetCallback;
// Initializes a new DiskBasedCertCache that will use |backend|, which has // Initializes a new DiskBasedCertCache that will access the disk cache via
// previously been initialized, to store the certificate in the cache. // |backend|.
explicit DiskBasedCertCache(disk_cache::Backend* backend); explicit DiskBasedCertCache(disk_cache::Backend* backend);
~DiskBasedCertCache(); ~DiskBasedCertCache();
...@@ -39,20 +39,22 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache { ...@@ -39,20 +39,22 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache {
// Otherwise, |cb| will be called with NULL. Callers that wish to store // Otherwise, |cb| will be called with NULL. Callers that wish to store
// a reference to the certificate need to use X509Certificate::DupOSCertHandle // a reference to the certificate need to use X509Certificate::DupOSCertHandle
// inside |cb|. // inside |cb|.
void Get(const std::string& key, const GetCallback& cb); void GetCertificate(const std::string& key, const GetCallback& cb);
// Stores |cert_handle| in the cache. If |cert_handle| is successfully stored, // Stores |cert_handle| in the cache. If |cert_handle| is successfully stored,
// |cb| will be called with the key. If |cb| is called with an empty // |cb| will be called with the key. If |cb| is called with an empty
// string, then |cert_handle| was not stored. // string, then |cert_handle| was not stored.
void Set(const X509Certificate::OSCertHandle cert_handle, void SetCertificate(const X509Certificate::OSCertHandle cert_handle,
const SetCallback& cb); const SetCallback& cb);
// Returns the number of in-memory MRU cache hits that have occurred // Returns the number of in-memory MRU cache hits that have occurred
// on Set and Get operations. Intended for test purposes only. // on SetCertificate and GetCertificate operations. Intended for test purposes
// only.
size_t mem_cache_hits_for_testing() const { return mem_cache_hits_; } size_t mem_cache_hits_for_testing() const { return mem_cache_hits_; }
// Returns the number of in-memory MRU cache misses that have occurred // Returns the number of in-memory MRU cache misses that have occurred
// on Set and Get operations. Intended for test purposes only. // on SetCertificate and GetCertificate operations. Intended for test purposes
// only.
size_t mem_cache_misses_for_testing() const { return mem_cache_misses_; } size_t mem_cache_misses_for_testing() const { return mem_cache_misses_; }
private: private:
...@@ -64,8 +66,8 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache { ...@@ -64,8 +66,8 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache {
void operator()(X509Certificate::OSCertHandle cert_handle); void operator()(X509Certificate::OSCertHandle cert_handle);
}; };
// An in-memory cache that is used to prevent redundant reads and writes // An in-memory cache that is used to prevent redundantly reading
// to and from the disk cache. // from disk.
typedef base::MRUCacheBase<std::string, typedef base::MRUCacheBase<std::string,
X509Certificate::OSCertHandle, X509Certificate::OSCertHandle,
CertFree> MRUCertCache; CertFree> MRUCertCache;
...@@ -75,9 +77,9 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache { ...@@ -75,9 +77,9 @@ class NET_EXPORT_PRIVATE DiskBasedCertCache {
typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap;
typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap;
// FinishedReadOperation and FinishedWriteOperation are used by callbacks // FinishedReadOperation and FinishedWriteOperation are used to remove
// given to the workers to signal the DiskBasedCertCache they have completed // workers from their respective worker maps, and perform other necessary
// their work. // cleanup. They are called from the workers via callback.
void FinishedReadOperation(const std::string& key, void FinishedReadOperation(const std::string& key,
X509Certificate::OSCertHandle cert_handle); X509Certificate::OSCertHandle cert_handle);
void FinishedWriteOperation(const std::string& key, void FinishedWriteOperation(const std::string& key,
......
...@@ -51,9 +51,9 @@ MockTransaction CreateMockTransaction(const char* key, int test_mode) { ...@@ -51,9 +51,9 @@ MockTransaction CreateMockTransaction(const char* key, int test_mode) {
return transaction; return transaction;
} }
// Helper class, for use with DiskBasedCertCache::Get, that will ensure that // Helper class, for use with DiskBasedCertCache::GetCertificate, that will
// the returned certificate handle is kept alive after the callback has been // store the returned certificate handle and allow users to WaitForResult of
// executed and allow a user to WaitForResult of DiskBasedCertCache::Get. // DiskBasedCertCache::GetCertificate.
class TestGetCallback { class TestGetCallback {
public: public:
TestGetCallback() : cert_handle_(NULL) {} TestGetCallback() : cert_handle_(NULL) {}
...@@ -62,12 +62,12 @@ class TestGetCallback { ...@@ -62,12 +62,12 @@ class TestGetCallback {
X509Certificate::FreeOSCertHandle(cert_handle_); X509Certificate::FreeOSCertHandle(cert_handle_);
} }
// Blocks until the underlying Get() operation has succeeded. // Blocks until the underlying GetCertificate() operation has succeeded.
void WaitForResult() { cb_.WaitForResult(); } void WaitForResult() { cb_.WaitForResult(); }
// Returns a Callback suitable for use with DiskBasedCertCache::Get(). The // Returns a Callback suitable for use with
// returned callback is only valid while the TestGetCallback object is still // DiskBasedCertCache::GetCertificate(). The returned callback is only valid
// valid. // while the TestGetCallback object is still valid.
DiskBasedCertCache::GetCallback callback() { DiskBasedCertCache::GetCallback callback() {
return base::Bind(&TestGetCallback::OnGetComplete, base::Unretained(this)); return base::Bind(&TestGetCallback::OnGetComplete, base::Unretained(this));
} }
...@@ -88,19 +88,20 @@ class TestGetCallback { ...@@ -88,19 +88,20 @@ class TestGetCallback {
X509Certificate::OSCertHandle cert_handle_; X509Certificate::OSCertHandle cert_handle_;
}; };
// Helper class, for use with DiskBasedCertCache::Set, that will store the // Helper class, for use with DiskBasedCertCache::SetCertificate, that will
// returned key and allow a user to WaitForResult of DiskBasedCertCache::Set. // store the returned key and allow a user to WaitForResult of
// DiskBasedCertCache::SetCertificate.
class TestSetCallback { class TestSetCallback {
public: public:
TestSetCallback() {} TestSetCallback() {}
~TestSetCallback() {} ~TestSetCallback() {}
// Blocks until the underlying Set() operation has succeeded. // Blocks until the underlying SetCertificate() operation has succeeded.
void WaitForResult() { cb_.WaitForResult(); } void WaitForResult() { cb_.WaitForResult(); }
// Returns a Callback suitable for use with DiskBasedCertCache::Set(). The // Returns a Callback suitable for use with
// returned callback is only valid while the TestSetCallback object is still // DiskBasedCertCache::SetCertificate(). The returned callback is only valid
// valid. // while the TestSetCallback object is still valid.
DiskBasedCertCache::SetCallback callback() { DiskBasedCertCache::SetCallback callback() {
return base::Bind(&TestSetCallback::OnSetComplete, base::Unretained(this)); return base::Bind(&TestSetCallback::OnSetComplete, base::Unretained(this));
} }
...@@ -193,7 +194,7 @@ TEST(DiskBasedCertCache, SetCert) { ...@@ -193,7 +194,7 @@ TEST(DiskBasedCertCache, SetCert) {
ASSERT_TRUE(cert.get()); ASSERT_TRUE(cert.get());
TestSetCallback set_callback; TestSetCallback set_callback;
cache.Set(cert->os_cert_handle(), set_callback.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback.callback());
set_callback.WaitForResult(); set_callback.WaitForResult();
EXPECT_EQ(kCert1.cache_key, set_callback.key()); EXPECT_EQ(kCert1.cache_key, set_callback.key());
ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1)); ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1));
...@@ -209,7 +210,7 @@ TEST(DiskBasedCertCache, GetCert) { ...@@ -209,7 +210,7 @@ TEST(DiskBasedCertCache, GetCert) {
DiskBasedCertCache cache(&backend); DiskBasedCertCache cache(&backend);
TestGetCallback get_callback; TestGetCallback get_callback;
cache.Get(kCert1.cache_key, get_callback.callback()); cache.GetCertificate(kCert1.cache_key, get_callback.callback());
get_callback.WaitForResult(); get_callback.WaitForResult();
scoped_refptr<X509Certificate> cert( scoped_refptr<X509Certificate> cert(
...@@ -230,7 +231,7 @@ TEST(DiskBasedCertCache, SyncSet) { ...@@ -230,7 +231,7 @@ TEST(DiskBasedCertCache, SyncSet) {
ASSERT_TRUE(cert.get()); ASSERT_TRUE(cert.get());
TestSetCallback set_callback; TestSetCallback set_callback;
cache.Set(cert->os_cert_handle(), set_callback.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback.callback());
set_callback.WaitForResult(); set_callback.WaitForResult();
EXPECT_EQ(kCert1.cache_key, set_callback.key()); EXPECT_EQ(kCert1.cache_key, set_callback.key());
ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1)); ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1));
...@@ -250,13 +251,13 @@ TEST(DiskBasedCertCache, SyncGet) { ...@@ -250,13 +251,13 @@ TEST(DiskBasedCertCache, SyncGet) {
ASSERT_TRUE(cert.get()); ASSERT_TRUE(cert.get());
TestGetCallback get_callback; TestGetCallback get_callback;
cache.Get(kCert1.cache_key, get_callback.callback()); cache.GetCertificate(kCert1.cache_key, get_callback.callback());
get_callback.WaitForResult(); get_callback.WaitForResult();
EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback.cert_handle(), EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback.cert_handle(),
cert->os_cert_handle())); cert->os_cert_handle()));
} }
// Tests that Get will fail on a corrupted certificate. // Tests that GetCertificate will fail on a corrupted certificate.
TEST(DiskBasedCertCache, GetBrokenCert) { TEST(DiskBasedCertCache, GetBrokenCert) {
ScopedMockTransaction trans1( ScopedMockTransaction trans1(
CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL));
...@@ -265,7 +266,7 @@ TEST(DiskBasedCertCache, GetBrokenCert) { ...@@ -265,7 +266,7 @@ TEST(DiskBasedCertCache, GetBrokenCert) {
DiskBasedCertCache cache(&backend); DiskBasedCertCache cache(&backend);
TestGetCallback get_callback; TestGetCallback get_callback;
cache.Get(kCert1.cache_key, get_callback.callback()); cache.GetCertificate(kCert1.cache_key, get_callback.callback());
get_callback.WaitForResult(); get_callback.WaitForResult();
EXPECT_FALSE(get_callback.cert_handle()); EXPECT_FALSE(get_callback.cert_handle());
...@@ -280,7 +281,7 @@ TEST(DiskBasedCertCache, GetUncachedCert) { ...@@ -280,7 +281,7 @@ TEST(DiskBasedCertCache, GetUncachedCert) {
DiskBasedCertCache cache(&backend); DiskBasedCertCache cache(&backend);
TestGetCallback get_callback; TestGetCallback get_callback;
cache.Get(kCert1.cache_key, get_callback.callback()); cache.GetCertificate(kCert1.cache_key, get_callback.callback());
get_callback.WaitForResult(); get_callback.WaitForResult();
EXPECT_EQ(NULL, get_callback.cert_handle()); EXPECT_EQ(NULL, get_callback.cert_handle());
} }
...@@ -300,12 +301,12 @@ TEST(DiskBasedCertCache, SetMultiple) { ...@@ -300,12 +301,12 @@ TEST(DiskBasedCertCache, SetMultiple) {
// Behind the scenes, these two operations will be combined // Behind the scenes, these two operations will be combined
// into one operation. IgnoreCallbacks guarantees that the // into one operation. IgnoreCallbacks guarantees that the
// first Set operation is not yet complete when the second Set is // first SetCertificate operation is not yet complete when the second
// called, and then IgnoreCallbacks(false) continues the // SetCertificate is called, and then IgnoreCallbacks(false) continues the
// (combined) operation in the |cache|. // (combined) operation in the |cache|.
MockDiskEntry::IgnoreCallbacks(true); MockDiskEntry::IgnoreCallbacks(true);
cache.Set(cert->os_cert_handle(), set_callback1.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback1.callback());
cache.Set(cert->os_cert_handle(), set_callback2.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback2.callback());
MockDiskEntry::IgnoreCallbacks(false); MockDiskEntry::IgnoreCallbacks(false);
set_callback1.WaitForResult(); set_callback1.WaitForResult();
...@@ -328,9 +329,9 @@ TEST(DiskBasedCertCache, SetOverwrite) { ...@@ -328,9 +329,9 @@ TEST(DiskBasedCertCache, SetOverwrite) {
ASSERT_TRUE(cert.get()); ASSERT_TRUE(cert.get());
TestSetCallback set_callback1, set_callback2; TestSetCallback set_callback1, set_callback2;
cache.Set(cert->os_cert_handle(), set_callback1.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback1.callback());
set_callback1.WaitForResult(); set_callback1.WaitForResult();
cache.Set(cert->os_cert_handle(), set_callback2.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback2.callback());
set_callback2.WaitForResult(); set_callback2.WaitForResult();
EXPECT_EQ(set_callback1.key(), set_callback2.key()); EXPECT_EQ(set_callback1.key(), set_callback2.key());
...@@ -350,9 +351,9 @@ TEST(DiskBasedCertCache, SimpleSetAndGet) { ...@@ -350,9 +351,9 @@ TEST(DiskBasedCertCache, SimpleSetAndGet) {
TestSetCallback set_callback; TestSetCallback set_callback;
TestGetCallback get_callback; TestGetCallback get_callback;
cache.Set(cert->os_cert_handle(), set_callback.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback.callback());
set_callback.WaitForResult(); set_callback.WaitForResult();
cache.Get(set_callback.key(), get_callback.callback()); cache.GetCertificate(set_callback.key(), get_callback.callback());
get_callback.WaitForResult(); get_callback.WaitForResult();
EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback.cert_handle(), EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback.cert_handle(),
cert->os_cert_handle())); cert->os_cert_handle()));
...@@ -381,8 +382,8 @@ TEST(DiskBasedCertCache, BasicUsage) { ...@@ -381,8 +382,8 @@ TEST(DiskBasedCertCache, BasicUsage) {
// operations of the DiskBasedCertCache are always executed in the same // operations of the DiskBasedCertCache are always executed in the same
// order. // order.
MockDiskEntry::IgnoreCallbacks(true); MockDiskEntry::IgnoreCallbacks(true);
cache.Set(cert1->os_cert_handle(), set_callback1.callback()); cache.SetCertificate(cert1->os_cert_handle(), set_callback1.callback());
cache.Set(cert2->os_cert_handle(), set_callback2.callback()); cache.SetCertificate(cert2->os_cert_handle(), set_callback2.callback());
MockDiskEntry::IgnoreCallbacks(false); MockDiskEntry::IgnoreCallbacks(false);
set_callback1.WaitForResult(); set_callback1.WaitForResult();
set_callback2.WaitForResult(); set_callback2.WaitForResult();
...@@ -390,8 +391,8 @@ TEST(DiskBasedCertCache, BasicUsage) { ...@@ -390,8 +391,8 @@ TEST(DiskBasedCertCache, BasicUsage) {
TestGetCallback get_callback1, get_callback2; TestGetCallback get_callback1, get_callback2;
MockDiskEntry::IgnoreCallbacks(true); MockDiskEntry::IgnoreCallbacks(true);
cache.Get(set_callback1.key(), get_callback1.callback()); cache.GetCertificate(set_callback1.key(), get_callback1.callback());
cache.Get(set_callback2.key(), get_callback2.callback()); cache.GetCertificate(set_callback2.key(), get_callback2.callback());
MockDiskEntry::IgnoreCallbacks(false); MockDiskEntry::IgnoreCallbacks(false);
get_callback1.WaitForResult(); get_callback1.WaitForResult();
get_callback2.WaitForResult(); get_callback2.WaitForResult();
...@@ -418,8 +419,8 @@ TEST(DiskBasedCertCache, SimultaneousGetSet) { ...@@ -418,8 +419,8 @@ TEST(DiskBasedCertCache, SimultaneousGetSet) {
TestSetCallback set_callback; TestSetCallback set_callback;
MockDiskEntry::IgnoreCallbacks(true); MockDiskEntry::IgnoreCallbacks(true);
cache.Get(kCert1.cache_key, get_callback.callback()); cache.GetCertificate(kCert1.cache_key, get_callback.callback());
cache.Set(cert->os_cert_handle(), set_callback.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback.callback());
MockDiskEntry::IgnoreCallbacks(false); MockDiskEntry::IgnoreCallbacks(false);
get_callback.WaitForResult(); get_callback.WaitForResult();
set_callback.WaitForResult(); set_callback.WaitForResult();
...@@ -444,8 +445,8 @@ TEST(DiskBasedCertCache, SimultaneousSetGet) { ...@@ -444,8 +445,8 @@ TEST(DiskBasedCertCache, SimultaneousSetGet) {
TestGetCallback get_callback; TestGetCallback get_callback;
MockDiskEntry::IgnoreCallbacks(true); MockDiskEntry::IgnoreCallbacks(true);
cache.Set(cert->os_cert_handle(), set_callback.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback.callback());
cache.Get(kCert1.cache_key, get_callback.callback()); cache.GetCertificate(kCert1.cache_key, get_callback.callback());
MockDiskEntry::IgnoreCallbacks(false); MockDiskEntry::IgnoreCallbacks(false);
set_callback.WaitForResult(); set_callback.WaitForResult();
get_callback.WaitForResult(); get_callback.WaitForResult();
...@@ -467,7 +468,7 @@ TEST(DiskBasedCertCache, DeletedCertCache) { ...@@ -467,7 +468,7 @@ TEST(DiskBasedCertCache, DeletedCertCache) {
ASSERT_TRUE(cert.get()); ASSERT_TRUE(cert.get());
TestSetCallback set_callback; TestSetCallback set_callback;
cache->Set(cert->os_cert_handle(), set_callback.callback()); cache->SetCertificate(cert->os_cert_handle(), set_callback.callback());
cache.reset(); cache.reset();
set_callback.WaitForResult(); set_callback.WaitForResult();
EXPECT_EQ(std::string(), set_callback.key()); EXPECT_EQ(std::string(), set_callback.key());
...@@ -485,10 +486,10 @@ TEST(DiskBasedCertCache, MemCacheGet) { ...@@ -485,10 +486,10 @@ TEST(DiskBasedCertCache, MemCacheGet) {
DiskBasedCertCache cache(&backend); DiskBasedCertCache cache(&backend);
TestGetCallback get_callback1, get_callback2; TestGetCallback get_callback1, get_callback2;
cache.Get(kCert1.cache_key, get_callback1.callback()); cache.GetCertificate(kCert1.cache_key, get_callback1.callback());
get_callback1.WaitForResult(); get_callback1.WaitForResult();
EXPECT_EQ(0U, cache.mem_cache_hits_for_testing()); EXPECT_EQ(0U, cache.mem_cache_hits_for_testing());
cache.Get(kCert1.cache_key, get_callback2.callback()); cache.GetCertificate(kCert1.cache_key, get_callback2.callback());
get_callback2.WaitForResult(); get_callback2.WaitForResult();
EXPECT_EQ(1U, cache.mem_cache_hits_for_testing()); EXPECT_EQ(1U, cache.mem_cache_hits_for_testing());
EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback1.cert_handle(), EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback1.cert_handle(),
...@@ -507,7 +508,7 @@ TEST(DiskBasedCertCache, CorruptOverwrite) { ...@@ -507,7 +508,7 @@ TEST(DiskBasedCertCache, CorruptOverwrite) {
DiskBasedCertCache cache(&backend); DiskBasedCertCache cache(&backend);
TestGetCallback get_callback1, get_callback2; TestGetCallback get_callback1, get_callback2;
cache.Get(kCert1.cache_key, get_callback1.callback()); cache.GetCertificate(kCert1.cache_key, get_callback1.callback());
get_callback1.WaitForResult(); get_callback1.WaitForResult();
EXPECT_FALSE(get_callback2.cert_handle()); EXPECT_FALSE(get_callback2.cert_handle());
...@@ -515,12 +516,12 @@ TEST(DiskBasedCertCache, CorruptOverwrite) { ...@@ -515,12 +516,12 @@ TEST(DiskBasedCertCache, CorruptOverwrite) {
ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name)); ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name));
TestSetCallback set_callback; TestSetCallback set_callback;
cache.Set(cert->os_cert_handle(), set_callback.callback()); cache.SetCertificate(cert->os_cert_handle(), set_callback.callback());
set_callback.WaitForResult(); set_callback.WaitForResult();
EXPECT_EQ(kCert1.cache_key, set_callback.key()); EXPECT_EQ(kCert1.cache_key, set_callback.key());
EXPECT_EQ(0U, cache.mem_cache_hits_for_testing()); EXPECT_EQ(0U, cache.mem_cache_hits_for_testing());
cache.Get(kCert1.cache_key, get_callback2.callback()); cache.GetCertificate(kCert1.cache_key, get_callback2.callback());
get_callback2.WaitForResult(); get_callback2.WaitForResult();
EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback2.cert_handle(), EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback2.cert_handle(),
cert->os_cert_handle())); cert->os_cert_handle()));
......
...@@ -1886,11 +1886,11 @@ void HttpCache::Transaction::ReadCertChain() { ...@@ -1886,11 +1886,11 @@ void HttpCache::Transaction::ReadCertChain() {
scoped_refptr<SharedChainData> shared_chain_data( scoped_refptr<SharedChainData> shared_chain_data(
new SharedChainData(intermediates.size() + 1, TimeTicks::Now())); new SharedChainData(intermediates.size() + 1, TimeTicks::Now()));
cache_->cert_cache()->Get(key, cache_->cert_cache()->GetCertificate(key,
base::Bind(&OnCertReadIOComplete, base::Bind(&OnCertReadIOComplete,
dist_from_root, dist_from_root,
true /* is leaf */, true /* is leaf */,
shared_chain_data)); shared_chain_data));
for (X509Certificate::OSCertHandles::const_iterator it = for (X509Certificate::OSCertHandles::const_iterator it =
intermediates.begin(); intermediates.begin();
...@@ -1898,11 +1898,11 @@ void HttpCache::Transaction::ReadCertChain() { ...@@ -1898,11 +1898,11 @@ void HttpCache::Transaction::ReadCertChain() {
++it) { ++it) {
--dist_from_root; --dist_from_root;
key = GetCacheKeyForCert(*it); key = GetCacheKeyForCert(*it);
cache_->cert_cache()->Get(key, cache_->cert_cache()->GetCertificate(key,
base::Bind(&OnCertReadIOComplete, base::Bind(&OnCertReadIOComplete,
dist_from_root, dist_from_root,
false /* is not leaf */, false /* is not leaf */,
shared_chain_data)); shared_chain_data));
} }
DCHECK_EQ(0, dist_from_root); DCHECK_EQ(0, dist_from_root);
} }
...@@ -1914,21 +1914,22 @@ void HttpCache::Transaction::WriteCertChain() { ...@@ -1914,21 +1914,22 @@ void HttpCache::Transaction::WriteCertChain() {
scoped_refptr<SharedChainData> shared_chain_data( scoped_refptr<SharedChainData> shared_chain_data(
new SharedChainData(intermediates.size() + 1, TimeTicks::Now())); new SharedChainData(intermediates.size() + 1, TimeTicks::Now()));
cache_->cert_cache()->Set(response_.ssl_info.cert->os_cert_handle(), cache_->cert_cache()->SetCertificate(
base::Bind(&OnCertWriteIOComplete, response_.ssl_info.cert->os_cert_handle(),
dist_from_root, base::Bind(&OnCertWriteIOComplete,
true /* is leaf */, dist_from_root,
shared_chain_data)); true /* is leaf */,
shared_chain_data));
for (X509Certificate::OSCertHandles::const_iterator it = for (X509Certificate::OSCertHandles::const_iterator it =
intermediates.begin(); intermediates.begin();
it != intermediates.end(); it != intermediates.end();
++it) { ++it) {
--dist_from_root; --dist_from_root;
cache_->cert_cache()->Set(*it, cache_->cert_cache()->SetCertificate(*it,
base::Bind(&OnCertWriteIOComplete, base::Bind(&OnCertWriteIOComplete,
dist_from_root, dist_from_root,
false /* is not leaf */, false /* is not leaf */,
shared_chain_data)); shared_chain_data));
} }
DCHECK_EQ(0, dist_from_root); DCHECK_EQ(0, dist_from_root);
} }
...@@ -1944,7 +1945,7 @@ void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log, ...@@ -1944,7 +1945,7 @@ void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log,
break; break;
case RECORD: case RECORD:
// When in record mode, we want to NEVER load from the cache. // When in record mode, we want to NEVER load from the cache.
// The reason for this is beacuse we save the Set-Cookie headers // The reason for this is because we save the Set-Cookie headers
// (intentionally). If we read from the cache, we replay them // (intentionally). If we read from the cache, we replay them
// prematurely. // prematurely.
effective_load_flags_ |= LOAD_BYPASS_CACHE; effective_load_flags_ |= LOAD_BYPASS_CACHE;
......
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