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

Side by Side Diff: content/browser/media/webrtc_identity_store.cc

Issue 1000373002: favor DCHECK_CURRENTLY_ON for better logs in content/browser/[f-p]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 5 years, 9 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/media/webrtc_identity_store.h" 5 #include "content/browser/media/webrtc_identity_store.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 class WebRTCIdentityRequest { 76 class WebRTCIdentityRequest {
77 public: 77 public:
78 WebRTCIdentityRequest(const GURL& origin, 78 WebRTCIdentityRequest(const GURL& origin,
79 const std::string& identity_name, 79 const std::string& identity_name,
80 const std::string& common_name) 80 const std::string& common_name)
81 : origin_(origin), 81 : origin_(origin),
82 identity_name_(identity_name), 82 identity_name_(identity_name),
83 common_name_(common_name) {} 83 common_name_(common_name) {}
84 84
85 void Cancel(WebRTCIdentityRequestHandle* handle) { 85 void Cancel(WebRTCIdentityRequestHandle* handle) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 86 DCHECK_CURRENTLY_ON(BrowserThread::IO);
87 if (callbacks_.find(handle) == callbacks_.end()) 87 if (callbacks_.find(handle) == callbacks_.end())
88 return; 88 return;
89 callbacks_.erase(handle); 89 callbacks_.erase(handle);
90 } 90 }
91 91
92 private: 92 private:
93 friend class WebRTCIdentityStore; 93 friend class WebRTCIdentityStore;
94 94
95 void AddCallback(WebRTCIdentityRequestHandle* handle, 95 void AddCallback(WebRTCIdentityRequestHandle* handle,
96 const WebRTCIdentityStore::CompletionCallback& callback) { 96 const WebRTCIdentityStore::CompletionCallback& callback) {
97 DCHECK(callbacks_.find(handle) == callbacks_.end()); 97 DCHECK(callbacks_.find(handle) == callbacks_.end());
98 callbacks_[handle] = callback; 98 callbacks_[handle] = callback;
99 } 99 }
100 100
101 // This method deletes "this" and no one should access it after the request 101 // This method deletes "this" and no one should access it after the request
102 // completes. 102 // completes.
103 // We do not use base::Owned to tie its lifetime to the callback for 103 // We do not use base::Owned to tie its lifetime to the callback for
104 // WebRTCIdentityStoreBackend::FindIdentity, because it needs to live longer 104 // WebRTCIdentityStoreBackend::FindIdentity, because it needs to live longer
105 // than that if the identity does not exist in DB. 105 // than that if the identity does not exist in DB.
106 void Post(const WebRTCIdentityRequestResult& result) { 106 void Post(const WebRTCIdentityRequestResult& result) {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 107 DCHECK_CURRENTLY_ON(BrowserThread::IO);
108 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); 108 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end();
109 ++it) 109 ++it)
110 it->second.Run(result.error, result.certificate, result.private_key); 110 it->second.Run(result.error, result.certificate, result.private_key);
111 delete this; 111 delete this;
112 } 112 }
113 113
114 GURL origin_; 114 GURL origin_;
115 std::string identity_name_; 115 std::string identity_name_;
116 std::string common_name_; 116 std::string common_name_;
117 typedef std::map<WebRTCIdentityRequestHandle*, 117 typedef std::map<WebRTCIdentityRequestHandle*,
(...skipping 11 matching lines...) Expand all
129 WebRTCIdentityStore* store, 129 WebRTCIdentityStore* store,
130 const WebRTCIdentityStore::CompletionCallback& callback) 130 const WebRTCIdentityStore::CompletionCallback& callback)
131 : store_(store), request_(NULL), callback_(callback) {} 131 : store_(store), request_(NULL), callback_(callback) {}
132 132
133 private: 133 private:
134 friend class WebRTCIdentityStore; 134 friend class WebRTCIdentityStore;
135 135
136 // Cancel the request. Does nothing if the request finished or was already 136 // Cancel the request. Does nothing if the request finished or was already
137 // cancelled. 137 // cancelled.
138 void Cancel() { 138 void Cancel() {
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 139 DCHECK_CURRENTLY_ON(BrowserThread::IO);
140 if (!request_) 140 if (!request_)
141 return; 141 return;
142 142
143 callback_.Reset(); 143 callback_.Reset();
144 WebRTCIdentityRequest* request = request_; 144 WebRTCIdentityRequest* request = request_;
145 request_ = NULL; 145 request_ = NULL;
146 // "this" will be deleted after the following call, because "this" is 146 // "this" will be deleted after the following call, because "this" is
147 // owned by the Callback held by |request|. 147 // owned by the Callback held by |request|.
148 request->Cancel(this); 148 request->Cancel(this);
149 } 149 }
150 150
151 void OnRequestStarted(WebRTCIdentityRequest* request) { 151 void OnRequestStarted(WebRTCIdentityRequest* request) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 152 DCHECK_CURRENTLY_ON(BrowserThread::IO);
153 DCHECK(request); 153 DCHECK(request);
154 request_ = request; 154 request_ = request;
155 } 155 }
156 156
157 void OnRequestComplete(int error, 157 void OnRequestComplete(int error,
158 const std::string& certificate, 158 const std::string& certificate,
159 const std::string& private_key) { 159 const std::string& private_key) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 160 DCHECK_CURRENTLY_ON(BrowserThread::IO);
161 DCHECK(request_); 161 DCHECK(request_);
162 request_ = NULL; 162 request_ = NULL;
163 base::ResetAndReturn(&callback_).Run(error, certificate, private_key); 163 base::ResetAndReturn(&callback_).Run(error, certificate, private_key);
164 } 164 }
165 165
166 WebRTCIdentityStore* store_; 166 WebRTCIdentityStore* store_;
167 WebRTCIdentityRequest* request_; 167 WebRTCIdentityRequest* request_;
168 WebRTCIdentityStore::CompletionCallback callback_; 168 WebRTCIdentityStore::CompletionCallback callback_;
169 169
170 DISALLOW_COPY_AND_ASSIGN(WebRTCIdentityRequestHandle); 170 DISALLOW_COPY_AND_ASSIGN(WebRTCIdentityRequestHandle);
171 }; 171 };
172 172
173 WebRTCIdentityStore::WebRTCIdentityStore(const base::FilePath& path, 173 WebRTCIdentityStore::WebRTCIdentityStore(const base::FilePath& path,
174 storage::SpecialStoragePolicy* policy) 174 storage::SpecialStoragePolicy* policy)
175 : validity_period_(base::TimeDelta::FromDays(30)), 175 : validity_period_(base::TimeDelta::FromDays(30)),
176 task_runner_(base::WorkerPool::GetTaskRunner(true)), 176 task_runner_(base::WorkerPool::GetTaskRunner(true)),
177 backend_(new WebRTCIdentityStoreBackend(path, policy, validity_period_)) { 177 backend_(new WebRTCIdentityStoreBackend(path, policy, validity_period_)) {
178 } 178 }
179 179
180 WebRTCIdentityStore::~WebRTCIdentityStore() { backend_->Close(); } 180 WebRTCIdentityStore::~WebRTCIdentityStore() { backend_->Close(); }
181 181
182 base::Closure WebRTCIdentityStore::RequestIdentity( 182 base::Closure WebRTCIdentityStore::RequestIdentity(
183 const GURL& origin, 183 const GURL& origin,
184 const std::string& identity_name, 184 const std::string& identity_name,
185 const std::string& common_name, 185 const std::string& common_name,
186 const CompletionCallback& callback) { 186 const CompletionCallback& callback) {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 187 DCHECK_CURRENTLY_ON(BrowserThread::IO);
188 WebRTCIdentityRequest* request = 188 WebRTCIdentityRequest* request =
189 FindRequest(origin, identity_name, common_name); 189 FindRequest(origin, identity_name, common_name);
190 // If there is no identical request in flight, create a new one, queue it, 190 // If there is no identical request in flight, create a new one, queue it,
191 // and make the backend request. 191 // and make the backend request.
192 if (!request) { 192 if (!request) {
193 request = new WebRTCIdentityRequest(origin, identity_name, common_name); 193 request = new WebRTCIdentityRequest(origin, identity_name, common_name);
194 // |request| will delete itself after the result is posted. 194 // |request| will delete itself after the result is posted.
195 if (!backend_->FindIdentity( 195 if (!backend_->FindIdentity(
196 origin, 196 origin,
197 identity_name, 197 identity_name,
(...skipping 15 matching lines...) Expand all
213 base::Bind(&WebRTCIdentityRequestHandle::OnRequestComplete, 213 base::Bind(&WebRTCIdentityRequestHandle::OnRequestComplete,
214 base::Owned(handle))); 214 base::Owned(handle)));
215 handle->OnRequestStarted(request); 215 handle->OnRequestStarted(request);
216 return base::Bind(&WebRTCIdentityRequestHandle::Cancel, 216 return base::Bind(&WebRTCIdentityRequestHandle::Cancel,
217 base::Unretained(handle)); 217 base::Unretained(handle));
218 } 218 }
219 219
220 void WebRTCIdentityStore::DeleteBetween(base::Time delete_begin, 220 void WebRTCIdentityStore::DeleteBetween(base::Time delete_begin,
221 base::Time delete_end, 221 base::Time delete_end,
222 const base::Closure& callback) { 222 const base::Closure& callback) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 223 DCHECK_CURRENTLY_ON(BrowserThread::IO);
224 backend_->DeleteBetween(delete_begin, delete_end, callback); 224 backend_->DeleteBetween(delete_begin, delete_end, callback);
225 } 225 }
226 226
227 void WebRTCIdentityStore::SetValidityPeriodForTesting( 227 void WebRTCIdentityStore::SetValidityPeriodForTesting(
228 base::TimeDelta validity_period) { 228 base::TimeDelta validity_period) {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 229 DCHECK_CURRENTLY_ON(BrowserThread::IO);
230 validity_period_ = validity_period; 230 validity_period_ = validity_period;
231 backend_->SetValidityPeriodForTesting(validity_period); 231 backend_->SetValidityPeriodForTesting(validity_period);
232 } 232 }
233 233
234 void WebRTCIdentityStore::SetTaskRunnerForTesting( 234 void WebRTCIdentityStore::SetTaskRunnerForTesting(
235 const scoped_refptr<base::TaskRunner>& task_runner) { 235 const scoped_refptr<base::TaskRunner>& task_runner) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 236 DCHECK_CURRENTLY_ON(BrowserThread::IO);
237 task_runner_ = task_runner; 237 task_runner_ = task_runner;
238 } 238 }
239 239
240 void WebRTCIdentityStore::BackendFindCallback(WebRTCIdentityRequest* request, 240 void WebRTCIdentityStore::BackendFindCallback(WebRTCIdentityRequest* request,
241 int error, 241 int error,
242 const std::string& certificate, 242 const std::string& certificate,
243 const std::string& private_key) { 243 const std::string& private_key) {
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 244 DCHECK_CURRENTLY_ON(BrowserThread::IO);
245 if (error == net::OK) { 245 if (error == net::OK) {
246 DVLOG(2) << "Identity found in DB."; 246 DVLOG(2) << "Identity found in DB.";
247 WebRTCIdentityRequestResult result(error, certificate, private_key); 247 WebRTCIdentityRequestResult result(error, certificate, private_key);
248 PostRequestResult(request, result); 248 PostRequestResult(request, result);
249 return; 249 return;
250 } 250 }
251 // Generate a new identity if not found in the DB. 251 // Generate a new identity if not found in the DB.
252 WebRTCIdentityRequestResult* result = 252 WebRTCIdentityRequestResult* result =
253 new WebRTCIdentityRequestResult(0, "", ""); 253 new WebRTCIdentityRequestResult(0, "", "");
254 if (!task_runner_->PostTaskAndReply( 254 if (!task_runner_->PostTaskAndReply(
255 FROM_HERE, 255 FROM_HERE,
256 base::Bind(&GenerateIdentityWorker, 256 base::Bind(&GenerateIdentityWorker,
257 request->common_name_, 257 request->common_name_,
258 validity_period_, 258 validity_period_,
259 result), 259 result),
260 base::Bind(&WebRTCIdentityStore::GenerateIdentityCallback, 260 base::Bind(&WebRTCIdentityStore::GenerateIdentityCallback,
261 this, 261 this,
262 request, 262 request,
263 base::Owned(result)))) { 263 base::Owned(result)))) {
264 // Completes the request with error if failed to post the task. 264 // Completes the request with error if failed to post the task.
265 WebRTCIdentityRequestResult result(net::ERR_UNEXPECTED, "", ""); 265 WebRTCIdentityRequestResult result(net::ERR_UNEXPECTED, "", "");
266 PostRequestResult(request, result); 266 PostRequestResult(request, result);
267 } 267 }
268 } 268 }
269 269
270 void WebRTCIdentityStore::GenerateIdentityCallback( 270 void WebRTCIdentityStore::GenerateIdentityCallback(
271 WebRTCIdentityRequest* request, 271 WebRTCIdentityRequest* request,
272 WebRTCIdentityRequestResult* result) { 272 WebRTCIdentityRequestResult* result) {
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 273 DCHECK_CURRENTLY_ON(BrowserThread::IO);
274 if (result->error == net::OK) { 274 if (result->error == net::OK) {
275 DVLOG(2) << "New identity generated and added to the backend."; 275 DVLOG(2) << "New identity generated and added to the backend.";
276 backend_->AddIdentity(request->origin_, 276 backend_->AddIdentity(request->origin_,
277 request->identity_name_, 277 request->identity_name_,
278 request->common_name_, 278 request->common_name_,
279 result->certificate, 279 result->certificate,
280 result->private_key); 280 result->private_key);
281 } 281 }
282 PostRequestResult(request, *result); 282 PostRequestResult(request, *result);
283 } 283 }
284 284
285 void WebRTCIdentityStore::PostRequestResult( 285 void WebRTCIdentityStore::PostRequestResult(
286 WebRTCIdentityRequest* request, 286 WebRTCIdentityRequest* request,
287 const WebRTCIdentityRequestResult& result) { 287 const WebRTCIdentityRequestResult& result) {
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 288 DCHECK_CURRENTLY_ON(BrowserThread::IO);
289 // Removes the in flight request from the queue. 289 // Removes the in flight request from the queue.
290 for (size_t i = 0; i < in_flight_requests_.size(); ++i) { 290 for (size_t i = 0; i < in_flight_requests_.size(); ++i) {
291 if (in_flight_requests_[i] == request) { 291 if (in_flight_requests_[i] == request) {
292 in_flight_requests_.erase(in_flight_requests_.begin() + i); 292 in_flight_requests_.erase(in_flight_requests_.begin() + i);
293 break; 293 break;
294 } 294 }
295 } 295 }
296 // |request| will be deleted after this call. 296 // |request| will be deleted after this call.
297 request->Post(result); 297 request->Post(result);
298 } 298 }
299 299
300 // Find an identical request from the in flight requests. 300 // Find an identical request from the in flight requests.
301 WebRTCIdentityRequest* WebRTCIdentityStore::FindRequest( 301 WebRTCIdentityRequest* WebRTCIdentityStore::FindRequest(
302 const GURL& origin, 302 const GURL& origin,
303 const std::string& identity_name, 303 const std::string& identity_name,
304 const std::string& common_name) { 304 const std::string& common_name) {
305 for (size_t i = 0; i < in_flight_requests_.size(); ++i) { 305 for (size_t i = 0; i < in_flight_requests_.size(); ++i) {
306 if (in_flight_requests_[i]->origin_ == origin && 306 if (in_flight_requests_[i]->origin_ == origin &&
307 in_flight_requests_[i]->identity_name_ == identity_name && 307 in_flight_requests_[i]->identity_name_ == identity_name &&
308 in_flight_requests_[i]->common_name_ == common_name) { 308 in_flight_requests_[i]->common_name_ == common_name) {
309 return in_flight_requests_[i]; 309 return in_flight_requests_[i];
310 } 310 }
311 } 311 }
312 return NULL; 312 return NULL;
313 } 313 }
314 314
315 } // namespace content 315 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/media_internals_proxy.cc ('k') | content/browser/media/webrtc_identity_store_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698