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" | |
9 #include "base/location.h" | |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "webkit/dom_storage/dom_storage_area.h" | 11 #include "webkit/dom_storage/dom_storage_area.h" |
10 #include "webkit/dom_storage/dom_storage_task_runner.h" | 12 #include "webkit/dom_storage/dom_storage_task_runner.h" |
11 #include "webkit/dom_storage/dom_storage_types.h" | 13 #include "webkit/dom_storage/dom_storage_types.h" |
14 #include "webkit/dom_storage/session_storage_database.h" | |
12 | 15 |
13 namespace dom_storage { | 16 namespace dom_storage { |
14 | 17 |
15 DomStorageNamespace::DomStorageNamespace( | 18 DomStorageNamespace::DomStorageNamespace( |
16 const FilePath& directory, | 19 const FilePath& directory, |
17 DomStorageTaskRunner* task_runner) | 20 DomStorageTaskRunner* task_runner) |
18 : namespace_id_(kLocalStorageNamespaceId), | 21 : namespace_id_(kLocalStorageNamespaceId), |
19 directory_(directory), | 22 directory_(directory), |
20 task_runner_(task_runner) { | 23 task_runner_(task_runner) { |
21 } | 24 } |
22 | 25 |
23 DomStorageNamespace::DomStorageNamespace( | 26 DomStorageNamespace::DomStorageNamespace( |
24 int64 namespace_id, | 27 int64 namespace_id, |
28 SessionStorageDatabase* session_storage_database, | |
25 DomStorageTaskRunner* task_runner) | 29 DomStorageTaskRunner* task_runner) |
26 : namespace_id_(namespace_id), | 30 : namespace_id_(namespace_id), |
27 task_runner_(task_runner) { | 31 task_runner_(task_runner), |
32 session_storage_database_(session_storage_database) { | |
28 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); | 33 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); |
29 } | 34 } |
30 | 35 |
31 DomStorageNamespace::~DomStorageNamespace() { | 36 DomStorageNamespace::~DomStorageNamespace() { |
32 } | 37 } |
33 | 38 |
34 DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) { | 39 DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) { |
35 if (AreaHolder* holder = GetAreaHolder(origin)) { | 40 if (AreaHolder* holder = GetAreaHolder(origin)) { |
36 ++(holder->open_count_); | 41 ++(holder->open_count_); |
37 return holder->area_; | 42 return holder->area_; |
38 } | 43 } |
39 DomStorageArea* area = new DomStorageArea(namespace_id_, origin, | 44 DomStorageArea* area; |
40 directory_, task_runner_); | 45 if (namespace_id_ == kLocalStorageNamespaceId) { |
46 area = new DomStorageArea(namespace_id_, origin, directory_, task_runner_); | |
47 } else { | |
48 area = new DomStorageArea(namespace_id_, origin, session_storage_database_, | |
49 task_runner_); | |
50 } | |
41 areas_[origin] = AreaHolder(area, 1); | 51 areas_[origin] = AreaHolder(area, 1); |
42 return area; | 52 return area; |
43 } | 53 } |
44 | 54 |
45 void DomStorageNamespace::CloseStorageArea(DomStorageArea* area) { | 55 void DomStorageNamespace::CloseStorageArea(DomStorageArea* area) { |
46 AreaHolder* holder = GetAreaHolder(area->origin()); | 56 AreaHolder* holder = GetAreaHolder(area->origin()); |
47 DCHECK(holder); | 57 DCHECK(holder); |
48 DCHECK_EQ(holder->area_.get(), area); | 58 DCHECK_EQ(holder->area_.get(), area); |
49 --(holder->open_count_); | 59 --(holder->open_count_); |
50 // TODO(michaeln): Clean up areas that aren't needed in memory anymore. | 60 // 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. | 61 // The in-process-webkit based impl didn't do this either, but would be nice. |
52 } | 62 } |
53 | 63 |
54 DomStorageNamespace* DomStorageNamespace::Clone(int64 clone_namespace_id) { | 64 DomStorageNamespace* DomStorageNamespace::Clone(int64 clone_namespace_id) { |
55 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_); | 65 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_); |
56 DCHECK_NE(kLocalStorageNamespaceId, clone_namespace_id); | 66 DCHECK_NE(kLocalStorageNamespaceId, clone_namespace_id); |
57 DomStorageNamespace* clone = | 67 DomStorageNamespace* clone = new DomStorageNamespace( |
58 new DomStorageNamespace(clone_namespace_id, task_runner_); | 68 clone_namespace_id, session_storage_database_, task_runner_); |
59 AreaMap::const_iterator it = areas_.begin(); | 69 AreaMap::const_iterator it = areas_.begin(); |
70 // Clone the in-memory structures. | |
60 for (; it != areas_.end(); ++it) { | 71 for (; it != areas_.end(); ++it) { |
61 DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id); | 72 DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id); |
62 clone->areas_[it->first] = AreaHolder(area, 0); | 73 clone->areas_[it->first] = AreaHolder(area, 0); |
63 } | 74 } |
75 // And clone the on-disk structures, too. | |
76 if (session_storage_database_.get()) { | |
77 bool success = task_runner_->PostShutdownBlockingTask( | |
78 FROM_HERE, | |
79 DomStorageTaskRunner::COMMIT_SEQUENCE, | |
80 base::Bind(&SessionStorageDatabase::CloneNamespace, | |
81 session_storage_database_.get(), namespace_id_, | |
82 clone_namespace_id)); | |
83 DCHECK(success); | |
84 } | |
64 return clone; | 85 return clone; |
65 } | 86 } |
66 | 87 |
67 void DomStorageNamespace::DeleteOrigin(const GURL& origin) { | 88 void DomStorageNamespace::DeleteOrigin(const GURL& origin) { |
68 AreaHolder* holder = GetAreaHolder(origin); | 89 AreaHolder* holder = GetAreaHolder(origin); |
69 if (holder) { | 90 if (holder) { |
70 holder->area_->DeleteOrigin(); | 91 holder->area_->DeleteOrigin(); |
71 return; | 92 return; |
72 } | 93 } |
73 if (!directory_.empty()) { | 94 if (!directory_.empty()) { |
74 scoped_refptr<DomStorageArea> area = | 95 scoped_refptr<DomStorageArea> area = |
75 new DomStorageArea(namespace_id_, origin, directory_, task_runner_); | 96 new DomStorageArea(namespace_id_, origin, directory_, task_runner_); |
76 area->DeleteOrigin(); | 97 area->DeleteOrigin(); |
98 } else if (session_storage_database_.get()) { | |
michaeln
2012/05/16 08:10:55
i think the DomStorageNamespace::DeleteOrigin meth
marja
2012/05/30 11:46:19
Done.
Ah, yes, there was a race. What if I set is
| |
99 scoped_refptr<DomStorageArea> area = | |
100 new DomStorageArea(namespace_id_, origin, | |
101 session_storage_database_.get(), task_runner_); | |
102 area->DeleteOrigin(); | |
77 } | 103 } |
78 } | 104 } |
79 | 105 |
80 void DomStorageNamespace::PurgeMemory() { | 106 void DomStorageNamespace::PurgeMemory() { |
81 if (directory_.empty()) | 107 if (directory_.empty()) |
82 return; // We can't purge w/o backing on disk. | 108 return; // We can't purge w/o backing on disk. |
83 AreaMap::iterator it = areas_.begin(); | 109 AreaMap::iterator it = areas_.begin(); |
84 while (it != areas_.end()) { | 110 while (it != areas_.end()) { |
85 // Leave it alone if changes are pending | 111 // Leave it alone if changes are pending |
86 if (it->second.area_->HasUncommittedChanges()) { | 112 if (it->second.area_->HasUncommittedChanges()) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 | 151 |
126 DomStorageNamespace::AreaHolder::AreaHolder( | 152 DomStorageNamespace::AreaHolder::AreaHolder( |
127 DomStorageArea* area, int count) | 153 DomStorageArea* area, int count) |
128 : area_(area), open_count_(count) { | 154 : area_(area), open_count_(count) { |
129 } | 155 } |
130 | 156 |
131 DomStorageNamespace::AreaHolder::~AreaHolder() { | 157 DomStorageNamespace::AreaHolder::~AreaHolder() { |
132 } | 158 } |
133 | 159 |
134 } // namespace dom_storage | 160 } // namespace dom_storage |
OLD | NEW |