Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/dom_storage/dom_storage_namespace.h" | 5 #include "webkit/dom_storage/dom_storage_namespace.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "webkit/dom_storage/dom_storage_area.h" | 9 #include "webkit/dom_storage/dom_storage_area.h" |
| 10 #include "webkit/dom_storage/dom_storage_task_runner.h" | 10 #include "webkit/dom_storage/dom_storage_task_runner.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 DomStorageNamespace* clone = | 57 DomStorageNamespace* clone = |
| 58 new DomStorageNamespace(clone_namespace_id, task_runner_); | 58 new DomStorageNamespace(clone_namespace_id, task_runner_); |
| 59 AreaMap::const_iterator it = areas_.begin(); | 59 AreaMap::const_iterator it = areas_.begin(); |
| 60 for (; it != areas_.end(); ++it) { | 60 for (; it != areas_.end(); ++it) { |
| 61 DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id); | 61 DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id); |
| 62 clone->areas_[it->first] = AreaHolder(area, 0); | 62 clone->areas_[it->first] = AreaHolder(area, 0); |
| 63 } | 63 } |
| 64 return clone; | 64 return clone; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void DomStorageNamespace::DeleteOrigin(const GURL& origin) { | |
| 68 AreaHolder* holder = GetAreaHolder(origin); | |
| 69 if (holder) { | |
| 70 holder->area_->DeleteOrigin(); | |
| 71 return; | |
| 72 } | |
| 73 if (directory_.empty()) | |
| 74 return; | |
| 75 scoped_refptr<DomStorageArea> area = | |
| 76 new DomStorageArea(namespace_id_, origin, directory_, task_runner_); | |
| 77 area->DeleteOrigin(); | |
| 78 } | |
| 79 | |
| 67 void DomStorageNamespace::PurgeMemory() { | 80 void DomStorageNamespace::PurgeMemory() { |
| 68 // TODO(michaeln): write me | 81 DCHECK_EQ(kLocalStorageNamespaceId, namespace_id_); |
| 82 if (directory_.empty()) | |
| 83 return; // We can't purge w/o backing on disk. | |
| 84 AreaMap::const_iterator it = areas_.begin(); | |
| 85 while (it != areas_.end()) { | |
| 86 // Leave it alone if changes are pending | |
| 87 if (it->second.area_->HasUncommittedChanges()) { | |
| 88 ++it; | |
| 89 continue; | |
| 90 } | |
| 91 | |
| 92 // If not in use, we can shut it down and remove | |
| 93 // it from our collection entirely. | |
| 94 if (it->second.open_count_ == 0) { | |
| 95 it->second.area_->Shutdown(); | |
| 96 AreaMap::const_iterator delete_it = it; | |
|
jsbell
2012/03/21 20:26:29
Can you just do: areas_.erase(it++) ?
michaeln
2012/03/21 20:30:20
looks like i could
michaeln
2012/03/21 20:46:10
Done.
| |
| 97 ++it; | |
| 98 areas_.erase(delete_it); | |
| 99 continue; | |
| 100 } | |
| 101 | |
| 102 // Otherwise, we can clear caches and such. | |
| 103 it->second.area_->PurgeMemory(); | |
| 104 ++it; | |
| 105 } | |
| 69 } | 106 } |
| 70 | 107 |
| 71 void DomStorageNamespace::Shutdown() { | 108 void DomStorageNamespace::Shutdown() { |
| 72 AreaMap::const_iterator it = areas_.begin(); | 109 AreaMap::const_iterator it = areas_.begin(); |
| 73 for (; it != areas_.end(); ++it) | 110 for (; it != areas_.end(); ++it) |
| 74 it->second.area_->Shutdown(); | 111 it->second.area_->Shutdown(); |
| 75 } | 112 } |
| 76 | 113 |
| 77 | 114 |
| 78 DomStorageNamespace::AreaHolder* | 115 DomStorageNamespace::AreaHolder* |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 91 | 128 |
| 92 DomStorageNamespace::AreaHolder::AreaHolder( | 129 DomStorageNamespace::AreaHolder::AreaHolder( |
| 93 DomStorageArea* area, int count) | 130 DomStorageArea* area, int count) |
| 94 : area_(area), open_count_(count) { | 131 : area_(area), open_count_(count) { |
| 95 } | 132 } |
| 96 | 133 |
| 97 DomStorageNamespace::AreaHolder::~AreaHolder() { | 134 DomStorageNamespace::AreaHolder::~AreaHolder() { |
| 98 } | 135 } |
| 99 | 136 |
| 100 } // namespace dom_storage | 137 } // namespace dom_storage |
| OLD | NEW |