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

Unified Diff: chrome/browser/nacl_host/pnacl_translation_cache.cc

Issue 28933003: Delete PNaCl translation cache backend object when no longer needed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add dcheck Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/nacl_host/pnacl_translation_cache.cc
diff --git a/chrome/browser/nacl_host/pnacl_translation_cache.cc b/chrome/browser/nacl_host/pnacl_translation_cache.cc
index e3c8c207cbb429c29bd1b40e2d6a2dd62fee2922..56354792ebb6bf4ffe854927401c8781a44ceac4 100644
--- a/chrome/browser/nacl_host/pnacl_translation_cache.cc
+++ b/chrome/browser/nacl_host/pnacl_translation_cache.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
@@ -67,7 +68,8 @@ class PnaclTranslationCacheEntry
OPEN_ENTRY,
CREATE_ENTRY,
TRANSFER_ENTRY,
- CLOSE_ENTRY
+ CLOSE_ENTRY,
+ FINISHED
};
private:
@@ -142,8 +144,21 @@ PnaclTranslationCacheEntry::PnaclTranslationCacheEntry(
PnaclTranslationCacheEntry::~PnaclTranslationCacheEntry() {
// Ensure we have called the user's callback
- DCHECK(read_callback_.is_null());
- DCHECK(write_callback_.is_null());
+ if (step_ != FINISHED) {
+ if (!read_callback_.is_null()) {
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(read_callback_,
+ net::ERR_ABORTED,
+ scoped_refptr<net::DrainableIOBuffer>()));
+ }
+ if (!write_callback_.is_null()) {
+ BrowserThread::PostTask(BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(write_callback_, net::ERR_ABORTED));
+ }
+ }
}
void PnaclTranslationCacheEntry::Start() {
@@ -208,15 +223,17 @@ void PnaclTranslationCacheEntry::CloseEntry(int rv) {
}
void PnaclTranslationCacheEntry::Finish(int rv) {
+ step_ = FINISHED;
if (is_read_) {
if (!read_callback_.is_null()) {
- read_callback_.Run(rv, io_buf_);
- read_callback_.Reset();
+ BrowserThread::PostTask(BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(read_callback_, rv, io_buf_));
}
} else {
if (!write_callback_.is_null()) {
- write_callback_.Run(rv);
- write_callback_.Reset();
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE, base::Bind(write_callback_, rv));
}
}
cache_->OpComplete(this);
@@ -229,6 +246,7 @@ void PnaclTranslationCacheEntry::DispatchNext(int rv) {
switch (step_) {
case UNINITIALIZED:
+ case FINISHED:
LOG(ERROR) << "DispatchNext called uninitialized";
break;
@@ -273,8 +291,8 @@ void PnaclTranslationCacheEntry::DispatchNext(int rv) {
if (rv < 0) {
// We do not call DispatchNext directly if WriteEntry/ReadEntry returns
// ERR_IO_PENDING, and the callback should not return that value either.
- LOG(ERROR)
- << "Failed to complete write to entry: " << net::ErrorToString(rv);
+ LOG(ERROR) << "Failed to complete write to entry: "
+ << net::ErrorToString(rv);
step_ = CLOSE_ENTRY;
CloseEntry(rv);
break;
@@ -326,9 +344,8 @@ int PnaclTranslationCache::Init(net::CacheType cache_type,
NULL, /* dummy net log */
&disk_cache_,
base::Bind(&PnaclTranslationCache::OnCreateBackendComplete, AsWeakPtr()));
- init_callback_ = callback;
- if (rv != net::ERR_IO_PENDING) {
- OnCreateBackendComplete(rv);
+ if (rv == net::ERR_IO_PENDING) {
+ init_callback_ = callback;
}
return rv;
}
@@ -339,8 +356,8 @@ void PnaclTranslationCache::OnCreateBackendComplete(int rv) {
}
// Invoke our client's callback function.
if (!init_callback_.is_null()) {
- init_callback_.Run(rv);
- init_callback_.Reset();
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE, base::Bind(init_callback_, rv));
}
}
@@ -348,11 +365,6 @@ void PnaclTranslationCache::OnCreateBackendComplete(int rv) {
// High-level API
void PnaclTranslationCache::StoreNexe(const std::string& key,
- net::DrainableIOBuffer* nexe_data) {
- StoreNexe(key, nexe_data, CompletionCallback());
-}
-
-void PnaclTranslationCache::StoreNexe(const std::string& key,
net::DrainableIOBuffer* nexe_data,
const CompletionCallback& callback) {
PnaclTranslationCacheEntry* entry = PnaclTranslationCacheEntry::GetWriteEntry(
« no previous file with comments | « chrome/browser/nacl_host/pnacl_translation_cache.h ('k') | chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698