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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/location.h"
7 #include "base/task_runner.h"
8 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h"
9 #include "content/browser/indexed_db/indexed_db_backing_store.h"
10 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
11
12 namespace content {
13
14 IndexedDBActiveBlobRegistry::IndexedDBActiveBlobRegistry(
15 IndexedDBBackingStore* backing_store)
16 : backing_store_(backing_store) {
17 }
18
19 IndexedDBActiveBlobRegistry::~IndexedDBActiveBlobRegistry() {
20 }
21
22 void IndexedDBActiveBlobRegistry::MarkUsed(int64 database_id, int64 blob_key) {
23 fprintf(stderr, "ERICU: MarkUsed(%ld, %ld).\n", database_id, blob_key);
24 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread());
25 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
26 DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key));
27 SingleDBMap& single_db_map = use_counts_[database_id];
28 SingleDBMap::iterator iter = single_db_map.find(blob_key);
29 if (iter == single_db_map.end()) {
30 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
31 backing_store_->AddRef();
32 } else {
33 DCHECK(!iter->second); // You can't add a reference once it's been deleted.
34 }
35 }
36
37 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.
38 int64 database_id, int64 blob_key) {
39 fprintf(stderr, "ERICU: MarkUnused(%ld, %ld).\n", database_id, blob_key);
40 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread());
41 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
42 DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key));
43 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
44 if (all_dbs_iter == use_counts_.end()) {
45 NOTREACHED();
46 return;
47 }
48 SingleDBMap& single_db = all_dbs_iter->second;
49 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.
50 if (single_db_iter == single_db.end()) {
51 NOTREACHED();
52 return;
53 }
54 bool delete_in_backend = false;
55 DeletedDBSet::iterator db_to_delete = deleted_dbs_.find(database_id);
56 bool db_marked_for_deletion = db_to_delete != deleted_dbs_.end();
57 // Don't bother deleting the file if we're going to delete its whole
58 // database directory soon.
59 delete_in_backend = single_db_iter->second && !db_marked_for_deletion;
60 fprintf(stderr, "ERICU: MarkUnused delete_in_backend, db_m_f_d are %d, %d.\n",
61 delete_in_backend, db_marked_for_deletion);
62 single_db.erase(single_db_iter);
63 if (!single_db.size()) {
jsbell 2013/09/13 00:12:21 nit: use empty()
ericu 2013/11/20 23:05:39 Done.
64 fprintf(stderr, "ERICU: single_db is empty now.\n");
65 use_counts_.erase(all_dbs_iter);
66 if (db_marked_for_deletion) {
67 fprintf(stderr, "ERICU: db_marked_for_deletion.\n");
68 delete_in_backend = true;
69 blob_key = DatabaseMetaDataKey::kAllBlobsKey;
70 deleted_dbs_.erase(db_to_delete);
71 }
72 }
73 if (delete_in_backend)
74 backing_store_->ReportBlobUnused(database_id, blob_key);
75 backing_store_->Release();
76 }
77
78 bool IndexedDBActiveBlobRegistry::MarkDeletedCheckIfUsed(
79 int64 database_id, int64 blob_key) {
80 fprintf(stderr, "ERICU: MarkDeletedCheckIfUsed(%ld, %ld).\n",
81 database_id, blob_key);
82 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread());
83 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
84 AllDBsMap::iterator all_dbs_iter = use_counts_.find(database_id);
85 if (all_dbs_iter == use_counts_.end())
86 return false;
87
88 if (blob_key == DatabaseMetaDataKey::kAllBlobsKey) {
89 deleted_dbs_.insert(database_id);
90 fprintf(stderr, "ERICU: MarkDeletedCheckIfUsed returning early true.\n");
91 return true;
92 }
93
94 SingleDBMap& single_db = all_dbs_iter->second;
95 SingleDBMap::iterator iter = single_db.find(blob_key);
96 if (iter == single_db.end())
97 return false;
98
99 fprintf(stderr, "ERICU: MarkDeletedCheckIfUsed returning true.\n");
100 iter->second = true;
101 return true;
102 }
103
104 void IndexedDBActiveBlobRegistry::MarkUnusedThreadSafe(
105 int64 database_id, int64 blob_key, const base::FilePath& unused) {
106 backing_store_->task_runner()->PostTask(
107 FROM_HERE,
108 base::Bind(
109 &IndexedDBActiveBlobRegistry::MarkUnused, base::Unretained(this),
110 database_id, blob_key));
111 }
112
113 webkit_blob::ShareableFileReference::FinalReleaseCallback
114 IndexedDBActiveBlobRegistry::GetReleaseCallback(
115 int64 database_id, int64 blob_key) {
116 return base::Bind(
117 &IndexedDBActiveBlobRegistry::MarkUnusedThreadSafe,
118 base::Unretained(this), database_id, blob_key);
119 }
120
121 base::Closure IndexedDBActiveBlobRegistry::GetMarkUsedCallback(
122 int64 database_id, int64 blob_key) {
123 return base::Bind(
124 &IndexedDBActiveBlobRegistry::MarkUsed,
125 base::Unretained(this), database_id, blob_key);
126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698