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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/http/disk_cache_based_ssl_host_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H 5 #ifndef NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H
6 #define NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H 6 #define NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/lock.h" 10 #include "base/lock.h"
11 #include "base/non_thread_safe.h" 11 #include "base/non_thread_safe.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/weak_ptr.h"
13 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
14 #include "net/disk_cache/disk_cache.h" 15 #include "net/disk_cache/disk_cache.h"
15 #include "net/socket/ssl_host_info.h" 16 #include "net/socket/ssl_host_info.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 class HttpCache; 20 class HttpCache;
20 class IOBuffer; 21 class IOBuffer;
21 struct SSLConfig; 22 struct SSLConfig;
22 23
23 // DiskCacheBasedSSLHostInfo fetches information about an SSL host from our 24 // DiskCacheBasedSSLHostInfo fetches information about an SSL host from our
24 // standard disk cache. Since the information is defined to be non-sensitive, 25 // standard disk cache. Since the information is defined to be non-sensitive,
25 // it's ok for us to keep it on disk. 26 // it's ok for us to keep it on disk.
26 class DiskCacheBasedSSLHostInfo : public SSLHostInfo, 27 class DiskCacheBasedSSLHostInfo : public SSLHostInfo,
27 public NonThreadSafe { 28 public NonThreadSafe {
28 public: 29 public:
29 DiskCacheBasedSSLHostInfo(const std::string& hostname, 30 DiskCacheBasedSSLHostInfo(const std::string& hostname,
30 const SSLConfig& ssl_config, 31 const SSLConfig& ssl_config,
31 HttpCache* http_cache); 32 HttpCache* http_cache);
32 33
33 // Implementation of SSLHostInfo 34 // Implementation of SSLHostInfo
34 virtual void Start(); 35 virtual void Start();
35 virtual int WaitForDataReady(CompletionCallback* callback); 36 virtual int WaitForDataReady(CompletionCallback* callback);
36 virtual void Persist(); 37 virtual void Persist();
37 38
38 private: 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,
54 };
55
39 ~DiskCacheBasedSSLHostInfo(); 56 ~DiskCacheBasedSSLHostInfo();
57
58 class CallbackImpl : public CallbackRunner<Tuple1<int> > {
59 public:
60 CallbackImpl(const base::WeakPtr<DiskCacheBasedSSLHostInfo>& obj,
61 void (DiskCacheBasedSSLHostInfo::*meth) (int))
62 : obj_(obj),
63 meth_(meth) {
64 }
65
66 virtual void RunWithParams(const Tuple1<int>& params) {
67 if (!obj_) {
68 delete this;
69 } else {
70 DispatchToMethod(obj_.get(), meth_, params);
71 }
72 }
73
74 disk_cache::Backend** backend_pointer() { return &backend_; }
75 disk_cache::Entry** entry_pointer() { return &entry_; }
76 disk_cache::Backend* backend() const { return backend_; }
77 disk_cache::Entry* entry() const { return entry_; }
78
79 protected:
willchan no longer on Chromium 2010/12/16 00:12:27 private
80 base::WeakPtr<DiskCacheBasedSSLHostInfo> obj_;
81 void (DiskCacheBasedSSLHostInfo::*meth_) (int);
82
83 disk_cache::Backend* backend_;
84 disk_cache::Entry* entry_;
85 };
86
40 std::string key() const; 87 std::string key() const;
41 88
42 void DoLoop(int rv); 89 void DoLoop(int rv);
43 90
44 int DoGetBackendComplete(int rv); 91 int DoGetBackendComplete(int rv);
45 int DoOpenComplete(int rv); 92 int DoOpenComplete(int rv);
46 int DoReadComplete(int rv); 93 int DoReadComplete(int rv);
47 int DoWriteComplete(int rv); 94 int DoWriteComplete(int rv);
48 int DoCreateComplete(int rv); 95 int DoCreateComplete(int rv);
49 96
50 int DoGetBackend(); 97 int DoGetBackend();
51 int DoOpen(); 98 int DoOpen();
52 int DoRead(); 99 int DoRead();
53 int DoCreate(); 100 int DoCreate();
54 int DoWrite(); 101 int DoWrite();
55 102
56 // WaitForDataReadyDone is the terminal state of the read operation. 103 // WaitForDataReadyDone is the terminal state of the read operation.
57 int WaitForDataReadyDone(); 104 int WaitForDataReadyDone();
58 // SetDone is the terminal state of the write operation. 105 // SetDone is the terminal state of the write operation.
59 int SetDone(); 106 int SetDone();
60 107
61 enum State { 108 // IsCallbackPending returns true if we have a pending callback.
62 GET_BACKEND, 109 bool IsCallbackPending() const;
63 GET_BACKEND_COMPLETE,
64 OPEN,
65 OPEN_COMPLETE,
66 READ,
67 READ_COMPLETE,
68 WAIT_FOR_DATA_READY_DONE,
69 CREATE,
70 CREATE_COMPLETE,
71 WRITE,
72 WRITE_COMPLETE,
73 SET_DONE,
74 NONE,
75 };
76 110
77 scoped_refptr<CancelableCompletionCallback<DiskCacheBasedSSLHostInfo> > 111 base::WeakPtrFactory<DiskCacheBasedSSLHostInfo> weak_ptr_factory_;
78 callback_; 112 CallbackImpl* callback_;
79 State state_; 113 State state_;
80 bool ready_; 114 bool ready_;
81 std::string new_data_; 115 std::string new_data_;
82 const std::string hostname_; 116 const std::string hostname_;
83 HttpCache* const http_cache_; 117 HttpCache* const http_cache_;
84 disk_cache::Backend* backend_; 118 disk_cache::Backend* backend_;
85 disk_cache::Entry *entry_; 119 disk_cache::Entry* entry_;
86 CompletionCallback* user_callback_; 120 CompletionCallback* user_callback_;
87 scoped_refptr<net::IOBuffer> read_buffer_; 121 scoped_refptr<net::IOBuffer> read_buffer_;
88 scoped_refptr<net::IOBuffer> write_buffer_; 122 scoped_refptr<net::IOBuffer> write_buffer_;
89 std::string data_; 123 std::string data_;
90 }; 124 };
91 125
92 } // namespace net 126 } // namespace net
93 127
94 #endif // NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H 128 #endif // NET_HTTP_DISK_CACHE_BASED_SSL_HOST_INFO_H
OLDNEW
« no previous file with comments | « no previous file | net/http/disk_cache_based_ssl_host_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698