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/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 area->DeleteOrigin(); | 110 area->DeleteOrigin(); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 void DomStorageNamespace::DeleteSessionStorageOrigin(const GURL& origin) { | 114 void DomStorageNamespace::DeleteSessionStorageOrigin(const GURL& origin) { |
115 DomStorageArea* area = OpenStorageArea(origin); | 115 DomStorageArea* area = OpenStorageArea(origin); |
116 area->FastClear(); | 116 area->FastClear(); |
117 CloseStorageArea(area); | 117 CloseStorageArea(area); |
118 } | 118 } |
119 | 119 |
120 void DomStorageNamespace::PurgeMemory() { | 120 void DomStorageNamespace::PurgeMemory(PurgeOption option) { |
121 if (directory_.empty()) | 121 if (directory_.empty()) |
122 return; // We can't purge w/o backing on disk. | 122 return; // We can't purge w/o backing on disk. |
123 AreaMap::iterator it = areas_.begin(); | 123 AreaMap::iterator it = areas_.begin(); |
124 while (it != areas_.end()) { | 124 while (it != areas_.end()) { |
125 // Leave it alone if changes are pending | 125 // Leave it alone if changes are pending |
126 if (it->second.area_->HasUncommittedChanges()) { | 126 if (it->second.area_->HasUncommittedChanges()) { |
127 ++it; | 127 ++it; |
128 continue; | 128 continue; |
129 } | 129 } |
130 | 130 |
131 // If not in use, we can shut it down and remove | 131 // If not in use, we can shut it down and remove |
132 // it from our collection entirely. | 132 // it from our collection entirely. |
133 if (it->second.open_count_ == 0) { | 133 if (it->second.open_count_ == 0) { |
134 it->second.area_->Shutdown(); | 134 it->second.area_->Shutdown(); |
135 areas_.erase(it++); | 135 areas_.erase(it++); |
136 continue; | 136 continue; |
137 } | 137 } |
138 | 138 |
139 // Otherwise, we can clear caches and such. | 139 if (option == PURGE_AGGRESSIVE) { |
140 it->second.area_->PurgeMemory(); | 140 // If aggressive is true, we clear caches and such |
| 141 // for opened areas. |
| 142 it->second.area_->PurgeMemory(); |
| 143 } |
| 144 |
141 ++it; | 145 ++it; |
142 } | 146 } |
143 } | 147 } |
144 | 148 |
145 void DomStorageNamespace::Shutdown() { | 149 void DomStorageNamespace::Shutdown() { |
146 AreaMap::const_iterator it = areas_.begin(); | 150 AreaMap::const_iterator it = areas_.begin(); |
147 for (; it != areas_.end(); ++it) | 151 for (; it != areas_.end(); ++it) |
148 it->second.area_->Shutdown(); | 152 it->second.area_->Shutdown(); |
149 } | 153 } |
150 | 154 |
| 155 unsigned int DomStorageNamespace::CountInMemoryAreas() const { |
| 156 unsigned int area_count = 0; |
| 157 for (AreaMap::const_iterator it = areas_.begin(); it != areas_.end(); ++it) { |
| 158 if (it->second.area_->IsLoadedInMemory()) |
| 159 ++area_count; |
| 160 } |
| 161 return area_count; |
| 162 } |
151 | 163 |
152 DomStorageNamespace::AreaHolder* | 164 DomStorageNamespace::AreaHolder* |
153 DomStorageNamespace::GetAreaHolder(const GURL& origin) { | 165 DomStorageNamespace::GetAreaHolder(const GURL& origin) { |
154 AreaMap::iterator found = areas_.find(origin); | 166 AreaMap::iterator found = areas_.find(origin); |
155 if (found == areas_.end()) | 167 if (found == areas_.end()) |
156 return NULL; | 168 return NULL; |
157 return &(found->second); | 169 return &(found->second); |
158 } | 170 } |
159 | 171 |
160 // AreaHolder | 172 // AreaHolder |
161 | 173 |
162 DomStorageNamespace::AreaHolder::AreaHolder() | 174 DomStorageNamespace::AreaHolder::AreaHolder() |
163 : open_count_(0) { | 175 : open_count_(0) { |
164 } | 176 } |
165 | 177 |
166 DomStorageNamespace::AreaHolder::AreaHolder( | 178 DomStorageNamespace::AreaHolder::AreaHolder( |
167 DomStorageArea* area, int count) | 179 DomStorageArea* area, int count) |
168 : area_(area), open_count_(count) { | 180 : area_(area), open_count_(count) { |
169 } | 181 } |
170 | 182 |
171 DomStorageNamespace::AreaHolder::~AreaHolder() { | 183 DomStorageNamespace::AreaHolder::~AreaHolder() { |
172 } | 184 } |
173 | 185 |
174 } // namespace dom_storage | 186 } // namespace dom_storage |
OLD | NEW |