diff options
28 files changed, 169 insertions, 957 deletions
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc index 6717495..8a2a8d0 100644 --- a/chrome/browser/browsing_data_remover.cc +++ b/chrome/browser/browsing_data_remover.cc @@ -74,8 +74,7 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, delete_begin_(delete_begin), delete_end_(delete_end), ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( - base::Bind(&BrowsingDataRemover::DoClearCache, - base::Unretained(this)))), + this, &BrowsingDataRemover::DoClearCache)), next_cache_state_(STATE_NONE), cache_(NULL), main_context_getter_(profile->GetRequestContext()), @@ -98,8 +97,7 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, delete_begin_(CalculateBeginDeleteTime(time_period)), delete_end_(delete_end), ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( - base::Bind(&BrowsingDataRemover::DoClearCache, - base::Unretained(this)))), + this, &BrowsingDataRemover::DoClearCache)), next_cache_state_(STATE_NONE), cache_(NULL), main_context_getter_(profile->GetRequestContext()), @@ -438,7 +436,7 @@ void BrowsingDataRemover::DoClearCache(int rv) { net::HttpTransactionFactory* factory = getter->GetURLRequestContext()->http_transaction_factory(); - rv = factory->GetCache()->GetBackend(&cache_, cache_callback_); + rv = factory->GetCache()->GetBackend(&cache_, &cache_callback_); next_cache_state_ = (next_cache_state_ == STATE_CREATE_MAIN) ? STATE_DELETE_MAIN : STATE_DELETE_MEDIA; break; @@ -448,10 +446,10 @@ void BrowsingDataRemover::DoClearCache(int rv) { // |cache_| can be null if it cannot be initialized. if (cache_) { if (delete_begin_.is_null()) { - rv = cache_->DoomAllEntries(cache_callback_); + rv = cache_->DoomAllEntries(&cache_callback_); } else { rv = cache_->DoomEntriesBetween(delete_begin_, delete_end_, - cache_callback_); + &cache_callback_); } cache_ = NULL; } diff --git a/chrome/browser/browsing_data_remover.h b/chrome/browser/browsing_data_remover.h index 10f9061..385ecaa 100644 --- a/chrome/browser/browsing_data_remover.h +++ b/chrome/browser/browsing_data_remover.h @@ -229,7 +229,7 @@ class BrowsingDataRemover : public content::NotificationObserver, static bool removing_; // Used to delete data from the HTTP caches. - net::CompletionCallback cache_callback_; + net::OldCompletionCallbackImpl<BrowsingDataRemover> cache_callback_; CacheState next_cache_state_; disk_cache::Backend* cache_; diff --git a/chrome/browser/chrome_benchmarking_message_filter.cc b/chrome/browser/chrome_benchmarking_message_filter.cc index 3421192..577679c 100644 --- a/chrome/browser/chrome_benchmarking_message_filter.cc +++ b/chrome/browser/chrome_benchmarking_message_filter.cc @@ -4,10 +4,7 @@ #include "chrome/browser/chrome_benchmarking_message_filter.h" -#include "base/bind.h" -#include "base/bind_helpers.h" #include "base/command_line.h" -#include "base/memory/scoped_ptr.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/profiles/profile.h" @@ -22,17 +19,18 @@ namespace { -class ClearCacheHelper { +class ClearCacheCompletion : public net::OldCompletionCallback { public: - ClearCacheHelper(ChromeBenchmarkingMessageFilter* filter, - IPC::Message* reply_msg) + ClearCacheCompletion(ChromeBenchmarkingMessageFilter* filter, + IPC::Message* reply_msg) : filter_(filter), reply_msg_(reply_msg) { } - void Run(int result) { - ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg_, result); + virtual void RunWithParams(const Tuple1<int>& params) { + ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg_, params.a); filter_->Send(reply_msg_); + delete this; } private: @@ -48,25 +46,21 @@ class DoomEntriesHelper { : backend_(backend), entry_(NULL), iter_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(callback_( - base::Bind(&DoomEntriesHelper::CacheCallback, - base::Unretained(this)))), - clear_cache_helper_(NULL) { + ALLOW_THIS_IN_INITIALIZER_LIST(callback_(this, + &DoomEntriesHelper::CacheCallback)), + user_callback_(NULL) { } - // Takes ownership of |callback|. - void ClearCache(ClearCacheHelper* helper) { - clear_cache_helper_.reset(helper); + void ClearCache(ClearCacheCompletion* callback) { + user_callback_ = callback; return CacheCallback(net::OK); // Start clearing the cache. } - const net::CompletionCallback& callback() { return callback_; } - private: void CacheCallback(int result) { do { if (result != net::OK) { - clear_cache_helper_->Run(result); + user_callback_->RunWithParams(Tuple1<int>(result)); delete this; return; } @@ -82,15 +76,15 @@ class DoomEntriesHelper { entry_->Close(); entry_ = NULL; } - result = backend_->OpenNextEntry(&iter_, &entry_, callback_); + result = backend_->OpenNextEntry(&iter_, &entry_, &callback_); } while (result != net::ERR_IO_PENDING); } disk_cache::Backend* backend_; disk_cache::Entry* entry_; void* iter_; - net::CompletionCallback callback_; - scoped_ptr<ClearCacheHelper> clear_cache_helper_; + net::OldCompletionCallbackImpl<DoomEntriesHelper> callback_; + ClearCacheCompletion* user_callback_; }; } // namespace @@ -138,20 +132,20 @@ void ChromeBenchmarkingMessageFilter::OnClearCache(bool preserve_ssl_host_info, disk_cache::Backend* backend = request_context_->GetURLRequestContext()-> http_transaction_factory()->GetCache()->GetCurrentBackend(); if (backend) { - scoped_ptr<ClearCacheHelper> clear_cache_helper( - new ClearCacheHelper(this, reply_msg)); + ClearCacheCompletion* callback = + new ClearCacheCompletion(this, reply_msg); if (preserve_ssl_host_info) { DoomEntriesHelper* helper = new DoomEntriesHelper(backend); - helper->ClearCache(clear_cache_helper.release()); // Will self clean. + helper->ClearCache(callback); // Will self clean. return; } else { - rv = backend->DoomAllEntries( - base::Bind(&ClearCacheHelper::Run, - base::Owned(clear_cache_helper.release()))); + rv = backend->DoomAllEntries(callback); if (rv == net::ERR_IO_PENDING) { // The callback will send the reply. return; } + // Completed synchronously, no need for the callback. + delete callback; } } ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, rv); diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc index 52fa633..67fdb68 100644 --- a/chrome/browser/safe_browsing/malware_details_unittest.cc +++ b/chrome/browser/safe_browsing/malware_details_unittest.cc @@ -106,11 +106,11 @@ void WriteToEntry(disk_cache::Backend* cache, const std::string key, } void FillCache(net::URLRequestContextGetter* context_getter) { - net::TestCompletionCallback cb; + TestOldCompletionCallback cb; disk_cache::Backend* cache; int rv = context_getter->GetURLRequestContext()->http_transaction_factory()-> - GetCache()->GetBackend(&cache, cb.callback()); + GetCache()->GetBackend(&cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); std::string empty; diff --git a/chrome_frame/test/infobar_unittests.cc b/chrome_frame/test/infobar_unittests.cc index 6b3ee39..6704e29 100644 --- a/chrome_frame/test/infobar_unittests.cc +++ b/chrome_frame/test/infobar_unittests.cc @@ -97,7 +97,7 @@ template<typename T> class MockDelegate virtual ~MockDelegate() { Die(); } MOCK_METHOD0(Die, void()); MOCK_METHOD1(AdjustDisplacedWindowDimensions, void(RECT* rect)); -}; // class MockDelegate +}; // clas MockDelegate template<typename T> T* Initialize(T* t, HWND hwnd, diff --git a/net/base/test_completion_callback.cc b/net/base/test_completion_callback.cc index 9d1de1a..6851a7c 100644 --- a/net/base/test_completion_callback.cc +++ b/net/base/test_completion_callback.cc @@ -9,53 +9,50 @@ #include "base/message_loop.h" #include "net/base/net_errors.h" -void TestCompletionCallbackBase::SetResult(int result) { - result_ = result; - have_result_ = true; - if (waiting_for_result_) - MessageLoop::current()->Quit(); +TestOldCompletionCallback::TestOldCompletionCallback() + : result_(0), + have_result_(false), + waiting_for_result_(false) { } -int TestCompletionCallbackBase::WaitForResult() { - DCHECK(!waiting_for_result_); +TestOldCompletionCallback::~TestOldCompletionCallback() {} +int TestOldCompletionCallback::WaitForResult() { + DCHECK(!waiting_for_result_); while (!have_result_) { - printf("waiting\n"); waiting_for_result_ = true; MessageLoop::current()->Run(); waiting_for_result_ = false; } - - have_result_ = false; // Auto-reset for next callback. + have_result_ = false; // auto-reset for next callback return result_; } -int TestCompletionCallbackBase::GetResult(int result) { +int TestOldCompletionCallback::GetResult(int result) { if (net::ERR_IO_PENDING != result) return result; - return WaitForResult(); } -TestCompletionCallbackBase::TestCompletionCallbackBase() - : result_(0), - have_result_(false), - waiting_for_result_(false) { -} - void TestOldCompletionCallback::RunWithParams(const Tuple1<int>& params) { - SetResult(params.a); + result_ = params.a; + have_result_ = true; + if (waiting_for_result_) + MessageLoop::current()->Quit(); } namespace net { TestCompletionCallback::TestCompletionCallback() : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( - base::Bind(&TestCompletionCallback::SetResult, + base::Bind(&TestCompletionCallback::OnComplete, base::Unretained(this)))) { } TestCompletionCallback::~TestCompletionCallback() {} +void TestCompletionCallback::OnComplete(int result) { + old_callback_impl_.RunWithParams(Tuple1<int>(result)); +} } // namespace net diff --git a/net/base/test_completion_callback.h b/net/base/test_completion_callback.h index 888c610..a192194 100644 --- a/net/base/test_completion_callback.h +++ b/net/base/test_completion_callback.h @@ -22,51 +22,45 @@ // there could be other side-effects resulting from WaitForResult. For this // reason, this class is probably not ideal for a general application. // - -// Base class overridden by custom implementations of TestCompletionCallback. -class TestCompletionCallbackBase { +class TestOldCompletionCallback : public CallbackRunner< Tuple1<int> > { public: - void SetResult(int result); + TestOldCompletionCallback(); + virtual ~TestOldCompletionCallback(); + int WaitForResult(); + int GetResult(int result); + bool have_result() const { return have_result_; } - protected: - TestCompletionCallbackBase(); + virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE; + private: int result_; bool have_result_; bool waiting_for_result_; - - private: - DISALLOW_COPY_AND_ASSIGN(TestCompletionCallbackBase); -}; - -class TestOldCompletionCallback : public TestCompletionCallbackBase, - public CallbackRunner< Tuple1<int> > { - public: - TestOldCompletionCallback() {}; - virtual ~TestOldCompletionCallback() {} - - virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(TestOldCompletionCallback); }; namespace net { -class TestCompletionCallback : public TestCompletionCallbackBase { +class TestCompletionCallback { public: TestCompletionCallback(); ~TestCompletionCallback(); + int WaitForResult() { return old_callback_impl_.WaitForResult(); } + + int GetResult(int result) { return old_callback_impl_.GetResult(result); } + + bool have_result() const { return old_callback_impl_.have_result(); } + const CompletionCallback& callback() const { return callback_; } private: - const CompletionCallback callback_; + void OnComplete(int result); - DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); + const CompletionCallback callback_; + TestOldCompletionCallback old_callback_impl_; }; } // namespace net diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index d452f22..14a2722 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -1381,13 +1381,6 @@ int BackendImpl::OpenEntry(const std::string& key, Entry** entry, return net::ERR_IO_PENDING; } -int BackendImpl::OpenEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) { - DCHECK(!callback.is_null()); - background_queue_.OpenEntry(key, entry, callback); - return net::ERR_IO_PENDING; -} - int BackendImpl::CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) { DCHECK(callback); @@ -1395,13 +1388,6 @@ int BackendImpl::CreateEntry(const std::string& key, Entry** entry, return net::ERR_IO_PENDING; } -int BackendImpl::CreateEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) { - DCHECK(!callback.is_null()); - background_queue_.CreateEntry(key, entry, callback); - return net::ERR_IO_PENDING; -} - int BackendImpl::DoomEntry(const std::string& key, OldCompletionCallback* callback) { DCHECK(callback); @@ -1415,12 +1401,6 @@ int BackendImpl::DoomAllEntries(OldCompletionCallback* callback) { return net::ERR_IO_PENDING; } -int BackendImpl::DoomAllEntries(const net::CompletionCallback& callback) { - DCHECK(!callback.is_null()); - background_queue_.DoomAllEntries(callback); - return net::ERR_IO_PENDING; -} - int BackendImpl::DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, OldCompletionCallback* callback) { @@ -1429,14 +1409,6 @@ int BackendImpl::DoomEntriesBetween(const base::Time initial_time, return net::ERR_IO_PENDING; } -int BackendImpl::DoomEntriesBetween(const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback) { - DCHECK(!callback.is_null()); - background_queue_.DoomEntriesBetween(initial_time, end_time, callback); - return net::ERR_IO_PENDING; -} - int BackendImpl::DoomEntriesSince(const base::Time initial_time, OldCompletionCallback* callback) { DCHECK(callback); @@ -1451,13 +1423,6 @@ int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry, return net::ERR_IO_PENDING; } -int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry, - const net::CompletionCallback& callback) { - DCHECK(!callback.is_null()); - background_queue_.OpenNextEntry(iter, next_entry, callback); - return net::ERR_IO_PENDING; -} - void BackendImpl::EndEnumeration(void** iter) { background_queue_.EndEnumeration(*iter); *iter = NULL; diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h index 96ac24b..1e38678 100644 --- a/net/disk_cache/backend_impl.h +++ b/net/disk_cache/backend_impl.h @@ -65,7 +65,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { int SyncInit(); void CleanupCache(); - // Same behavior as OpenNextEntry but walks the list from back to front. + // Same bahavior as OpenNextEntry but walks the list from back to front. int OpenPrevEntry(void** iter, Entry** prev_entry, OldCompletionCallback* callback); @@ -260,29 +260,18 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { virtual int32 GetEntryCount() const OVERRIDE; virtual int OpenEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; - virtual int OpenEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) OVERRIDE; virtual int CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; - virtual int CreateEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntry(const std::string& key, OldCompletionCallback* callback) OVERRIDE; virtual int DoomAllEntries(OldCompletionCallback* callback) OVERRIDE; - virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, OldCompletionCallback* callback) OVERRIDE; - virtual int DoomEntriesBetween( - const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntriesSince(const base::Time initial_time, OldCompletionCallback* callback) OVERRIDE; virtual int OpenNextEntry(void** iter, Entry** next_entry, OldCompletionCallback* callback) OVERRIDE; - virtual int OpenNextEntry(void** iter, Entry** next_entry, - const net::CompletionCallback& callback) OVERRIDE; virtual void EndEnumeration(void** iter) OVERRIDE; virtual void GetStats(StatsItems* stats) OVERRIDE; virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h index ca29cb2..3e0efa6 100644 --- a/net/disk_cache/disk_cache.h +++ b/net/disk_cache/disk_cache.h @@ -78,8 +78,6 @@ class NET_EXPORT Backend { // |entry| must remain valid until the operation completes. virtual int OpenEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) = 0; - virtual int OpenEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) = 0; // Creates a new entry. Upon success, the out param holds a pointer to an // Entry object representing the newly created disk cache entry. When the @@ -89,8 +87,6 @@ class NET_EXPORT Backend { // receive the |entry| must remain valid until the operation completes. virtual int CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) = 0; - virtual int CreateEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) = 0; // Marks the entry, specified by the given key, for deletion. The return value // is a net error code. If this method returns ERR_IO_PENDING, the |callback| @@ -102,7 +98,6 @@ class NET_EXPORT Backend { // this method returns ERR_IO_PENDING, the |callback| will be invoked when the // operation completes. virtual int DoomAllEntries(OldCompletionCallback* callback) = 0; - virtual int DoomAllEntries(const net::CompletionCallback& callback) = 0; // Marks a range of entries for deletion. This supports unbounded deletes in // either direction by using null Time values for either argument. The return @@ -111,9 +106,6 @@ class NET_EXPORT Backend { virtual int DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, OldCompletionCallback* callback) = 0; - virtual int DoomEntriesBetween(const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback) = 0; // Marks all entries accessed since |initial_time| for deletion. The return // value is a net error code. If this method returns ERR_IO_PENDING, the @@ -135,8 +127,6 @@ class NET_EXPORT Backend { // therefore it does not impact the eviction ranking of the entry. virtual int OpenNextEntry(void** iter, Entry** next_entry, OldCompletionCallback* callback) = 0; - virtual int OpenNextEntry(void** iter, Entry** next_entry, - const net::CompletionCallback& callback) = 0; // Releases iter without returning the next entry. Whenever OpenNextEntry() // returns true, but the caller is not interested in continuing the @@ -189,8 +179,6 @@ class NET_EXPORT Entry { // performed from the callback code. virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* completion_callback) = 0; - virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback) = 0; // Copies cache data from the given buffer of length |buf_len|. If // completion_callback is null, then this call blocks until the write @@ -208,9 +196,6 @@ class NET_EXPORT Entry { virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* completion_callback, bool truncate) = 0; - virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback, - bool truncate) = 0; // Sparse entries support: // diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 7ba6e94..7e13029 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -35,14 +35,6 @@ class SyncCallback: public disk_cache::FileIOCallback { SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer, net::OldCompletionCallback* callback, net::NetLog::EventType end_event_type) - : entry_(entry), old_callback_(callback), buf_(buffer), - start_(TimeTicks::Now()), end_event_type_(end_event_type) { - entry->AddRef(); - entry->IncrementIoCount(); - } - SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer, - const net::CompletionCallback& callback, - net::NetLog::EventType end_event_type) : entry_(entry), callback_(callback), buf_(buffer), start_(TimeTicks::Now()), end_event_type_(end_event_type) { entry->AddRef(); @@ -55,8 +47,7 @@ class SyncCallback: public disk_cache::FileIOCallback { private: disk_cache::EntryImpl* entry_; - net::OldCompletionCallback* old_callback_; - net::CompletionCallback callback_; + net::OldCompletionCallback* callback_; scoped_refptr<net::IOBuffer> buf_; TimeTicks start_; const net::NetLog::EventType end_event_type_; @@ -66,7 +57,7 @@ class SyncCallback: public disk_cache::FileIOCallback { void SyncCallback::OnFileIOComplete(int bytes_copied) { entry_->DecrementIoCount(); - if (old_callback_ || !callback_.is_null()) { + if (callback_) { if (entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().EndEvent( end_event_type_, @@ -74,19 +65,14 @@ void SyncCallback::OnFileIOComplete(int bytes_copied) { new disk_cache::ReadWriteCompleteParameters(bytes_copied))); } entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_); - - if (old_callback_) - old_callback_->Run(bytes_copied); - else - callback_.Run(bytes_copied); + callback_->Run(bytes_copied); } entry_->Release(); delete this; } void SyncCallback::Discard() { - old_callback_ = NULL; - callback_.Reset(); + callback_ = NULL; buf_ = NULL; OnFileIOComplete(0); } @@ -341,26 +327,6 @@ int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf, return result; } -int EntryImpl::ReadDataImpl( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) { - if (net_log_.IsLoggingAllEvents()) { - net_log_.BeginEvent( - net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, false))); - } - - int result = InternalReadData(index, offset, buf, buf_len, callback); - - if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { - net_log_.EndEvent( - net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); - } - return result; -} - int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate) { @@ -382,27 +348,6 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, return result; } -int EntryImpl::WriteDataImpl( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback, bool truncate) { - if (net_log_.IsLoggingAllEvents()) { - net_log_.BeginEvent( - net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, truncate))); - } - - int result = InternalWriteData(index, offset, buf, buf_len, callback, - truncate); - - if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { - net_log_.EndEvent( - net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); - } - return result; -} - int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback) { DCHECK(node_.Data()->dirty || read_only_); @@ -873,27 +818,6 @@ int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, return net::ERR_IO_PENDING; } -int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) { - if (callback.is_null()) - return ReadDataImpl(index, offset, buf, buf_len, callback); - - DCHECK(node_.Data()->dirty || read_only_); - if (index < 0 || index >= kNumStreams) - return net::ERR_INVALID_ARGUMENT; - - int entry_size = entry_.Data()->data_size[index]; - if (offset >= entry_size || offset < 0 || !buf_len) - return 0; - - if (buf_len < 0) - return net::ERR_INVALID_ARGUMENT; - - backend_->background_queue()->ReadData(this, index, offset, buf, buf_len, - callback); - return net::ERR_IO_PENDING; -} - int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate) { if (!callback) @@ -911,24 +835,6 @@ int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, return net::ERR_IO_PENDING; } -int EntryImpl::WriteData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback, bool truncate) { - if (callback.is_null()) - return WriteDataImpl(index, offset, buf, buf_len, callback, truncate); - - DCHECK(node_.Data()->dirty || read_only_); - if (index < 0 || index >= kNumStreams) - return net::ERR_INVALID_ARGUMENT; - - if (offset < 0 || buf_len < 0) - return net::ERR_INVALID_ARGUMENT; - - backend_->background_queue()->WriteData(this, index, offset, buf, buf_len, - truncate, callback); - return net::ERR_IO_PENDING; -} - int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) { if (!callback) @@ -1107,82 +1013,6 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, return (completed || !callback) ? buf_len : net::ERR_IO_PENDING; } -int EntryImpl::InternalReadData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) { - DCHECK(node_.Data()->dirty || read_only_); - DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len; - if (index < 0 || index >= kNumStreams) - return net::ERR_INVALID_ARGUMENT; - - int entry_size = entry_.Data()->data_size[index]; - if (offset >= entry_size || offset < 0 || !buf_len) - return 0; - - if (buf_len < 0) - return net::ERR_INVALID_ARGUMENT; - - TimeTicks start = TimeTicks::Now(); - - if (offset + buf_len > entry_size) - buf_len = entry_size - offset; - - UpdateRank(false); - - backend_->OnEvent(Stats::READ_DATA); - backend_->OnRead(buf_len); - - Addr address(entry_.Data()->data_addr[index]); - int eof = address.is_initialized() ? entry_size : 0; - if (user_buffers_[index].get() && - user_buffers_[index]->PreRead(eof, offset, &buf_len)) { - // Complete the operation locally. - buf_len = user_buffers_[index]->Read(offset, buf, buf_len); - ReportIOTime(kRead, start); - return buf_len; - } - - address.set_value(entry_.Data()->data_addr[index]); - DCHECK(address.is_initialized()); - if (!address.is_initialized()) - return net::ERR_FAILED; - - File* file = GetBackingFile(address, index); - if (!file) - return net::ERR_FAILED; - - size_t file_offset = offset; - if (address.is_block_file()) { - DCHECK_LE(offset + buf_len, kMaxBlockSize); - file_offset += address.start_block() * address.BlockSize() + - kBlockHeaderSize; - } - - SyncCallback* io_callback = NULL; - if (!callback.is_null()) { - io_callback = new SyncCallback(this, buf, callback, - net::NetLog::TYPE_ENTRY_READ_DATA); - } - - TimeTicks start_async = TimeTicks::Now(); - - bool completed; - if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) { - if (io_callback) - io_callback->Discard(); - return net::ERR_FAILED; - } - - if (io_callback && completed) - io_callback->Discard(); - - if (io_callback) - ReportIOTime(kReadAsync1, start_async); - - ReportIOTime(kRead, start); - return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING; -} - int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate) { @@ -1283,106 +1113,6 @@ int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, return (completed || !callback) ? buf_len : net::ERR_IO_PENDING; } -int EntryImpl::InternalWriteData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback, bool truncate) { - DCHECK(node_.Data()->dirty || read_only_); - DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len; - if (index < 0 || index >= kNumStreams) - return net::ERR_INVALID_ARGUMENT; - - if (offset < 0 || buf_len < 0) - return net::ERR_INVALID_ARGUMENT; - - int max_file_size = backend_->MaxFileSize(); - - // offset or buf_len could be negative numbers. - if (offset > max_file_size || buf_len > max_file_size || - offset + buf_len > max_file_size) { - int size = offset + buf_len; - if (size <= max_file_size) - size = kint32max; - backend_->TooMuchStorageRequested(size); - return net::ERR_FAILED; - } - - TimeTicks start = TimeTicks::Now(); - - // Read the size at this point (it may change inside prepare). - int entry_size = entry_.Data()->data_size[index]; - bool extending = entry_size < offset + buf_len; - truncate = truncate && entry_size > offset + buf_len; - Trace("To PrepareTarget 0x%x", entry_.address().value()); - if (!PrepareTarget(index, offset, buf_len, truncate)) - return net::ERR_FAILED; - - Trace("From PrepareTarget 0x%x", entry_.address().value()); - if (extending || truncate) - UpdateSize(index, entry_size, offset + buf_len); - - UpdateRank(true); - - backend_->OnEvent(Stats::WRITE_DATA); - backend_->OnWrite(buf_len); - - if (user_buffers_[index].get()) { - // Complete the operation locally. - user_buffers_[index]->Write(offset, buf, buf_len); - ReportIOTime(kWrite, start); - return buf_len; - } - - Addr address(entry_.Data()->data_addr[index]); - if (offset + buf_len == 0) { - if (truncate) { - DCHECK(!address.is_initialized()); - } - return 0; - } - - File* file = GetBackingFile(address, index); - if (!file) - return net::ERR_FAILED; - - size_t file_offset = offset; - if (address.is_block_file()) { - DCHECK_LE(offset + buf_len, kMaxBlockSize); - file_offset += address.start_block() * address.BlockSize() + - kBlockHeaderSize; - } else if (truncate || (extending && !buf_len)) { - if (!file->SetLength(offset + buf_len)) - return net::ERR_FAILED; - } - - if (!buf_len) - return 0; - - SyncCallback* io_callback = NULL; - if (!callback.is_null()) { - io_callback = new SyncCallback(this, buf, callback, - net::NetLog::TYPE_ENTRY_WRITE_DATA); - } - - TimeTicks start_async = TimeTicks::Now(); - - bool completed; - if (!file->Write(buf->data(), buf_len, file_offset, io_callback, - &completed)) { - if (io_callback) - io_callback->Discard(); - return net::ERR_FAILED; - } - - if (io_callback && completed) - io_callback->Discard(); - - if (io_callback) - ReportIOTime(kWriteAsync1, start_async); - - ReportIOTime(kWrite, start); - return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING; -} - // ------------------------------------------------------------------------ bool EntryImpl::CreateDataBlock(int index, int size) { diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h index 6ff7152..62ec9d7 100644 --- a/net/disk_cache/entry_impl.h +++ b/net/disk_cache/entry_impl.h @@ -41,12 +41,8 @@ class NET_EXPORT_PRIVATE EntryImpl void DoomImpl(); int ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback); - int ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback); int WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate); - int WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback, bool truncate); int ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback); int WriteSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, @@ -153,15 +149,9 @@ class NET_EXPORT_PRIVATE EntryImpl virtual int ReadData( int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; - virtual int ReadData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback) OVERRIDE; virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback, bool truncate) OVERRIDE; - virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback, - bool truncate) OVERRIDE; virtual int ReadSparseData( int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; @@ -187,12 +177,8 @@ class NET_EXPORT_PRIVATE EntryImpl // separate functions to make logging of results simpler. int InternalReadData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback); - int InternalReadData(int index, int offset, net::IOBuffer* buf, - int buf_len, const net::CompletionCallback& callback); int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate); - int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback, bool truncate); // Initializes the storage for an internal or external data block. bool CreateDataBlock(int index, int size); diff --git a/net/disk_cache/in_flight_backend_io.cc b/net/disk_cache/in_flight_backend_io.cc index 25d39a5..b99d627 100644 --- a/net/disk_cache/in_flight_backend_io.cc +++ b/net/disk_cache/in_flight_backend_io.cc @@ -16,21 +16,7 @@ namespace disk_cache { BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, net::OldCompletionCallback* callback) - : BackgroundIO(controller), - backend_(backend), - old_callback_(callback), - operation_(OP_NONE), - ALLOW_THIS_IN_INITIALIZER_LIST( - my_callback_(this, &BackendIO::OnIOComplete)) { - start_time_ = base::TimeTicks::Now(); -} - -BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, - const net::CompletionCallback& callback) - : BackgroundIO(controller), - backend_(backend), - old_callback_(NULL), - callback_(callback), + : BackgroundIO(controller), backend_(backend), callback_(callback), operation_(OP_NONE), ALLOW_THIS_IN_INITIALIZER_LIST( my_callback_(this, &BackendIO::OnIOComplete)) { @@ -327,13 +313,6 @@ void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, PostOperation(operation); } -void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); - operation->OpenEntry(key, entry); - PostOperation(operation); -} - void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) { scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); @@ -341,13 +320,6 @@ void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, PostOperation(operation); } -void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); - operation->CreateEntry(key, entry); - PostOperation(operation); -} - void InFlightBackendIO::DoomEntry(const std::string& key, OldCompletionCallback* callback) { scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); @@ -361,13 +333,6 @@ void InFlightBackendIO::DoomAllEntries(OldCompletionCallback* callback) { PostOperation(operation); } -void InFlightBackendIO::DoomAllEntries( - const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); - operation->DoomAllEntries(); - PostOperation(operation); -} - void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, OldCompletionCallback* callback) { @@ -376,14 +341,6 @@ void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, PostOperation(operation); } -void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); - operation->DoomEntriesBetween(initial_time, end_time); - PostOperation(operation); -} - void InFlightBackendIO::DoomEntriesSince(const base::Time initial_time, OldCompletionCallback* callback) { scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); @@ -398,13 +355,6 @@ void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, PostOperation(operation); } -void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, - const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); - operation->OpenNextEntry(iter, next_entry); - PostOperation(operation); -} - void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry, OldCompletionCallback* callback) { scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); @@ -456,14 +406,6 @@ void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, PostOperation(operation); } -void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, - net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); - operation->ReadData(entry, index, offset, buf, buf_len); - PostOperation(operation); -} - void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, int buf_len, bool truncate, @@ -473,15 +415,6 @@ void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, PostOperation(operation); } -void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, - net::IOBuffer* buf, int buf_len, - bool truncate, - const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); - operation->WriteData(entry, index, offset, buf, buf_len, truncate); - PostOperation(operation); -} - void InFlightBackendIO::ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback) { @@ -531,10 +464,8 @@ void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); } - if (op->old_callback() && (!cancel || op->IsEntryOperation())) - op->old_callback()->Run(op->result()); - else if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) - op->callback().Run(op->result()); + if (op->callback() && (!cancel || op->IsEntryOperation())) + op->callback()->Run(op->result()); } void InFlightBackendIO::PostOperation(BackendIO* operation) { diff --git a/net/disk_cache/in_flight_backend_io.h b/net/disk_cache/in_flight_backend_io.h index 3d66cdc..17efb1a 100644 --- a/net/disk_cache/in_flight_backend_io.h +++ b/net/disk_cache/in_flight_backend_io.h @@ -27,8 +27,6 @@ class BackendIO : public BackgroundIO { public: BackendIO(InFlightIO* controller, BackendImpl* backend, net::OldCompletionCallback* callback); - BackendIO(InFlightIO* controller, BackendImpl* backend, - const net::CompletionCallback& callback); // Runs the actual operation on the background thread. void ExecuteOperation(); @@ -39,8 +37,7 @@ class BackendIO : public BackgroundIO { // Returns true if this operation is directed to an entry (vs. the backend). bool IsEntryOperation(); - net::OldCompletionCallback* old_callback() const { return old_callback_; } - net::CompletionCallback callback() const { return callback_; } + net::OldCompletionCallback* callback() { return callback_; } // Grabs an extra reference of entry_. void ReferenceEntry(); @@ -116,8 +113,7 @@ class BackendIO : public BackgroundIO { void ExecuteEntryOperation(); BackendImpl* backend_; - net::OldCompletionCallback* old_callback_; - net::CompletionCallback callback_; + net::OldCompletionCallback* callback_; Operation operation_; net::OldCompletionCallbackImpl<BackendIO> my_callback_; @@ -153,27 +149,17 @@ class InFlightBackendIO : public InFlightIO { void Init(net::OldCompletionCallback* callback); void OpenEntry(const std::string& key, Entry** entry, net::OldCompletionCallback* callback); - void OpenEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback); void CreateEntry(const std::string& key, Entry** entry, net::OldCompletionCallback* callback); - void CreateEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback); void DoomEntry(const std::string& key, net::OldCompletionCallback* callback); void DoomAllEntries(net::OldCompletionCallback* callback); - void DoomAllEntries(const net::CompletionCallback& callback); void DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, net::OldCompletionCallback* callback); - void DoomEntriesBetween(const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback); void DoomEntriesSince(const base::Time initial_time, net::OldCompletionCallback* callback); void OpenNextEntry(void** iter, Entry** next_entry, net::OldCompletionCallback* callback); - void OpenNextEntry(void** iter, Entry** next_entry, - const net::CompletionCallback& callback); void OpenPrevEntry(void** iter, Entry** prev_entry, net::OldCompletionCallback* callback); void EndEnumeration(void* iterator); @@ -184,14 +170,8 @@ class InFlightBackendIO : public InFlightIO { void RunTask(Task* task, net::OldCompletionCallback* callback); void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback); - void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, - int buf_len, const net::CompletionCallback& callback); - void WriteData(EntryImpl* entry, int index, int offset, - net::IOBuffer* buf, int buf_len, bool truncate, - net::OldCompletionCallback* callback); - void WriteData(EntryImpl* entry, int index, int offset, - net::IOBuffer* buf, int buf_len, bool truncate, - const net::CompletionCallback& callback); + void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, + int buf_len, bool truncate, net::OldCompletionCallback* callback); void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback); void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc index 8cdf0ac..f08b316 100644 --- a/net/disk_cache/mem_backend_impl.cc +++ b/net/disk_cache/mem_backend_impl.cc @@ -136,14 +136,6 @@ int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry, return net::ERR_FAILED; } -int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) { - if (OpenEntry(key, entry)) - return net::OK; - - return net::ERR_FAILED; -} - int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) { if (CreateEntry(key, entry)) @@ -152,14 +144,6 @@ int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry, return net::ERR_FAILED; } -int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) { - if (CreateEntry(key, entry)) - return net::OK; - - return net::ERR_FAILED; -} - int MemBackendImpl::DoomEntry(const std::string& key, OldCompletionCallback* callback) { if (DoomEntry(key)) @@ -175,13 +159,6 @@ int MemBackendImpl::DoomAllEntries(OldCompletionCallback* callback) { return net::ERR_FAILED; } -int MemBackendImpl::DoomAllEntries(const net::CompletionCallback& callback) { - if (DoomAllEntries()) - return net::OK; - - return net::ERR_FAILED; -} - int MemBackendImpl::DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, OldCompletionCallback* callback) { @@ -191,15 +168,6 @@ int MemBackendImpl::DoomEntriesBetween(const base::Time initial_time, return net::ERR_FAILED; } -int MemBackendImpl::DoomEntriesBetween( - const base::Time initial_time, const base::Time end_time, - const net::CompletionCallback& callback) { - if (DoomEntriesBetween(initial_time, end_time)) - return net::OK; - - return net::ERR_FAILED; -} - int MemBackendImpl::DoomEntriesSince(const base::Time initial_time, OldCompletionCallback* callback) { if (DoomEntriesSince(initial_time)) @@ -216,14 +184,6 @@ int MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry, return net::ERR_FAILED; } -int MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry, - const net::CompletionCallback& callback) { - if (OpenNextEntry(iter, next_entry)) - return net::OK; - - return net::ERR_FAILED; -} - void MemBackendImpl::EndEnumeration(void** iter) { *iter = NULL; } diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h index 85b0144..abf1443 100644 --- a/net/disk_cache/mem_backend_impl.h +++ b/net/disk_cache/mem_backend_impl.h @@ -66,29 +66,18 @@ class NET_EXPORT_PRIVATE MemBackendImpl : public Backend { virtual int32 GetEntryCount() const OVERRIDE; virtual int OpenEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; - virtual int OpenEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) OVERRIDE; virtual int CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; - virtual int CreateEntry(const std::string& key, Entry** entry, - const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntry(const std::string& key, OldCompletionCallback* callback) OVERRIDE; virtual int DoomAllEntries(OldCompletionCallback* callback) OVERRIDE; - virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, OldCompletionCallback* callback) OVERRIDE; - virtual int DoomEntriesBetween( - const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntriesSince(const base::Time initial_time, OldCompletionCallback* callback) OVERRIDE; virtual int OpenNextEntry(void** iter, Entry** next_entry, OldCompletionCallback* callback) OVERRIDE; - virtual int OpenNextEntry(void** iter, Entry** next_entry, - const net::CompletionCallback& callback) OVERRIDE; virtual void EndEnumeration(void** iter) OVERRIDE; virtual void GetStats( std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE {} diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc index 4874761..677cd6a 100644 --- a/net/disk_cache/mem_entry_impl.cc +++ b/net/disk_cache/mem_entry_impl.cc @@ -185,26 +185,6 @@ int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, return result; } -int MemEntryImpl::ReadData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback) { - if (net_log_.IsLoggingAllEvents()) { - net_log_.BeginEvent( - net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, false))); - } - - int result = InternalReadData(index, offset, buf, buf_len); - - if (net_log_.IsLoggingAllEvents()) { - net_log_.EndEvent( - net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); - } - return result; -} - int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback, bool truncate) { if (net_log_.IsLoggingAllEvents()) { @@ -224,26 +204,6 @@ int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, return result; } -int MemEntryImpl::WriteData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback, bool truncate) { - if (net_log_.IsLoggingAllEvents()) { - net_log_.BeginEvent( - net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, truncate))); - } - - int result = InternalWriteData(index, offset, buf, buf_len, truncate); - - if (net_log_.IsLoggingAllEvents()) { - net_log_.EndEvent( - net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); - } - return result; -} - int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) { if (net_log_.IsLoggingAllEvents()) { diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h index 2967154..b1d4703 100644 --- a/net/disk_cache/mem_entry_impl.h +++ b/net/disk_cache/mem_entry_impl.h @@ -101,15 +101,9 @@ class MemEntryImpl : public Entry { virtual int ReadData( int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; - virtual int ReadData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback) OVERRIDE; virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback, bool truncate) OVERRIDE; - virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& completion_callback, - bool truncate) OVERRIDE; virtual int ReadSparseData( int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; diff --git a/net/http/disk_cache_based_ssl_host_info.cc b/net/http/disk_cache_based_ssl_host_info.cc index 985a261..003618e 100644 --- a/net/http/disk_cache_based_ssl_host_info.cc +++ b/net/http/disk_cache_based_ssl_host_info.cc @@ -40,8 +40,8 @@ DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo( HttpCache* http_cache) : SSLHostInfo(hostname, ssl_config, cert_verifier), weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), - callback_(base::Bind(&DiskCacheBasedSSLHostInfo::OnIOComplete, - weak_ptr_factory_.GetWeakPtr())), + callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(), + &DiskCacheBasedSSLHostInfo::OnIOComplete)), state_(GET_BACKEND), ready_(false), found_entry_(false), @@ -93,6 +93,8 @@ DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() { DCHECK(user_callback_.is_null()); if (entry_) entry_->Close(); + if (!IsCallbackPending()) + delete callback_; } std::string DiskCacheBasedSSLHostInfo::key() const { @@ -158,6 +160,7 @@ int DiskCacheBasedSSLHostInfo::DoLoop(int rv) { int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { if (rv == OK) { + backend_ = callback_->backend(); state_ = OPEN; } else { state_ = WAIT_FOR_DATA_READY_DONE; @@ -167,6 +170,7 @@ int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) { if (rv == OK) { + entry_ = callback_->entry(); state_ = READ; found_entry_ = true; } else { @@ -190,22 +194,23 @@ int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) { } int DiskCacheBasedSSLHostInfo::DoCreateOrOpenComplete(int rv) { - if (rv != OK) + if (rv != OK) { state_ = SET_DONE; - else + } else { + entry_ = callback_->entry(); state_ = WRITE; - + } return OK; } int DiskCacheBasedSSLHostInfo::DoGetBackend() { state_ = GET_BACKEND_COMPLETE; - return http_cache_->GetBackend(&backend_, callback_); + return http_cache_->GetBackend(callback_->backend_pointer(), callback_); } int DiskCacheBasedSSLHostInfo::DoOpen() { state_ = OPEN_COMPLETE; - return backend_->OpenEntry(key(), &entry_, callback_); + return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_); } int DiskCacheBasedSSLHostInfo::DoRead() { @@ -227,17 +232,16 @@ int DiskCacheBasedSSLHostInfo::DoWrite() { state_ = WRITE_COMPLETE; return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_, - new_data_.size(), callback_, - true /* truncate */); + new_data_.size(), callback_, true /* truncate */); } int DiskCacheBasedSSLHostInfo::DoCreateOrOpen() { DCHECK(entry_ == NULL); state_ = CREATE_OR_OPEN_COMPLETE; if (found_entry_) - return backend_->OpenEntry(key(), &entry_, callback_); + return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_); - return backend_->CreateEntry(key(), &entry_, callback_); + return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_); } int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() { diff --git a/net/http/disk_cache_based_ssl_host_info.h b/net/http/disk_cache_based_ssl_host_info.h index 48651ed..2339ae9 100644 --- a/net/http/disk_cache_based_ssl_host_info.h +++ b/net/http/disk_cache_based_ssl_host_info.h @@ -106,7 +106,7 @@ class NET_EXPORT_PRIVATE DiskCacheBasedSSLHostInfo bool IsCallbackPending() const; base::WeakPtrFactory<DiskCacheBasedSSLHostInfo> weak_ptr_factory_; - CompletionCallback callback_; + CallbackImpl* callback_; State state_; bool ready_; bool found_entry_; // Controls the behavior of DoCreateOrOpen. diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index e968526..58fa5cb 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -23,7 +23,6 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/stringprintf.h" -#include "net/base/completion_callback.h" #include "net/base/io_buffer.h" #include "net/base/load_flags.h" #include "net/base/net_errors.h" @@ -144,16 +143,11 @@ enum WorkItemOperation { class HttpCache::WorkItem { public: WorkItem(WorkItemOperation operation, Transaction* trans, ActiveEntry** entry) - : operation_(operation), - trans_(trans), - entry_(entry), + : operation_(operation), trans_(trans), entry_(entry), callback_(NULL), backend_(NULL) {} WorkItem(WorkItemOperation operation, Transaction* trans, - const CompletionCallback& cb, disk_cache::Backend** backend) - : operation_(operation), - trans_(trans), - entry_(NULL), - callback_(cb), + OldCompletionCallback* cb, disk_cache::Backend** backend) + : operation_(operation), trans_(trans), entry_(NULL), callback_(cb), backend_(backend) {} ~WorkItem() {} @@ -171,31 +165,25 @@ class HttpCache::WorkItem { bool DoCallback(int result, disk_cache::Backend* backend) { if (backend_) *backend_ = backend; - if (!callback_.is_null()) { - callback_.Run(result); + if (callback_) { + callback_->Run(result); return true; } return false; } - void ClearCallback() { - callback_.Reset(); - } - - bool IsValid() const { - return trans_ || entry_ || !callback_.is_null(); - } - WorkItemOperation operation() { return operation_; } void ClearTransaction() { trans_ = NULL; } void ClearEntry() { entry_ = NULL; } + void ClearCallback() { callback_ = NULL; } bool Matches(Transaction* trans) const { return trans == trans_; } + bool IsValid() const { return trans_ || entry_ || callback_; } private: WorkItemOperation operation_; Transaction* trans_; ActiveEntry** entry_; - CompletionCallback callback_; + OldCompletionCallback* callback_; // User callback. disk_cache::Backend** backend_; }; @@ -434,8 +422,8 @@ HttpCache::~HttpCache() { } int HttpCache::GetBackend(disk_cache::Backend** backend, - const CompletionCallback& callback) { - DCHECK(!callback.is_null()); + OldCompletionCallback* callback) { + DCHECK(callback != NULL); if (disk_cache_.get()) { *backend = disk_cache_.get(); @@ -464,10 +452,8 @@ void HttpCache::WriteMetadata(const GURL& url, return; // Do lazy initialization of disk cache if needed. - if (!disk_cache_.get()) { - // We don't care about the result. - CreateBackend(NULL, CompletionCallback()); - } + if (!disk_cache_.get()) + CreateBackend(NULL, NULL); // We don't care about the result. HttpCache::Transaction* trans = new HttpCache::Transaction(this); MetadataWriter* writer = new MetadataWriter(trans); @@ -506,10 +492,8 @@ void HttpCache::OnExternalCacheHit(const GURL& url, int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) { // Do lazy initialization of disk cache if needed. - if (!disk_cache_.get()) { - // We don't care about the result. - CreateBackend(NULL, CompletionCallback()); - } + if (!disk_cache_.get()) + CreateBackend(NULL, NULL); // We don't care about the result. trans->reset(new HttpCache::Transaction(this)); return OK; @@ -528,7 +512,7 @@ HttpNetworkSession* HttpCache::GetSession() { //----------------------------------------------------------------------------- int HttpCache::CreateBackend(disk_cache::Backend** backend, - const CompletionCallback& callback) { + OldCompletionCallback* callback) { if (!backend_factory_.get()) return ERR_FAILED; @@ -541,7 +525,7 @@ int HttpCache::CreateBackend(disk_cache::Backend** backend, // entry, so we use an empty key for it. PendingOp* pending_op = GetPendingOp(""); if (pending_op->writer) { - if (!callback.is_null()) + if (callback) pending_op->pending_queue.push_back(item.release()); return ERR_IO_PENDING; } @@ -569,8 +553,7 @@ int HttpCache::GetBackendForTransaction(Transaction* trans) { if (!building_backend_) return ERR_FAILED; - WorkItem* item = new WorkItem(WI_CREATE_BACKEND, trans, - CompletionCallback(), NULL); + WorkItem* item = new WorkItem(WI_CREATE_BACKEND, trans, NULL, NULL); PendingOp* pending_op = GetPendingOp(""); DCHECK(pending_op->writer); pending_op->pending_queue.push_back(item); diff --git a/net/http/http_cache.h b/net/http/http_cache.h index 176d9ff..526da58 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -157,8 +157,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, // a network error code, and it could be ERR_IO_PENDING, in which case the // |callback| will be notified when the operation completes. The pointer that // receives the |backend| must remain valid until the operation completes. - int GetBackend(disk_cache::Backend** backend, - const CompletionCallback& callback); + int GetBackend(disk_cache::Backend** backend, OldCompletionCallback* callback); // Returns the current backend (can be NULL). disk_cache::Backend* GetCurrentBackend() const; @@ -191,7 +190,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, // referred to by |url| and |http_method|. void OnExternalCacheHit(const GURL& url, const std::string& http_method); - // HttpTransactionFactory implementation. + // HttpTransactionFactory implementation: virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans) OVERRIDE; virtual HttpCache* GetCache() OVERRIDE; virtual HttpNetworkSession* GetSession() OVERRIDE; @@ -244,7 +243,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, // Creates the |backend| object and notifies the |callback| when the operation // completes. Returns an error code. int CreateBackend(disk_cache::Backend** backend, - const CompletionCallback& callback); + OldCompletionCallback* callback); // Makes sure that the backend creation is complete before allowing the // provided transaction to use the object. Returns an error code. |trans| diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index 93f7476..0c0ff6f 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -11,7 +11,6 @@ #include "base/stringprintf.h" #include "net/base/cache_type.h" #include "net/base/cert_status_flags.h" -#include "net/base/completion_callback.h" #include "net/base/host_port_pair.h" #include "net/base/load_flags.h" #include "net/base/net_errors.h" @@ -33,27 +32,18 @@ using base::Time; namespace { -class DeleteCacheCompletionCallback : public TestCompletionCallbackBase { +class DeleteCacheOldCompletionCallback : public TestOldCompletionCallback { public: - explicit DeleteCacheCompletionCallback(MockHttpCache* cache) - : cache_(cache), - ALLOW_THIS_IN_INITIALIZER_LIST(callback_( - base::Bind(&DeleteCacheCompletionCallback::OnComplete, - base::Unretained(this)))) { - } - - const net::CompletionCallback& callback() const { return callback_; } + explicit DeleteCacheOldCompletionCallback(MockHttpCache* cache) + : cache_(cache) {} - private: - void OnComplete(int result) { + virtual void RunWithParams(const Tuple1<int>& params) { delete cache_; - SetResult(result); + TestOldCompletionCallback::RunWithParams(params); } + private: MockHttpCache* cache_; - const net::CompletionCallback callback_; - - DISALLOW_COPY_AND_ASSIGN(DeleteCacheCompletionCallback); }; //----------------------------------------------------------------------------- @@ -405,9 +395,9 @@ TEST(HttpCache, GetBackend) { MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0)); disk_cache::Backend* backend; - net::TestCompletionCallback cb; + TestOldCompletionCallback cb; // This will lazily initialize the backend. - int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); + int rv = cache.http_cache()->GetBackend(&backend, &cb); EXPECT_EQ(net::OK, cb.GetResult(rv)); } @@ -1475,9 +1465,9 @@ TEST(HttpCache, DeleteCacheWaitingForBackend2) { MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); MockHttpCache* cache = new MockHttpCache(factory); - DeleteCacheCompletionCallback cb(cache); + DeleteCacheOldCompletionCallback cb(cache); disk_cache::Backend* backend; - int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); + int rv = cache->http_cache()->GetBackend(&backend, &cb); EXPECT_EQ(net::ERR_IO_PENDING, rv); // Now let's queue a regular transaction @@ -1490,8 +1480,8 @@ TEST(HttpCache, DeleteCacheWaitingForBackend2) { c->trans->Start(&request, &c->callback, net::BoundNetLog()); // And another direct backend request. - net::TestCompletionCallback cb2; - rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); + TestOldCompletionCallback cb2; + rv = cache->http_cache()->GetBackend(&backend, &cb2); EXPECT_EQ(net::ERR_IO_PENDING, rv); // Just to make sure that everything is still pending. diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc index 4ff840d..98efd70 100644 --- a/net/http/mock_http_cache.cc +++ b/net/http/mock_http_cache.cc @@ -11,26 +11,6 @@ namespace { -class OldCallbackRunner : public Task { - public: - OldCallbackRunner(net::OldCompletionCallback* callback, int result) - : callback_(callback), result_(result) {} - virtual void Run() { - callback_->Run(result_); - } - - private: - net::OldCompletionCallback* callback_; - int result_; - - DISALLOW_COPY_AND_ASSIGN(OldCallbackRunner); -}; - -void CompletionCallbackRunner( - const net::CompletionCallback& callback, int result) { - callback.Run(result); -} - int GetTestModeForEntry(const std::string& key) { // 'key' is prefixed with an identifier if it corresponds to a cached POST. // Skip past that to locate the actual URL. @@ -61,8 +41,7 @@ int g_test_mode = 0; struct MockDiskEntry::CallbackInfo { scoped_refptr<MockDiskEntry> entry; - net::OldCompletionCallback* old_callback; - net::CompletionCallback callback; + net::OldCompletionCallback* callback; int result; }; @@ -127,30 +106,6 @@ int MockDiskEntry::ReadData(int index, int offset, net::IOBuffer* buf, return net::ERR_IO_PENDING; } -int MockDiskEntry::ReadData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) { - DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); - DCHECK(!callback.is_null()); - - if (fail_requests_) - return net::ERR_CACHE_READ_FAILURE; - - if (offset < 0 || offset > static_cast<int>(data_[index].size())) - return net::ERR_FAILED; - if (static_cast<size_t>(offset) == data_[index].size()) - return 0; - - int num = std::min(buf_len, static_cast<int>(data_[index].size()) - offset); - memcpy(buf->data(), &data_[index][offset], num); - - if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ) - return num; - - CallbackLater(callback, num); - return net::ERR_IO_PENDING; -} - int MockDiskEntry::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback, bool truncate) { @@ -177,32 +132,6 @@ int MockDiskEntry::WriteData(int index, int offset, net::IOBuffer* buf, return net::ERR_IO_PENDING; } -int MockDiskEntry::WriteData( - int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback, bool truncate) { - DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); - DCHECK(truncate); - DCHECK(!callback.is_null()); - - if (fail_requests_) { - CallbackLater(callback, net::ERR_CACHE_READ_FAILURE); - return net::ERR_IO_PENDING; - } - - if (offset < 0 || offset > static_cast<int>(data_[index].size())) - return net::ERR_FAILED; - - data_[index].resize(offset + buf_len); - if (buf_len) - memcpy(&data_[index][offset], buf->data(), buf_len); - - if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE) - return buf_len; - - CallbackLater(callback, buf_len); - return net::ERR_IO_PENDING; -} - int MockDiskEntry::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) { DCHECK(callback); @@ -335,7 +264,7 @@ void MockDiskEntry::IgnoreCallbacks(bool value) { return; ignore_callbacks_ = value; if (!value) - StoreAndDeliverCallbacks(false, NULL, NULL, net::CompletionCallback(), 0); + StoreAndDeliverCallbacks(false, NULL, NULL, 0); } MockDiskEntry::~MockDiskEntry() { @@ -346,29 +275,13 @@ MockDiskEntry::~MockDiskEntry() { // leveraging the fact that this class is reference counted. void MockDiskEntry::CallbackLater(net::OldCompletionCallback* callback, int result) { - if (ignore_callbacks_) { - StoreAndDeliverCallbacks(true, this, callback, - net::CompletionCallback(), result); - return; - } - - MessageLoop::current()->PostTask(FROM_HERE, base::Bind( - &MockDiskEntry::RunOldCallback, this, callback, result)); -} - -void MockDiskEntry::CallbackLater(const net::CompletionCallback& callback, - int result) { - if (ignore_callbacks_) { - StoreAndDeliverCallbacks(true, this, NULL, callback, result); - return; - } - + if (ignore_callbacks_) + return StoreAndDeliverCallbacks(true, this, callback, result); MessageLoop::current()->PostTask(FROM_HERE, base::Bind( &MockDiskEntry::RunCallback, this, callback, result)); } -void MockDiskEntry::RunOldCallback( - net::OldCompletionCallback* callback, int result) { +void MockDiskEntry::RunCallback(net::OldCompletionCallback* callback, int result) { if (busy_) { // This is kind of hacky, but controlling the behavior of just this entry // from a test is sort of complicated. What we really want to do is @@ -377,7 +290,7 @@ void MockDiskEntry::RunOldCallback( // this operation (already posted to the message loop)... and without // just delaying for n mS (which may cause trouble with slow bots). So // we re-post this operation (all async sparse IO operations will take two - // trips through the message loop instead of one). + // trips trhough the message loop instead of one). if (!delayed_) { delayed_ = true; return CallbackLater(callback, result); @@ -387,44 +300,20 @@ void MockDiskEntry::RunOldCallback( callback->Run(result); } -void MockDiskEntry::RunCallback( - const net::CompletionCallback& callback, int result) { - if (busy_) { - // This is kind of hacky, but controlling the behavior of just this entry - // from a test is sort of complicated. What we really want to do is - // delay the delivery of a sparse IO operation a little more so that the - // request start operation (async) will finish without seeing the end of - // this operation (already posted to the message loop)... and without - // just delaying for n mS (which may cause trouble with slow bots). So - // we re-post this operation (all async sparse IO operations will take two - // trips through the message loop instead of one). - if (!delayed_) { - delayed_ = true; - return CallbackLater(callback, result); - } - } - busy_ = false; - callback.Run(result); -} - // When |store| is true, stores the callback to be delivered later; otherwise // delivers any callback previously stored. // Static. -void MockDiskEntry::StoreAndDeliverCallbacks( - bool store, MockDiskEntry* entry, - net::OldCompletionCallback* old_callback, - const net::CompletionCallback& callback, int result) { +void MockDiskEntry::StoreAndDeliverCallbacks(bool store, MockDiskEntry* entry, + net::OldCompletionCallback* callback, + int result) { static std::vector<CallbackInfo> callback_list; if (store) { - CallbackInfo c = {entry, old_callback, callback, result}; + CallbackInfo c = {entry, callback, result}; callback_list.push_back(c); } else { - for (size_t i = 0; i < callback_list.size(); ++i) { + for (size_t i = 0; i < callback_list.size(); i++) { CallbackInfo& c = callback_list[i]; - if (c.old_callback) - c.entry->CallbackLater(c.old_callback, c.result); - else - c.entry->CallbackLater(c.callback, c.result); + c.entry->CallbackLater(c.callback, c.result); } callback_list.clear(); } @@ -436,6 +325,20 @@ bool MockDiskEntry::ignore_callbacks_ = false; //----------------------------------------------------------------------------- +class MockDiskCache::CallbackRunner : public Task { + public: + CallbackRunner(net::OldCompletionCallback* callback, int result) + : callback_(callback), result_(result) {} + virtual void Run() { + callback_->Run(result_); + } + + private: + net::OldCompletionCallback* callback_; + int result_; + DISALLOW_COPY_AND_ASSIGN(CallbackRunner); +}; + MockDiskCache::MockDiskCache() : open_count_(0), create_count_(0), fail_requests_(false), soft_failures_(false), double_create_check_(true) { @@ -480,38 +383,6 @@ int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry, return net::ERR_IO_PENDING; } -int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry, - const net::CompletionCallback& callback) { - DCHECK(!callback.is_null()); - - if (fail_requests_) - return net::ERR_CACHE_OPEN_FAILURE; - - EntryMap::iterator it = entries_.find(key); - if (it == entries_.end()) - return net::ERR_CACHE_OPEN_FAILURE; - - if (it->second->is_doomed()) { - it->second->Release(); - entries_.erase(it); - return net::ERR_CACHE_OPEN_FAILURE; - } - - open_count_++; - - it->second->AddRef(); - *entry = it->second; - - if (soft_failures_) - it->second->set_fail_requests(); - - if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START) - return net::OK; - - CallbackLater(callback, net::OK); - return net::ERR_IO_PENDING; -} - int MockDiskCache::CreateEntry(const std::string& key, disk_cache::Entry** entry, net::OldCompletionCallback* callback) { @@ -551,46 +422,6 @@ int MockDiskCache::CreateEntry(const std::string& key, return net::ERR_IO_PENDING; } -int MockDiskCache::CreateEntry(const std::string& key, - disk_cache::Entry** entry, - const net::CompletionCallback& callback) { - DCHECK(!callback.is_null()); - - if (fail_requests_) - return net::ERR_CACHE_CREATE_FAILURE; - - EntryMap::iterator it = entries_.find(key); - if (it != entries_.end()) { - if (!it->second->is_doomed()) { - if (double_create_check_) - NOTREACHED(); - else - return net::ERR_CACHE_CREATE_FAILURE; - } - it->second->Release(); - entries_.erase(it); - } - - create_count_++; - - MockDiskEntry* new_entry = new MockDiskEntry(key); - - new_entry->AddRef(); - entries_[key] = new_entry; - - new_entry->AddRef(); - *entry = new_entry; - - if (soft_failures_) - new_entry->set_fail_requests(); - - if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START) - return net::OK; - - CallbackLater(callback, net::OK); - return net::ERR_IO_PENDING; -} - int MockDiskCache::DoomEntry(const std::string& key, net::OldCompletionCallback* callback) { DCHECK(callback); @@ -611,22 +442,12 @@ int MockDiskCache::DoomAllEntries(net::OldCompletionCallback* callback) { return net::ERR_NOT_IMPLEMENTED; } -int MockDiskCache::DoomAllEntries(const net::CompletionCallback& callback) { - return net::ERR_NOT_IMPLEMENTED; -} - int MockDiskCache::DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, net::OldCompletionCallback* callback) { return net::ERR_NOT_IMPLEMENTED; } -int MockDiskCache::DoomEntriesBetween(const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback) { - return net::ERR_NOT_IMPLEMENTED; -} - int MockDiskCache::DoomEntriesSince(const base::Time initial_time, net::OldCompletionCallback* callback) { return net::ERR_NOT_IMPLEMENTED; @@ -637,11 +458,6 @@ int MockDiskCache::OpenNextEntry(void** iter, disk_cache::Entry** next_entry, return net::ERR_NOT_IMPLEMENTED; } -int MockDiskCache::OpenNextEntry(void** iter, disk_cache::Entry** next_entry, - const net::CompletionCallback& callback) { - return net::ERR_NOT_IMPLEMENTED; -} - void MockDiskCache::EndEnumeration(void** iter) { } @@ -662,13 +478,7 @@ void MockDiskCache::ReleaseAll() { void MockDiskCache::CallbackLater(net::OldCompletionCallback* callback, int result) { MessageLoop::current()->PostTask(FROM_HERE, - new OldCallbackRunner(callback, result)); -} - -void MockDiskCache::CallbackLater(const net::CompletionCallback& callback, - int result) { - MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&CompletionCallbackRunner, callback, result)); + new CallbackRunner(callback, result)); } //----------------------------------------------------------------------------- @@ -691,9 +501,9 @@ MockHttpCache::MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory) } MockDiskCache* MockHttpCache::disk_cache() { - net::TestCompletionCallback cb; + TestOldCompletionCallback cb; disk_cache::Backend* backend; - int rv = http_cache_.GetBackend(&backend, cb.callback()); + int rv = http_cache_.GetBackend(&backend, &cb); rv = cb.GetResult(rv); return (rv == net::OK) ? static_cast<MockDiskCache*>(backend) : NULL; } diff --git a/net/http/mock_http_cache.h b/net/http/mock_http_cache.h index d2c8853..975058f 100644 --- a/net/http/mock_http_cache.h +++ b/net/http/mock_http_cache.h @@ -35,14 +35,9 @@ class MockDiskEntry : public disk_cache::Entry, virtual int32 GetDataSize(int index) const OVERRIDE; virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) OVERRIDE; - virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) OVERRIDE; virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback, bool truncate) OVERRIDE; - virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback, - bool truncate) OVERRIDE; virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) OVERRIDE; virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, @@ -72,16 +67,13 @@ class MockDiskEntry : public disk_cache::Entry, // if the consumer called Close on the MockDiskEntry. We achieve that by // leveraging the fact that this class is reference counted. void CallbackLater(net::OldCompletionCallback* callback, int result); - void CallbackLater(const net::CompletionCallback& callback, int result); - void RunOldCallback(net::OldCompletionCallback* callback, int result); - void RunCallback(const net::CompletionCallback& callback, int result); + void RunCallback(net::OldCompletionCallback* callback, int result); // When |store| is true, stores the callback to be delivered later; otherwise // delivers any callback previously stored. static void StoreAndDeliverCallbacks(bool store, MockDiskEntry* entry, - net::OldCompletionCallback* old_callback, - const net::CompletionCallback& callback, + net::OldCompletionCallback* callback, int result); static const int kNumCacheEntryDataIndices = 3; @@ -106,29 +98,18 @@ class MockDiskCache : public disk_cache::Backend { virtual int32 GetEntryCount() const OVERRIDE; virtual int OpenEntry(const std::string& key, disk_cache::Entry** entry, net::OldCompletionCallback* callback) OVERRIDE; - virtual int OpenEntry(const std::string& key, disk_cache::Entry** entry, - const net::CompletionCallback& callback) OVERRIDE; virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, net::OldCompletionCallback* callback) OVERRIDE; - virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, - const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntry(const std::string& key, net::OldCompletionCallback* callback) OVERRIDE; virtual int DoomAllEntries(net::OldCompletionCallback* callback) OVERRIDE; - virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, net::OldCompletionCallback* callback) OVERRIDE; - virtual int DoomEntriesBetween( - const base::Time initial_time, - const base::Time end_time, - const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntriesSince(const base::Time initial_time, net::OldCompletionCallback* callback) OVERRIDE; virtual int OpenNextEntry(void** iter, disk_cache::Entry** next_entry, net::OldCompletionCallback* callback) OVERRIDE; - virtual int OpenNextEntry(void** iter, disk_cache::Entry** next_entry, - const net::CompletionCallback& callback) OVERRIDE; virtual void EndEnumeration(void** iter) OVERRIDE; virtual void GetStats( std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; @@ -153,9 +134,9 @@ class MockDiskCache : public disk_cache::Backend { private: typedef base::hash_map<std::string, MockDiskEntry*> EntryMap; + class CallbackRunner; void CallbackLater(net::OldCompletionCallback* callback, int result); - void CallbackLater(const net::CompletionCallback& callback, int result); EntryMap entries_; int open_count_; diff --git a/net/url_request/view_cache_helper.cc b/net/url_request/view_cache_helper.cc index 6810245..e0f6456 100644 --- a/net/url_request/view_cache_helper.cc +++ b/net/url_request/view_cache_helper.cc @@ -4,8 +4,6 @@ #include "net/url_request/view_cache_helper.h" -#include "base/bind.h" -#include "base/bind_helpers.h" #include "base/stringprintf.h" #include "net/base/escape.h" #include "net/base/io_buffer.h" @@ -48,10 +46,8 @@ ViewCacheHelper::ViewCacheHelper() index_(0), data_(NULL), next_state_(STATE_NONE), - ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( - base::Bind(&ViewCacheHelper::OnIOComplete, base::Unretained(this)))), ALLOW_THIS_IN_INITIALIZER_LIST( - old_cache_callback_(this, &ViewCacheHelper::OnIOComplete)), + cache_callback_(this, &ViewCacheHelper::OnIOComplete)), ALLOW_THIS_IN_INITIALIZER_LIST( entry_callback_(new CancelableOldCompletionCallback<ViewCacheHelper>( this, &ViewCacheHelper::OnIOComplete))) { @@ -223,7 +219,7 @@ int ViewCacheHelper::DoGetBackend() { if (!http_cache) return ERR_FAILED; - return http_cache->GetBackend(&disk_cache_, cache_callback_); + return http_cache->GetBackend(&disk_cache_, &cache_callback_); } int ViewCacheHelper::DoGetBackendComplete(int result) { @@ -246,7 +242,7 @@ int ViewCacheHelper::DoGetBackendComplete(int result) { int ViewCacheHelper::DoOpenNextEntry() { next_state_ = STATE_OPEN_NEXT_ENTRY_COMPLETE; - return disk_cache_->OpenNextEntry(&iter_, &entry_, &old_cache_callback_); + return disk_cache_->OpenNextEntry(&iter_, &entry_, &cache_callback_); } int ViewCacheHelper::DoOpenNextEntryComplete(int result) { @@ -266,7 +262,7 @@ int ViewCacheHelper::DoOpenNextEntryComplete(int result) { int ViewCacheHelper::DoOpenEntry() { next_state_ = STATE_OPEN_ENTRY_COMPLETE; - return disk_cache_->OpenEntry(key_, &entry_, &old_cache_callback_); + return disk_cache_->OpenEntry(key_, &entry_, &cache_callback_); } int ViewCacheHelper::DoOpenEntryComplete(int result) { diff --git a/net/url_request/view_cache_helper.h b/net/url_request/view_cache_helper.h index c31d0fc..f6f7cc4 100644 --- a/net/url_request/view_cache_helper.h +++ b/net/url_request/view_cache_helper.h @@ -114,8 +114,7 @@ class NET_EXPORT ViewCacheHelper { State next_state_; - CompletionCallback cache_callback_; - OldCompletionCallbackImpl<ViewCacheHelper> old_cache_callback_; + OldCompletionCallbackImpl<ViewCacheHelper> cache_callback_; scoped_refptr<CancelableOldCompletionCallback<ViewCacheHelper> > entry_callback_; DISALLOW_COPY_AND_ASSIGN(ViewCacheHelper); diff --git a/net/url_request/view_cache_helper_unittest.cc b/net/url_request/view_cache_helper_unittest.cc index e911fcc..17bad61 100644 --- a/net/url_request/view_cache_helper_unittest.cc +++ b/net/url_request/view_cache_helper_unittest.cc @@ -5,7 +5,6 @@ #include "net/url_request/view_cache_helper.h" #include "base/pickle.h" -#include "net/base/completion_callback.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/disk_cache/disk_cache.h" @@ -86,10 +85,10 @@ void WriteToEntry(disk_cache::Backend* cache, const std::string key, } void FillCache(URLRequestContext* context) { - TestCompletionCallback cb; + TestOldCompletionCallback cb; disk_cache::Backend* cache; - int rv = context->http_transaction_factory()->GetCache()->GetBackend( - &cache, cb.callback()); + int rv = + context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb); ASSERT_EQ(OK, cb.GetResult(rv)); std::string empty; @@ -181,16 +180,15 @@ TEST(ViewCacheHelper, TruncatedFlag) { scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); ViewCacheHelper helper; - TestCompletionCallback cb; + TestOldCompletionCallback cb; disk_cache::Backend* cache; - int rv = context->http_transaction_factory()->GetCache()->GetBackend( - &cache, cb.callback()); + int rv = + context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb); ASSERT_EQ(OK, cb.GetResult(rv)); std::string key("the key"); disk_cache::Entry* entry; - TestOldCompletionCallback cb2; - rv = cache->CreateEntry(key, &entry, &cb2); + rv = cache->CreateEntry(key, &entry, &cb); ASSERT_EQ(OK, cb.GetResult(rv)); // RESPONSE_INFO_TRUNCATED defined on response_info.cc |