1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H_
6 #define NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "net/base/completion_callback.h"
14 #include "net/disk_cache/disk_cache.h"
15 #include "net/socket/ssl_host_info.h"
23 // DiskCacheBasedSSLHostInfo fetches information about an SSL host from our
24 // standard disk cache. Since the information is defined to be non-sensitive,
25 // it's ok for us to keep it on disk.
26 class DiskCacheBasedSSLHostInfo
: public SSLHostInfo
,
27 public base::NonThreadSafe
{
29 DiskCacheBasedSSLHostInfo(const std::string
& hostname
,
30 const SSLConfig
& ssl_config
,
31 CertVerifier
* cert_verifier
,
32 HttpCache
* http_cache
);
34 // Implementation of SSLHostInfo
36 virtual int WaitForDataReady(CompletionCallback
* callback
);
37 virtual void Persist();
47 WAIT_FOR_DATA_READY_DONE
,
56 class CallbackImpl
: public CallbackRunner
<Tuple1
<int> > {
58 CallbackImpl(const base::WeakPtr
<DiskCacheBasedSSLHostInfo
>& obj
,
59 void (DiskCacheBasedSSLHostInfo::*meth
)(int));
60 virtual ~CallbackImpl();
62 disk_cache::Backend
** backend_pointer() { return &backend_
; }
63 disk_cache::Entry
** entry_pointer() { return &entry_
; }
64 disk_cache::Backend
* backend() const { return backend_
; }
65 disk_cache::Entry
* entry() const { return entry_
; }
67 // CallbackRunner<Tuple1<int> >:
68 virtual void RunWithParams(const Tuple1
<int>& params
);
71 base::WeakPtr
<DiskCacheBasedSSLHostInfo
> obj_
;
72 void (DiskCacheBasedSSLHostInfo::*meth_
)(int);
74 disk_cache::Backend
* backend_
;
75 disk_cache::Entry
* entry_
;
78 virtual ~DiskCacheBasedSSLHostInfo();
80 std::string
key() const;
84 int DoGetBackendComplete(int rv
);
85 int DoOpenComplete(int rv
);
86 int DoReadComplete(int rv
);
87 int DoWriteComplete(int rv
);
88 int DoCreateComplete(int rv
);
96 // DoWaitForDataReadyDone is the terminal state of the read operation.
97 int DoWaitForDataReadyDone();
99 // DoSetDone is the terminal state of the write operation.
102 // IsCallbackPending returns true if we have a pending callback.
103 bool IsCallbackPending() const;
105 base::WeakPtrFactory
<DiskCacheBasedSSLHostInfo
> weak_ptr_factory_
;
106 CallbackImpl
* callback_
;
109 std::string new_data_
;
110 const std::string hostname_
;
111 HttpCache
* const http_cache_
;
112 disk_cache::Backend
* backend_
;
113 disk_cache::Entry
* entry_
;
114 CompletionCallback
* user_callback_
;
115 scoped_refptr
<net::IOBuffer
> read_buffer_
;
116 scoped_refptr
<net::IOBuffer
> write_buffer_
;
122 #endif // NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H_