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

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

Issue 10546167: Create and store persistent unique ids for sessionStorage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: code review Created 8 years, 6 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') | webkit/dom_storage/dom_storage_session.h » ('j') | 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"
11 #include "webkit/dom_storage/dom_storage_types.h" 11 #include "webkit/dom_storage/dom_storage_types.h"
12 12
13 namespace dom_storage { 13 namespace dom_storage {
14 14
15 DomStorageNamespace::DomStorageNamespace( 15 DomStorageNamespace::DomStorageNamespace(
16 const FilePath& directory, 16 const FilePath& directory,
17 DomStorageTaskRunner* task_runner) 17 DomStorageTaskRunner* task_runner)
18 : namespace_id_(kLocalStorageNamespaceId), 18 : namespace_id_(kLocalStorageNamespaceId),
19 directory_(directory), 19 directory_(directory),
20 task_runner_(task_runner) { 20 task_runner_(task_runner) {
21 } 21 }
22 22
23 DomStorageNamespace::DomStorageNamespace( 23 DomStorageNamespace::DomStorageNamespace(
24 int64 namespace_id, 24 int64 namespace_id,
25 const std::string& persistent_namespace_id,
25 DomStorageTaskRunner* task_runner) 26 DomStorageTaskRunner* task_runner)
26 : namespace_id_(namespace_id), 27 : namespace_id_(namespace_id),
28 persistent_namespace_id_(persistent_namespace_id),
27 task_runner_(task_runner) { 29 task_runner_(task_runner) {
28 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); 30 DCHECK_NE(kLocalStorageNamespaceId, namespace_id);
29 } 31 }
30 32
31 DomStorageNamespace::~DomStorageNamespace() { 33 DomStorageNamespace::~DomStorageNamespace() {
32 } 34 }
33 35
34 DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) { 36 DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) {
35 if (AreaHolder* holder = GetAreaHolder(origin)) { 37 if (AreaHolder* holder = GetAreaHolder(origin)) {
36 ++(holder->open_count_); 38 ++(holder->open_count_);
37 return holder->area_; 39 return holder->area_;
38 } 40 }
39 DomStorageArea* area = new DomStorageArea(namespace_id_, origin, 41 DomStorageArea* area;
40 directory_, task_runner_); 42 if (namespace_id_ == kLocalStorageNamespaceId) {
43 area = new DomStorageArea(origin, directory_, task_runner_);
44 } else {
45 area = new DomStorageArea(namespace_id_, persistent_namespace_id_, origin,
46 task_runner_);
47 }
41 areas_[origin] = AreaHolder(area, 1); 48 areas_[origin] = AreaHolder(area, 1);
42 return area; 49 return area;
43 } 50 }
44 51
45 void DomStorageNamespace::CloseStorageArea(DomStorageArea* area) { 52 void DomStorageNamespace::CloseStorageArea(DomStorageArea* area) {
46 AreaHolder* holder = GetAreaHolder(area->origin()); 53 AreaHolder* holder = GetAreaHolder(area->origin());
47 DCHECK(holder); 54 DCHECK(holder);
48 DCHECK_EQ(holder->area_.get(), area); 55 DCHECK_EQ(holder->area_.get(), area);
49 --(holder->open_count_); 56 --(holder->open_count_);
50 // TODO(michaeln): Clean up areas that aren't needed in memory anymore. 57 // TODO(michaeln): Clean up areas that aren't needed in memory anymore.
51 // The in-process-webkit based impl didn't do this either, but would be nice. 58 // The in-process-webkit based impl didn't do this either, but would be nice.
52 } 59 }
53 60
54 DomStorageNamespace* DomStorageNamespace::Clone(int64 clone_namespace_id) { 61 DomStorageNamespace* DomStorageNamespace::Clone(
62 int64 clone_namespace_id,
63 const std::string& clone_persistent_namespace_id) {
55 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_); 64 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_);
56 DCHECK_NE(kLocalStorageNamespaceId, clone_namespace_id); 65 DCHECK_NE(kLocalStorageNamespaceId, clone_namespace_id);
57 DomStorageNamespace* clone = 66 DomStorageNamespace* clone = new DomStorageNamespace(
58 new DomStorageNamespace(clone_namespace_id, task_runner_); 67 clone_namespace_id, clone_persistent_namespace_id, task_runner_);
59 AreaMap::const_iterator it = areas_.begin(); 68 AreaMap::const_iterator it = areas_.begin();
60 for (; it != areas_.end(); ++it) { 69 for (; it != areas_.end(); ++it) {
61 DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id); 70 DomStorageArea* area = it->second.area_->ShallowCopy(
71 clone_namespace_id, clone_persistent_namespace_id);
62 clone->areas_[it->first] = AreaHolder(area, 0); 72 clone->areas_[it->first] = AreaHolder(area, 0);
63 } 73 }
64 return clone; 74 return clone;
65 } 75 }
66 76
67 void DomStorageNamespace::DeleteOrigin(const GURL& origin) { 77 void DomStorageNamespace::DeleteOrigin(const GURL& origin) {
68 AreaHolder* holder = GetAreaHolder(origin); 78 AreaHolder* holder = GetAreaHolder(origin);
69 if (holder) { 79 if (holder) {
70 holder->area_->DeleteOrigin(); 80 holder->area_->DeleteOrigin();
71 return; 81 return;
72 } 82 }
73 if (!directory_.empty()) { 83 if (!directory_.empty()) {
74 scoped_refptr<DomStorageArea> area = 84 scoped_refptr<DomStorageArea> area =
75 new DomStorageArea(namespace_id_, origin, directory_, task_runner_); 85 new DomStorageArea(origin, directory_, task_runner_);
76 area->DeleteOrigin(); 86 area->DeleteOrigin();
77 } 87 }
78 } 88 }
79 89
80 void DomStorageNamespace::PurgeMemory() { 90 void DomStorageNamespace::PurgeMemory() {
81 if (directory_.empty()) 91 if (directory_.empty())
82 return; // We can't purge w/o backing on disk. 92 return; // We can't purge w/o backing on disk.
83 AreaMap::iterator it = areas_.begin(); 93 AreaMap::iterator it = areas_.begin();
84 while (it != areas_.end()) { 94 while (it != areas_.end()) {
85 // Leave it alone if changes are pending 95 // Leave it alone if changes are pending
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 135
126 DomStorageNamespace::AreaHolder::AreaHolder( 136 DomStorageNamespace::AreaHolder::AreaHolder(
127 DomStorageArea* area, int count) 137 DomStorageArea* area, int count)
128 : area_(area), open_count_(count) { 138 : area_(area), open_count_(count) {
129 } 139 }
130 140
131 DomStorageNamespace::AreaHolder::~AreaHolder() { 141 DomStorageNamespace::AreaHolder::~AreaHolder() {
132 } 142 }
133 143
134 } // namespace dom_storage 144 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_namespace.h ('k') | webkit/dom_storage/dom_storage_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698