Fix nits related to SSLHostInfo.
[chromium-blink-merge.git] / net / http / disk_cache_based_ssl_host_info.h
blobc28d403b45ef9390d888fb94dc3c033c35779a75
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_
8 #include <string>
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"
17 namespace net {
19 class HttpCache;
20 class IOBuffer;
21 struct SSLConfig;
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 {
28 public:
29 DiskCacheBasedSSLHostInfo(const std::string& hostname,
30 const SSLConfig& ssl_config,
31 CertVerifier* cert_verifier,
32 HttpCache* http_cache);
34 // Implementation of SSLHostInfo
35 virtual void Start();
36 virtual int WaitForDataReady(CompletionCallback* callback);
37 virtual void Persist();
39 private:
40 enum State {
41 GET_BACKEND,
42 GET_BACKEND_COMPLETE,
43 OPEN,
44 OPEN_COMPLETE,
45 READ,
46 READ_COMPLETE,
47 WAIT_FOR_DATA_READY_DONE,
48 CREATE,
49 CREATE_COMPLETE,
50 WRITE,
51 WRITE_COMPLETE,
52 SET_DONE,
53 NONE,
56 class CallbackImpl : public CallbackRunner<Tuple1<int> > {
57 public:
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);
70 private:
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;
82 void DoLoop(int rv);
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);
90 int DoGetBackend();
91 int DoOpen();
92 int DoRead();
93 int DoWrite();
94 int DoCreate();
96 // DoWaitForDataReadyDone is the terminal state of the read operation.
97 int DoWaitForDataReadyDone();
99 // DoSetDone is the terminal state of the write operation.
100 int DoSetDone();
102 // IsCallbackPending returns true if we have a pending callback.
103 bool IsCallbackPending() const;
105 base::WeakPtrFactory<DiskCacheBasedSSLHostInfo> weak_ptr_factory_;
106 CallbackImpl* callback_;
107 State state_;
108 bool ready_;
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_;
117 std::string data_;
120 } // namespace net
122 #endif // NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H_