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

Side by Side Diff: webkit/dom_storage/dom_storage_namespace.cc

Issue 9817011: DomStorage data deletion and memory purging. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « webkit/dom_storage/dom_storage_namespace.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 scoped_refptr<DomStorageArea> area =
75 new DomStorageArea(namespace_id_, origin, directory_, task_runner_);
76 area->DeleteOrigin();
77 }
78 }
79
67 void DomStorageNamespace::PurgeMemory() { 80 void DomStorageNamespace::PurgeMemory() {
68 // TODO(michaeln): write me 81 if (directory_.empty())
82 return; // We can't purge w/o backing on disk.
83 AreaMap::iterator it = areas_.begin();
84 while (it != areas_.end()) {
85 // Leave it alone if changes are pending
86 if (it->second.area_->HasUncommittedChanges()) {
87 ++it;
88 continue;
89 }
90
91 // If not in use, we can shut it down and remove
92 // it from our collection entirely.
93 if (it->second.open_count_ == 0) {
94 it->second.area_->Shutdown();
95 areas_.erase(it++);
96 continue;
97 }
98
99 // Otherwise, we can clear caches and such.
100 it->second.area_->PurgeMemory();
101 ++it;
102 }
69 } 103 }
70 104
71 void DomStorageNamespace::Shutdown() { 105 void DomStorageNamespace::Shutdown() {
72 AreaMap::const_iterator it = areas_.begin(); 106 AreaMap::const_iterator it = areas_.begin();
73 for (; it != areas_.end(); ++it) 107 for (; it != areas_.end(); ++it)
74 it->second.area_->Shutdown(); 108 it->second.area_->Shutdown();
75 } 109 }
76 110
77 111
78 DomStorageNamespace::AreaHolder* 112 DomStorageNamespace::AreaHolder*
(...skipping 12 matching lines...) Expand all
91 125
92 DomStorageNamespace::AreaHolder::AreaHolder( 126 DomStorageNamespace::AreaHolder::AreaHolder(
93 DomStorageArea* area, int count) 127 DomStorageArea* area, int count)
94 : area_(area), open_count_(count) { 128 : area_(area), open_count_(count) {
95 } 129 }
96 130
97 DomStorageNamespace::AreaHolder::~AreaHolder() { 131 DomStorageNamespace::AreaHolder::~AreaHolder() {
98 } 132 }
99 133
100 } // namespace dom_storage 134 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_namespace.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698