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

Unified Diff: net/http/disk_cache_based_ssl_host_info.h

Issue 5826001: net: fix callbacks in DiskCacheBasedSSLHostInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/http/disk_cache_based_ssl_host_info.h
diff --git a/net/http/disk_cache_based_ssl_host_info.h b/net/http/disk_cache_based_ssl_host_info.h
index 1d53b909dffbc7ac822ea74b34bbc0cea20a87f1..b3c23bb13530197267ef735b5e1574554ad1ec27 100644
--- a/net/http/disk_cache_based_ssl_host_info.h
+++ b/net/http/disk_cache_based_ssl_host_info.h
@@ -10,6 +10,7 @@
#include "base/lock.h"
#include "base/non_thread_safe.h"
#include "base/scoped_ptr.h"
+#include "base/weak_ptr.h"
#include "net/base/completion_callback.h"
#include "net/disk_cache/disk_cache.h"
#include "net/socket/ssl_host_info.h"
@@ -58,6 +59,9 @@ class DiskCacheBasedSSLHostInfo : public SSLHostInfo,
// SetDone is the terminal state of the write operation.
int SetDone();
+ // IsCallbackPending returns true if we have a pending callback.
+ bool IsCallbackPending() const;
+
enum State {
GET_BACKEND,
GET_BACKEND_COMPLETE,
@@ -74,15 +78,38 @@ class DiskCacheBasedSSLHostInfo : public SSLHostInfo,
NONE,
};
- scoped_refptr<CancelableCompletionCallback<DiskCacheBasedSSLHostInfo> >
- callback_;
+ class CallbackImpl : public CallbackRunner<Tuple1<int> > {
willchan no longer on Chromium 2010/12/15 00:03:14 Nice solution! http://google-styleguide.googlecod
agl 2010/12/15 16:28:08 Done.
+ public:
+ CallbackImpl(const base::WeakPtr<DiskCacheBasedSSLHostInfo>& obj,
+ void (DiskCacheBasedSSLHostInfo::*meth) (int))
+ : obj_(obj),
+ meth_(meth) {
+ }
+
+ virtual void RunWithParams(const Tuple1<int>& params) {
+ if (!obj_) {
+ delete this;
+ } else {
+ DispatchToMethod(obj_.get(), meth_, params);
+ }
+ }
+
+ void* user_data;
willchan no longer on Chromium 2010/12/15 00:03:14 I see why you've done this, but this is also again
agl 2010/12/15 16:28:08 Rather than have the complexity of two callbacks (
+
+ protected:
+ base::WeakPtr<DiskCacheBasedSSLHostInfo> obj_;
+ void (DiskCacheBasedSSLHostInfo::*meth_) (int);
+ };
+
+ base::WeakPtrFactory<DiskCacheBasedSSLHostInfo> weak_ptr_factory_;
+ CallbackImpl* callback_;
State state_;
bool ready_;
std::string new_data_;
const std::string hostname_;
HttpCache* const http_cache_;
disk_cache::Backend* backend_;
rvargas (doing something else) 2010/12/15 02:00:16 Interesting. How do we make sure that this pointer
willchan no longer on Chromium 2010/12/15 02:14:25 The HttpCache hands out SSLHostInfos to the HttpNe
- disk_cache::Entry *entry_;
+ disk_cache::Entry* entry_;
CompletionCallback* user_callback_;
scoped_refptr<net::IOBuffer> read_buffer_;
scoped_refptr<net::IOBuffer> write_buffer_;
« no previous file with comments | « no previous file | net/http/disk_cache_based_ssl_host_info.cc » ('j') | net/http/disk_cache_based_ssl_host_info.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698