Chromium Code Reviews| Index: content/browser/indexed_db/indexed_db_connection.cc |
| diff --git a/content/browser/indexed_db/indexed_db_connection.cc b/content/browser/indexed_db/indexed_db_connection.cc |
| index f7133a69230da18b88b9deb75e84775823d9467e..469ba1b41f1d087262946f70f5bb8ce82c52dca8 100644 |
| --- a/content/browser/indexed_db/indexed_db_connection.cc |
| +++ b/content/browser/indexed_db/indexed_db_connection.cc |
| @@ -4,6 +4,9 @@ |
| #include "content/browser/indexed_db/indexed_db_connection.h" |
| +#include "base/logging.h" |
| +#include "base/stl_util.h" |
| + |
| namespace content { |
| IndexedDBConnection::IndexedDBConnection( |
| @@ -21,6 +24,7 @@ void IndexedDBConnection::Close() { |
| if (this_obj) { |
| database_ = nullptr; |
| callbacks_ = nullptr; |
| + active_observers_.clear(); |
| } |
| } |
| @@ -35,6 +39,7 @@ void IndexedDBConnection::ForceClose() { |
| if (this_obj) { |
| database_ = nullptr; |
| callbacks_ = nullptr; |
| + active_observers_.clear(); |
| } |
| callbacks->OnForcedClose(); |
| } |
| @@ -49,4 +54,36 @@ bool IndexedDBConnection::IsConnected() { |
| return database_.get() != NULL; |
| } |
| +void IndexedDBConnection::ActivatePendingObservers( |
| + std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers) { |
| + for (uint32_t i = 0; i < pending_observers.size(); i++) { |
| + active_observers_.push_back(std::move(pending_observers[i])); |
| + } |
| + // pending_observers->clear(); |
|
dmurph
2016/06/27 21:20:51
Probably safe to clear here.
palakj1
2016/06/27 23:13:08
Done. Is it okay to pass the argument by value?
|
| +} |
| + |
| +void IndexedDBConnection::RemoveObservers( |
| + const std::vector<int32_t>& observer_ids_to_remove) { |
| + // TODO(palakj): Change from vector to set or create tmp vector instead of |
| + // erase. |
| + std::vector<int32_t> pending_observer_ids; |
| + for (int32_t id_to_remove : observer_ids_to_remove) { |
| + bool removed = false; |
| + for (size_t j = 0; j < active_observers_.size(); j++) { |
| + if (active_observers_[j]->id() == id_to_remove) { |
| + active_observers_.erase(active_observers_.begin() + j); |
|
dmurph
2016/06/27 21:20:51
Again, this won't work. You'll remove the item at
dmurph
2016/06/27 21:44:06
Nevermind, this works.
|
| + removed = true; |
| + break; |
| + } |
| + } |
| + // If observer not in active_observers_ , must be in pending_observer list |
| + // of one of the transactions. |
| + if (!removed) { |
| + pending_observer_ids.push_back(id_to_remove); |
| + } |
| + } |
| + if (!pending_observer_ids.empty()) |
| + database_->RemovePendingObservers(this, pending_observer_ids); |
| +} |
| + |
| } // namespace content |