OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/task_runner.h" | 8 #include "base/task_runner.h" |
9 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" | 9 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" |
10 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 10 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
11 #include "content/browser/indexed_db/indexed_db_factory.h" | 11 #include "content/browser/indexed_db/indexed_db_factory.h" |
12 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 12 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 IndexedDBActiveBlobRegistry::IndexedDBActiveBlobRegistry( | 16 IndexedDBActiveBlobRegistry::IndexedDBActiveBlobRegistry( |
17 IndexedDBBackingStore* backing_store) | 17 IndexedDBBackingStore* backing_store) |
18 : backing_store_(backing_store), weak_factory_(this) {} | 18 : backing_store_(backing_store), weak_factory_(this) {} |
19 | 19 |
20 IndexedDBActiveBlobRegistry::~IndexedDBActiveBlobRegistry() { | 20 IndexedDBActiveBlobRegistry::~IndexedDBActiveBlobRegistry() { |
21 } | 21 } |
22 | 22 |
23 void IndexedDBActiveBlobRegistry::AddBlobRef(int64 database_id, | 23 void IndexedDBActiveBlobRegistry::AddBlobRef(int64_t database_id, |
24 int64 blob_key) { | 24 int64_t blob_key) { |
25 DCHECK(backing_store_); | 25 DCHECK(backing_store_); |
26 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); | 26 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); |
27 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); | 27 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); |
28 DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key)); | 28 DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key)); |
29 DCHECK(!ContainsKey(deleted_dbs_, database_id)); | 29 DCHECK(!ContainsKey(deleted_dbs_, database_id)); |
30 bool need_ref = use_tracker_.empty(); | 30 bool need_ref = use_tracker_.empty(); |
31 SingleDBMap& single_db_map = use_tracker_[database_id]; | 31 SingleDBMap& single_db_map = use_tracker_[database_id]; |
32 SingleDBMap::iterator iter = single_db_map.find(blob_key); | 32 SingleDBMap::iterator iter = single_db_map.find(blob_key); |
33 if (iter == single_db_map.end()) { | 33 if (iter == single_db_map.end()) { |
34 single_db_map[blob_key] = false; | 34 single_db_map[blob_key] = false; |
35 if (need_ref) { | 35 if (need_ref) { |
36 backing_store_->factory()->ReportOutstandingBlobs( | 36 backing_store_->factory()->ReportOutstandingBlobs( |
37 backing_store_->origin_url(), true); | 37 backing_store_->origin_url(), true); |
38 } | 38 } |
39 } else { | 39 } else { |
40 DCHECK(!need_ref); | 40 DCHECK(!need_ref); |
41 DCHECK(!iter->second); // You can't add a reference once it's been deleted. | 41 DCHECK(!iter->second); // You can't add a reference once it's been deleted. |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 void IndexedDBActiveBlobRegistry::ReleaseBlobRef(int64 database_id, | 45 void IndexedDBActiveBlobRegistry::ReleaseBlobRef(int64_t database_id, |
46 int64 blob_key) { | 46 int64_t blob_key) { |
47 DCHECK(backing_store_); | 47 DCHECK(backing_store_); |
48 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); | 48 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); |
49 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); | 49 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); |
50 DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key)); | 50 DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key)); |
51 AllDBsMap::iterator db_pair = use_tracker_.find(database_id); | 51 AllDBsMap::iterator db_pair = use_tracker_.find(database_id); |
52 if (db_pair == use_tracker_.end()) { | 52 if (db_pair == use_tracker_.end()) { |
53 NOTREACHED(); | 53 NOTREACHED(); |
54 return; | 54 return; |
55 } | 55 } |
56 SingleDBMap& single_db = db_pair->second; | 56 SingleDBMap& single_db = db_pair->second; |
(...skipping 18 matching lines...) Expand all Loading... |
75 } | 75 } |
76 } | 76 } |
77 if (delete_in_backend) | 77 if (delete_in_backend) |
78 backing_store_->ReportBlobUnused(database_id, blob_key); | 78 backing_store_->ReportBlobUnused(database_id, blob_key); |
79 if (use_tracker_.empty()) { | 79 if (use_tracker_.empty()) { |
80 backing_store_->factory()->ReportOutstandingBlobs( | 80 backing_store_->factory()->ReportOutstandingBlobs( |
81 backing_store_->origin_url(), false); | 81 backing_store_->origin_url(), false); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 bool IndexedDBActiveBlobRegistry::MarkDeletedCheckIfUsed(int64 database_id, | 85 bool IndexedDBActiveBlobRegistry::MarkDeletedCheckIfUsed(int64_t database_id, |
86 int64 blob_key) { | 86 int64_t blob_key) { |
87 DCHECK(backing_store_); | 87 DCHECK(backing_store_); |
88 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); | 88 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); |
89 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); | 89 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); |
90 AllDBsMap::iterator db_pair = use_tracker_.find(database_id); | 90 AllDBsMap::iterator db_pair = use_tracker_.find(database_id); |
91 if (db_pair == use_tracker_.end()) | 91 if (db_pair == use_tracker_.end()) |
92 return false; | 92 return false; |
93 | 93 |
94 if (blob_key == DatabaseMetaDataKey::kAllBlobsKey) { | 94 if (blob_key == DatabaseMetaDataKey::kAllBlobsKey) { |
95 deleted_dbs_.insert(database_id); | 95 deleted_dbs_.insert(database_id); |
96 return true; | 96 return true; |
97 } | 97 } |
98 | 98 |
99 SingleDBMap& single_db = db_pair->second; | 99 SingleDBMap& single_db = db_pair->second; |
100 SingleDBMap::iterator iter = single_db.find(blob_key); | 100 SingleDBMap::iterator iter = single_db.find(blob_key); |
101 if (iter == single_db.end()) | 101 if (iter == single_db.end()) |
102 return false; | 102 return false; |
103 | 103 |
104 iter->second = true; | 104 iter->second = true; |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 void IndexedDBActiveBlobRegistry::ReleaseBlobRefThreadSafe( | 108 void IndexedDBActiveBlobRegistry::ReleaseBlobRefThreadSafe( |
109 scoped_refptr<base::TaskRunner> task_runner, | 109 scoped_refptr<base::TaskRunner> task_runner, |
110 base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, | 110 base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, |
111 int64 database_id, | 111 int64_t database_id, |
112 int64 blob_key, | 112 int64_t blob_key, |
113 const base::FilePath& unused) { | 113 const base::FilePath& unused) { |
114 task_runner->PostTask(FROM_HERE, | 114 task_runner->PostTask(FROM_HERE, |
115 base::Bind(&IndexedDBActiveBlobRegistry::ReleaseBlobRef, | 115 base::Bind(&IndexedDBActiveBlobRegistry::ReleaseBlobRef, |
116 weak_ptr, | 116 weak_ptr, |
117 database_id, | 117 database_id, |
118 blob_key)); | 118 blob_key)); |
119 } | 119 } |
120 | 120 |
121 storage::ShareableFileReference::FinalReleaseCallback | 121 storage::ShareableFileReference::FinalReleaseCallback |
122 IndexedDBActiveBlobRegistry::GetFinalReleaseCallback(int64 database_id, | 122 IndexedDBActiveBlobRegistry::GetFinalReleaseCallback(int64_t database_id, |
123 int64 blob_key) { | 123 int64_t blob_key) { |
124 return base::Bind( | 124 return base::Bind( |
125 &IndexedDBActiveBlobRegistry::ReleaseBlobRefThreadSafe, | 125 &IndexedDBActiveBlobRegistry::ReleaseBlobRefThreadSafe, |
126 scoped_refptr<base::TaskRunner>(backing_store_->task_runner()), | 126 scoped_refptr<base::TaskRunner>(backing_store_->task_runner()), |
127 weak_factory_.GetWeakPtr(), | 127 weak_factory_.GetWeakPtr(), |
128 database_id, | 128 database_id, |
129 blob_key); | 129 blob_key); |
130 } | 130 } |
131 | 131 |
132 base::Closure IndexedDBActiveBlobRegistry::GetAddBlobRefCallback( | 132 base::Closure IndexedDBActiveBlobRegistry::GetAddBlobRefCallback( |
133 int64 database_id, | 133 int64_t database_id, |
134 int64 blob_key) { | 134 int64_t blob_key) { |
135 return base::Bind(&IndexedDBActiveBlobRegistry::AddBlobRef, | 135 return base::Bind(&IndexedDBActiveBlobRegistry::AddBlobRef, |
136 weak_factory_.GetWeakPtr(), | 136 weak_factory_.GetWeakPtr(), |
137 database_id, | 137 database_id, |
138 blob_key); | 138 blob_key); |
139 } | 139 } |
140 | 140 |
141 void IndexedDBActiveBlobRegistry::ForceShutdown() { | 141 void IndexedDBActiveBlobRegistry::ForceShutdown() { |
142 weak_factory_.InvalidateWeakPtrs(); | 142 weak_factory_.InvalidateWeakPtrs(); |
143 use_tracker_.clear(); | 143 use_tracker_.clear(); |
144 backing_store_ = NULL; | 144 backing_store_ = NULL; |
145 } | 145 } |
146 | 146 |
147 } // namespace content | 147 } // namespace content |
OLD | NEW |