OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" | 5 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Fetch the certs. This must be called in the IO thread. | 31 // Fetch the certs. This must be called in the IO thread. |
32 void FetchOnIOThread(); | 32 void FetchOnIOThread(); |
33 | 33 |
34 // Notifies the completion callback. This must be called in the UI thread. | 34 // Notifies the completion callback. This must be called in the UI thread. |
35 void NotifyInUIThread(); | 35 void NotifyInUIThread(); |
36 | 36 |
37 // Delete a single cert. This must be called in IO thread. | 37 // Delete a single cert. This must be called in IO thread. |
38 void DeleteOnIOThread(const std::string& server_id); | 38 void DeleteOnIOThread(const std::string& server_id); |
39 | 39 |
| 40 // Access to |server_bound_cert_list_| is triggered indirectly via the UI |
| 41 // thread and guarded by |is_fetching_|. This means |server_bound_cert_list_| |
| 42 // is only accessed while |is_fetching_| is true. The flag |is_fetching_| is |
| 43 // only accessed on the UI thread. |
40 net::ServerBoundCertStore::ServerBoundCertList server_bound_cert_list_; | 44 net::ServerBoundCertStore::ServerBoundCertList server_bound_cert_list_; |
41 | 45 |
42 // Indicates whether or not we're currently fetching information: | 46 // Indicates whether or not we're currently fetching information: |
43 // it's true when StartFetching() is called in the UI thread, and it's reset | 47 // it's true when StartFetching() is called in the UI thread, and it's reset |
44 // after we notify the callback in the UI thread. | 48 // after we notify the callback in the UI thread. |
45 // This only mutates on the UI thread. | 49 // This only mutates on the UI thread. |
46 bool is_fetching_; | 50 bool is_fetching_; |
47 | 51 |
48 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 52 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
49 | 53 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 143 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
140 CannedBrowsingDataServerBoundCertHelper* clone = | 144 CannedBrowsingDataServerBoundCertHelper* clone = |
141 new CannedBrowsingDataServerBoundCertHelper(); | 145 new CannedBrowsingDataServerBoundCertHelper(); |
142 | 146 |
143 clone->server_bound_cert_map_ = server_bound_cert_map_; | 147 clone->server_bound_cert_map_ = server_bound_cert_map_; |
144 return clone; | 148 return clone; |
145 } | 149 } |
146 | 150 |
147 void CannedBrowsingDataServerBoundCertHelper::AddServerBoundCert( | 151 void CannedBrowsingDataServerBoundCertHelper::AddServerBoundCert( |
148 const net::ServerBoundCertStore::ServerBoundCert& server_bound_cert) { | 152 const net::ServerBoundCertStore::ServerBoundCert& server_bound_cert) { |
| 153 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
149 server_bound_cert_map_[server_bound_cert.server_identifier()] = | 154 server_bound_cert_map_[server_bound_cert.server_identifier()] = |
150 server_bound_cert; | 155 server_bound_cert; |
151 } | 156 } |
152 | 157 |
153 void CannedBrowsingDataServerBoundCertHelper::Reset() { | 158 void CannedBrowsingDataServerBoundCertHelper::Reset() { |
154 server_bound_cert_map_.clear(); | 159 server_bound_cert_map_.clear(); |
155 } | 160 } |
156 | 161 |
157 bool CannedBrowsingDataServerBoundCertHelper::empty() const { | 162 bool CannedBrowsingDataServerBoundCertHelper::empty() const { |
158 return server_bound_cert_map_.empty(); | 163 return server_bound_cert_map_.empty(); |
159 } | 164 } |
160 | 165 |
161 size_t CannedBrowsingDataServerBoundCertHelper::GetCertCount() const { | 166 size_t CannedBrowsingDataServerBoundCertHelper::GetCertCount() const { |
| 167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
162 return server_bound_cert_map_.size(); | 168 return server_bound_cert_map_.size(); |
163 } | 169 } |
164 | 170 |
165 void CannedBrowsingDataServerBoundCertHelper::StartFetching( | 171 void CannedBrowsingDataServerBoundCertHelper::StartFetching( |
166 const FetchResultCallback& callback) { | 172 const FetchResultCallback& callback) { |
167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 173 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
168 if (callback.is_null()) | 174 if (callback.is_null()) |
169 return; | 175 return; |
170 // We post a task to emulate async fetching behavior. | 176 // We post a task to emulate async fetching behavior. |
171 completion_callback_ = callback; | 177 completion_callback_ = callback; |
172 MessageLoop::current()->PostTask( | 178 MessageLoop::current()->PostTask( |
173 FROM_HERE, | 179 FROM_HERE, |
174 base::Bind(&CannedBrowsingDataServerBoundCertHelper::FinishFetching, | 180 base::Bind(&CannedBrowsingDataServerBoundCertHelper::FinishFetching, |
175 this)); | 181 this)); |
176 } | 182 } |
177 | 183 |
178 void CannedBrowsingDataServerBoundCertHelper::FinishFetching() { | 184 void CannedBrowsingDataServerBoundCertHelper::FinishFetching() { |
179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 185 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
180 net::ServerBoundCertStore::ServerBoundCertList cert_list; | 186 net::ServerBoundCertStore::ServerBoundCertList cert_list; |
181 for (ServerBoundCertMap::iterator i = server_bound_cert_map_.begin(); | 187 for (ServerBoundCertMap::iterator i = server_bound_cert_map_.begin(); |
182 i != server_bound_cert_map_.end(); ++i) | 188 i != server_bound_cert_map_.end(); ++i) |
183 cert_list.push_back(i->second); | 189 cert_list.push_back(i->second); |
184 completion_callback_.Run(cert_list); | 190 completion_callback_.Run(cert_list); |
185 } | 191 } |
186 | 192 |
187 void CannedBrowsingDataServerBoundCertHelper::DeleteServerBoundCert( | 193 void CannedBrowsingDataServerBoundCertHelper::DeleteServerBoundCert( |
188 const std::string& server_id) { | 194 const std::string& server_id) { |
189 NOTREACHED(); | 195 NOTREACHED(); |
190 } | 196 } |
OLD | NEW |