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

Side by Side Diff: chrome/browser/nacl_host/pnacl_host.cc

Issue 23458015: Handle cache-control:no-store header in PNaCl translation cache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 "chrome/browser/nacl_host/pnacl_host.h" 5 #include "chrome/browser/nacl_host/pnacl_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 LOG(ERROR) << "OnTempFileReturn: id not found"; 261 LOG(ERROR) << "OnTempFileReturn: id not found";
262 BrowserThread::PostBlockingPoolTask( 262 BrowserThread::PostBlockingPoolTask(
263 FROM_HERE, base::Bind(base::IgnoreResult(base::ClosePlatformFile), fd)); 263 FROM_HERE, base::Bind(base::IgnoreResult(base::ClosePlatformFile), fd));
264 return; 264 return;
265 } 265 }
266 if (fd == base::kInvalidPlatformFileValue) { 266 if (fd == base::kInvalidPlatformFileValue) {
267 // This translation will fail, but we need to retry any translation 267 // This translation will fail, but we need to retry any translation
268 // waiting for its result. 268 // waiting for its result.
269 LOG(ERROR) << "OnTempFileReturn: temp file creation failed"; 269 LOG(ERROR) << "OnTempFileReturn: temp file creation failed";
270 std::string key(entry->second.cache_key); 270 std::string key(entry->second.cache_key);
271 bool is_incognito = entry->second.is_incognito; 271 bool may_have_waiting_translations = !entry->second.is_incognito &&
272 !entry->second.cache_info.has_no_store_header;
jvoung (off chromium) 2013/08/30 22:19:09 Would it be useful to put these checks in a helper
Derek Schuff 2013/09/03 22:14:52 Done.
272 entry->second.callback.Run(fd, false); 273 entry->second.callback.Run(fd, false);
273 pending_translations_.erase(entry); 274 pending_translations_.erase(entry);
274 // No translations will be waiting for an incongnito translation 275 // No translations will be waiting for an incongnito translation
275 if (!is_incognito) 276 if (may_have_waiting_translations)
276 RequeryMatchingTranslations(key); 277 RequeryMatchingTranslations(key);
277 return; 278 return;
278 } 279 }
279 PendingTranslation* pt = &entry->second; 280 PendingTranslation* pt = &entry->second;
280 pt->got_nexe_fd = true; 281 pt->got_nexe_fd = true;
281 pt->nexe_fd = fd; 282 pt->nexe_fd = fd;
282 CheckCacheQueryReady(entry); 283 CheckCacheQueryReady(entry);
283 } 284 }
284 285
285 // Check whether both the cache query and the temp file have returned, and check 286 // Check whether both the cache query and the temp file have returned, and check
286 // whether we actually got a hit or not. 287 // whether we actually got a hit or not.
287 void PnaclHost::CheckCacheQueryReady( 288 void PnaclHost::CheckCacheQueryReady(
288 const PendingTranslationMap::iterator& entry) { 289 const PendingTranslationMap::iterator& entry) {
289 PendingTranslation* pt = &entry->second; 290 PendingTranslation* pt = &entry->second;
290 if (!(pt->got_cache_reply && pt->got_nexe_fd)) 291 if (!(pt->got_cache_reply && pt->got_nexe_fd))
291 return; 292 return;
292 if (!pt->got_cache_hit) { 293 if (!pt->got_cache_hit) {
293 // Check if there is already a pending translation for this file. If there 294 // Check if there is already a pending translation for this file. If there
294 // is, we will wait for it to come back, to avoid redundant translations. 295 // is, we will wait for it to come back, to avoid redundant translations.
295 for (PendingTranslationMap::iterator it = pending_translations_.begin(); 296 for (PendingTranslationMap::iterator it = pending_translations_.begin();
296 it != pending_translations_.end(); 297 it != pending_translations_.end();
297 ++it) { 298 ++it) {
298 // Another translation matches if it's a request for the same file, 299 // Another translation matches if it's a request for the same file,
299 if (it->second.cache_key == entry->second.cache_key && 300 if (it->second.cache_key == entry->second.cache_key &&
300 // and it's not this translation, 301 // and it's not this translation,
301 it->first != entry->first && 302 it->first != entry->first &&
302 // and it's not incognito, 303 // and it's not incognito,
303 !it->second.is_incognito && 304 !it->second.is_incognito &&
305 // and it doesn't have the no-store header
306 !it->second.cache_info.has_no_store_header &&
304 // and if it's already gotten past this check and returned the miss. 307 // and if it's already gotten past this check and returned the miss.
305 it->second.got_cache_reply && 308 it->second.got_cache_reply &&
306 it->second.got_nexe_fd) { 309 it->second.got_nexe_fd) {
307 return; 310 return;
308 } 311 }
309 } 312 }
310 ReturnMiss(entry); 313 ReturnMiss(entry);
311 return; 314 return;
312 } 315 }
313 316
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 << "," << pp_instance << " not found."; 380 << "," << pp_instance << " not found.";
378 return; 381 return;
379 } 382 }
380 bool store_nexe = true; 383 bool store_nexe = true;
381 // If this is a premature response (i.e. we haven't returned a temp file 384 // If this is a premature response (i.e. we haven't returned a temp file
382 // yet) or if it's an unsuccessful translation, or if we are incognito, 385 // yet) or if it's an unsuccessful translation, or if we are incognito,
383 // don't store in the cache. 386 // don't store in the cache.
384 // TODO(dschuff): use a separate in-memory cache for incognito 387 // TODO(dschuff): use a separate in-memory cache for incognito
385 // translations. 388 // translations.
386 if (!entry->second.got_nexe_fd || !entry->second.got_cache_reply || 389 if (!entry->second.got_nexe_fd || !entry->second.got_cache_reply ||
387 !success || entry->second.is_incognito) { 390 !success || entry->second.is_incognito ||
391 entry->second.cache_info.has_no_store_header) {
388 store_nexe = false; 392 store_nexe = false;
389 } else if (!base::PostTaskAndReplyWithResult( 393 } else if (!base::PostTaskAndReplyWithResult(
390 BrowserThread::GetBlockingPool(), 394 BrowserThread::GetBlockingPool(),
391 FROM_HERE, 395 FROM_HERE,
392 base::Bind(&PnaclHost::CopyFileToBuffer, 396 base::Bind(&PnaclHost::CopyFileToBuffer,
393 entry->second.nexe_fd), 397 entry->second.nexe_fd),
394 base::Bind(&PnaclHost::StoreTranslatedNexe, 398 base::Bind(&PnaclHost::StoreTranslatedNexe,
395 weak_factory_.GetWeakPtr(), 399 weak_factory_.GetWeakPtr(),
396 id))) { 400 id))) {
397 store_nexe = false; 401 store_nexe = false;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 for (PendingTranslationMap::iterator it = pending_translations_.begin(); 522 for (PendingTranslationMap::iterator it = pending_translations_.begin();
519 it != pending_translations_.end();) { 523 it != pending_translations_.end();) {
520 PendingTranslationMap::iterator to_erase(it++); 524 PendingTranslationMap::iterator to_erase(it++);
521 if (to_erase->first.first == render_process_id) { 525 if (to_erase->first.first == render_process_id) {
522 // Clean up the open files. 526 // Clean up the open files.
523 BrowserThread::PostBlockingPoolTask( 527 BrowserThread::PostBlockingPoolTask(
524 FROM_HERE, 528 FROM_HERE,
525 base::Bind(base::IgnoreResult(base::ClosePlatformFile), 529 base::Bind(base::IgnoreResult(base::ClosePlatformFile),
526 to_erase->second.nexe_fd)); 530 to_erase->second.nexe_fd));
527 std::string key(to_erase->second.cache_key); 531 std::string key(to_erase->second.cache_key);
528 bool is_incognito = to_erase->second.is_incognito; 532 bool may_have_waiting_translations = !to_erase->second.is_incognito &&
533 !to_erase->second.cache_info.has_no_store_header;
529 pending_translations_.erase(to_erase); 534 pending_translations_.erase(to_erase);
530 // No translations will be blocked waiting for an incongnito translation 535 // No translations will be blocked waiting for an incongnito translation
531 if (!is_incognito) 536 if (may_have_waiting_translations)
532 RequeryMatchingTranslations(key); 537 RequeryMatchingTranslations(key);
533 } 538 }
534 } 539 }
535 if (pending_translations_.empty()) { 540 if (pending_translations_.empty()) {
536 cache_state_ = CacheUninitialized; 541 cache_state_ = CacheUninitialized;
537 // Freeing the backend causes it to flush to disk, so do it when the 542 // Freeing the backend causes it to flush to disk, so do it when the
538 // last renderer closes rather than on destruction. 543 // last renderer closes rather than on destruction.
539 disk_cache_.reset(); 544 disk_cache_.reset();
540 } 545 }
541 } 546 }
(...skipping 26 matching lines...) Expand all
568 end_time, 573 end_time,
569 base::Bind(&PnaclHost::OnEntriesDoomed, callback)); 574 base::Bind(&PnaclHost::OnEntriesDoomed, callback));
570 if (rv != net::ERR_IO_PENDING) 575 if (rv != net::ERR_IO_PENDING)
571 OnEntriesDoomed(callback, rv); 576 OnEntriesDoomed(callback, rv);
572 } 577 }
573 578
574 // static 579 // static
575 void PnaclHost::OnEntriesDoomed(const base::Closure& callback, int net_error) { 580 void PnaclHost::OnEntriesDoomed(const base::Closure& callback, int net_error) {
576 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); 581 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback);
577 } 582 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/nacl_host/pnacl_host_unittest.cc » ('j') | components/nacl/common/pnacl_types.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698