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

Unified Diff: content/browser/indexed_db/indexed_db_active_blob_registry.cc

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge fixes [builds, untested] 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_active_blob_registry.cc
diff --git a/content/browser/indexed_db/indexed_db_active_blob_registry.cc b/content/browser/indexed_db/indexed_db_active_blob_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cc2ab2effcb293b90120ed4334b6e51ae5267c71
--- /dev/null
+++ b/content/browser/indexed_db/indexed_db_active_blob_registry.cc
@@ -0,0 +1,128 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/task_runner.h"
+#include "content/browser/indexed_db/indexed_db_active_blob_registry.h"
+#include "content/browser/indexed_db/indexed_db_backing_store.h"
+#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
+
+namespace content {
+
+IndexedDBActiveBlobRegistry::IndexedDBActiveBlobRegistry(
+ IndexedDBBackingStore* backing_store)
+ : backing_store_(backing_store) {
+}
+
+IndexedDBActiveBlobRegistry::~IndexedDBActiveBlobRegistry() {
+}
+
+void IndexedDBActiveBlobRegistry::MarkUsed(int64 database_id, int64 blob_key) {
+ fprintf(stderr, "ERICU: MarkUsed(%ld, %ld).\n", database_id, blob_key);
+ DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread());
+ DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
+ DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key));
+ SingleDBMap& single_db_map = use_counts_[database_id];
+ SingleDBMap::iterator iter = single_db_map.find(blob_key);
+ if (iter == single_db_map.end()) {
+ single_db_map[blob_key] = false;
jsbell 2013/09/13 00:12:21 Call me an optimist, but could we swap the sense o
ericu 2013/11/20 23:05:39 Well, it's a little awkward the other way, too. R
+ backing_store_->AddRef();
+ } else {
+ DCHECK(!iter->second); // You can't add a reference once it's been deleted.
+ }
+}
+
+void IndexedDBActiveBlobRegistry::MarkUnused(
jsbell 2013/09/13 00:12:21 "Unused" in backing store means it has zero refere
ericu 2013/11/20 23:05:39 Done.
+ int64 database_id, int64 blob_key) {
+ fprintf(stderr, "ERICU: MarkUnused(%ld, %ld).\n", database_id, blob_key);
+ DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread());
+ DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
+ DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key));
+ AllDBsMap::iterator all_dbs_iter = use_counts_.find(database_id);
jsbell 2013/09/13 00:12:21 I'd tweak this variable name based on what it has
ericu 2013/11/20 23:05:39 Ug. I had a lot of trouble with those names--didn
+ if (all_dbs_iter == use_counts_.end()) {
+ NOTREACHED();
+ return;
+ }
+ SingleDBMap& single_db = all_dbs_iter->second;
+ SingleDBMap::iterator single_db_iter = single_db.find(blob_key);
jsbell 2013/09/13 00:12:21 Ditto - name the iterator for what it holds, not w
ericu 2013/11/20 23:05:39 Done.
+ if (single_db_iter == single_db.end()) {
+ NOTREACHED();
+ return;
+ }
+ bool delete_in_backend = false;
+ DeletedDBSet::iterator db_to_delete = deleted_dbs_.find(database_id);
+ bool db_marked_for_deletion = db_to_delete != deleted_dbs_.end();
+ // Don't bother deleting the file if we're going to delete its whole
+ // database directory soon.
+ delete_in_backend = single_db_iter->second && !db_marked_for_deletion;
+ fprintf(stderr, "ERICU: MarkUnused delete_in_backend, db_m_f_d are %d, %d.\n",
+ delete_in_backend, db_marked_for_deletion);
+ single_db.erase(single_db_iter);
+ if (!single_db.size()) {
jsbell 2013/09/13 00:12:21 nit: use empty()
ericu 2013/11/20 23:05:39 Done.
+ fprintf(stderr, "ERICU: single_db is empty now.\n");
+ use_counts_.erase(all_dbs_iter);
+ if (db_marked_for_deletion) {
+ fprintf(stderr, "ERICU: db_marked_for_deletion.\n");
+ delete_in_backend = true;
+ blob_key = DatabaseMetaDataKey::kAllBlobsKey;
+ deleted_dbs_.erase(db_to_delete);
+ }
+ }
+ if (delete_in_backend)
+ backing_store_->ReportBlobUnused(database_id, blob_key);
+ backing_store_->Release();
+}
+
+bool IndexedDBActiveBlobRegistry::MarkDeletedCheckIfUsed(
+ int64 database_id, int64 blob_key) {
+ fprintf(stderr, "ERICU: MarkDeletedCheckIfUsed(%ld, %ld).\n",
+ database_id, blob_key);
+ DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread());
+ DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
+ AllDBsMap::iterator all_dbs_iter = use_counts_.find(database_id);
+ if (all_dbs_iter == use_counts_.end())
+ return false;
+
+ if (blob_key == DatabaseMetaDataKey::kAllBlobsKey) {
+ deleted_dbs_.insert(database_id);
+ fprintf(stderr, "ERICU: MarkDeletedCheckIfUsed returning early true.\n");
+ return true;
+ }
+
+ SingleDBMap& single_db = all_dbs_iter->second;
+ SingleDBMap::iterator iter = single_db.find(blob_key);
+ if (iter == single_db.end())
+ return false;
+
+ fprintf(stderr, "ERICU: MarkDeletedCheckIfUsed returning true.\n");
+ iter->second = true;
+ return true;
+}
+
+void IndexedDBActiveBlobRegistry::MarkUnusedThreadSafe(
+ int64 database_id, int64 blob_key, const base::FilePath& unused) {
+ backing_store_->task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &IndexedDBActiveBlobRegistry::MarkUnused, base::Unretained(this),
+ database_id, blob_key));
+}
+
+webkit_blob::ShareableFileReference::FinalReleaseCallback
+IndexedDBActiveBlobRegistry::GetReleaseCallback(
+ int64 database_id, int64 blob_key) {
+ return base::Bind(
+ &IndexedDBActiveBlobRegistry::MarkUnusedThreadSafe,
+ base::Unretained(this), database_id, blob_key);
+}
+
+base::Closure IndexedDBActiveBlobRegistry::GetMarkUsedCallback(
+ int64 database_id, int64 blob_key) {
+ return base::Bind(
+ &IndexedDBActiveBlobRegistry::MarkUsed,
+ base::Unretained(this), database_id, blob_key);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698