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

Side by Side Diff: content/browser/dom_storage/dom_storage_host.cc

Issue 757723002: [Tests not passing yet] Remove prerender sessionStorage namespace merging. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/dom_storage/dom_storage_host.h" 5 #include "content/browser/dom_storage/dom_storage_host.h"
6 6
7 #include "content/browser/dom_storage/dom_storage_area.h" 7 #include "content/browser/dom_storage/dom_storage_area.h"
8 #include "content/browser/dom_storage/dom_storage_context_impl.h" 8 #include "content/browser/dom_storage/dom_storage_context_impl.h"
9 #include "content/browser/dom_storage/dom_storage_namespace.h" 9 #include "content/browser/dom_storage/dom_storage_namespace.h"
10 #include "content/common/dom_storage/dom_storage_types.h" 10 #include "content/common/dom_storage/dom_storage_types.h"
11 #include "url/gurl.h" 11 #include "url/gurl.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 DOMStorageHost::DOMStorageHost(DOMStorageContextImpl* context, 15 DOMStorageHost::DOMStorageHost(DOMStorageContextImpl* context)
16 int render_process_id) 16 : context_(context) {
17 : context_(context),
18 render_process_id_(render_process_id) {
19 } 17 }
20 18
21 DOMStorageHost::~DOMStorageHost() { 19 DOMStorageHost::~DOMStorageHost() {
22 AreaMap::const_iterator it = connections_.begin(); 20 AreaMap::const_iterator it = connections_.begin();
23 for (; it != connections_.end(); ++it) 21 for (; it != connections_.end(); ++it)
24 it->second.namespace_->CloseStorageArea(it->second.area_.get()); 22 it->second.namespace_->CloseStorageArea(it->second.area_.get());
25 connections_.clear(); // Clear prior to releasing the context_ 23 connections_.clear(); // Clear prior to releasing the context_
26 } 24 }
27 25
28 bool DOMStorageHost::OpenStorageArea(int connection_id, int namespace_id, 26 bool DOMStorageHost::OpenStorageArea(int connection_id, int namespace_id,
(...skipping 13 matching lines...) Expand all
42 40
43 void DOMStorageHost::CloseStorageArea(int connection_id) { 41 void DOMStorageHost::CloseStorageArea(int connection_id) {
44 AreaMap::iterator found = connections_.find(connection_id); 42 AreaMap::iterator found = connections_.find(connection_id);
45 if (found == connections_.end()) 43 if (found == connections_.end())
46 return; 44 return;
47 found->second.namespace_->CloseStorageArea(found->second.area_.get()); 45 found->second.namespace_->CloseStorageArea(found->second.area_.get());
48 connections_.erase(found); 46 connections_.erase(found);
49 } 47 }
50 48
51 bool DOMStorageHost::ExtractAreaValues( 49 bool DOMStorageHost::ExtractAreaValues(
52 int connection_id, DOMStorageValuesMap* map, bool* send_log_get_messages) { 50 int connection_id, DOMStorageValuesMap* map) {
53 map->clear(); 51 map->clear();
54 DOMStorageArea* area = GetOpenArea(connection_id); 52 DOMStorageArea* area = GetOpenArea(connection_id);
55 if (!area) 53 if (!area)
56 return false; 54 return false;
57 if (!area->IsLoadedInMemory()) { 55 if (!area->IsLoadedInMemory()) {
58 DOMStorageNamespace* ns = GetNamespace(connection_id); 56 DOMStorageNamespace* ns = GetNamespace(connection_id);
59 DCHECK(ns); 57 DCHECK(ns);
60 if (ns->CountInMemoryAreas() > kMaxInMemoryStorageAreas) { 58 if (ns->CountInMemoryAreas() > kMaxInMemoryStorageAreas) {
61 ns->PurgeMemory(DOMStorageNamespace::PURGE_UNOPENED); 59 ns->PurgeMemory(DOMStorageNamespace::PURGE_UNOPENED);
62 if (ns->CountInMemoryAreas() > kMaxInMemoryStorageAreas) 60 if (ns->CountInMemoryAreas() > kMaxInMemoryStorageAreas)
63 ns->PurgeMemory(DOMStorageNamespace::PURGE_AGGRESSIVE); 61 ns->PurgeMemory(DOMStorageNamespace::PURGE_AGGRESSIVE);
64 } 62 }
65 } 63 }
66 area->ExtractValues(map); 64 area->ExtractValues(map);
67 *send_log_get_messages = false;
68 DOMStorageNamespace* ns = GetNamespace(connection_id);
69 DCHECK(ns);
70 *send_log_get_messages = ns->IsLoggingRenderer(render_process_id_);
71 return true; 65 return true;
72 } 66 }
73 67
74 unsigned DOMStorageHost::GetAreaLength(int connection_id) { 68 unsigned DOMStorageHost::GetAreaLength(int connection_id) {
75 DOMStorageArea* area = GetOpenArea(connection_id); 69 DOMStorageArea* area = GetOpenArea(connection_id);
76 if (!area) 70 if (!area)
77 return 0; 71 return 0;
78 return area->Length(); 72 return area->Length();
79 } 73 }
80 74
(...skipping 17 matching lines...) Expand all
98 int connection_id, const base::string16& key, 92 int connection_id, const base::string16& key,
99 const base::string16& value, const GURL& page_url, 93 const base::string16& value, const GURL& page_url,
100 base::NullableString16* old_value) { 94 base::NullableString16* old_value) {
101 DOMStorageArea* area = GetOpenArea(connection_id); 95 DOMStorageArea* area = GetOpenArea(connection_id);
102 if (!area) 96 if (!area)
103 return false; 97 return false;
104 if (!area->SetItem(key, value, old_value)) 98 if (!area->SetItem(key, value, old_value))
105 return false; 99 return false;
106 if (old_value->is_null() || old_value->string() != value) 100 if (old_value->is_null() || old_value->string() != value)
107 context_->NotifyItemSet(area, key, value, *old_value, page_url); 101 context_->NotifyItemSet(area, key, value, *old_value, page_url);
108 MaybeLogTransaction(connection_id,
109 DOMStorageNamespace::TRANSACTION_WRITE,
110 area->origin(), page_url, key,
111 base::NullableString16(value, false));
112 return true; 102 return true;
113 } 103 }
114 104
115 void DOMStorageHost::LogGetAreaItem(
116 int connection_id, const base::string16& key,
117 const base::NullableString16& value) {
118 DOMStorageArea* area = GetOpenArea(connection_id);
119 if (!area)
120 return;
121 MaybeLogTransaction(connection_id,
122 DOMStorageNamespace::TRANSACTION_READ,
123 area->origin(), GURL(), key, value);
124 }
125
126 bool DOMStorageHost::RemoveAreaItem( 105 bool DOMStorageHost::RemoveAreaItem(
127 int connection_id, const base::string16& key, const GURL& page_url, 106 int connection_id, const base::string16& key, const GURL& page_url,
128 base::string16* old_value) { 107 base::string16* old_value) {
129 DOMStorageArea* area = GetOpenArea(connection_id); 108 DOMStorageArea* area = GetOpenArea(connection_id);
130 if (!area) 109 if (!area)
131 return false; 110 return false;
132 if (!area->RemoveItem(key, old_value)) 111 if (!area->RemoveItem(key, old_value))
133 return false; 112 return false;
134 context_->NotifyItemRemoved(area, key, *old_value, page_url); 113 context_->NotifyItemRemoved(area, key, *old_value, page_url);
135 MaybeLogTransaction(connection_id,
136 DOMStorageNamespace::TRANSACTION_REMOVE,
137 area->origin(), page_url, key, base::NullableString16());
138 return true; 114 return true;
139 } 115 }
140 116
141 bool DOMStorageHost::ClearArea(int connection_id, const GURL& page_url) { 117 bool DOMStorageHost::ClearArea(int connection_id, const GURL& page_url) {
142 DOMStorageArea* area = GetOpenArea(connection_id); 118 DOMStorageArea* area = GetOpenArea(connection_id);
143 if (!area) 119 if (!area)
144 return false; 120 return false;
145 if (!area->Clear()) 121 if (!area->Clear())
146 return false; 122 return false;
147 context_->NotifyAreaCleared(area, page_url); 123 context_->NotifyAreaCleared(area, page_url);
148 MaybeLogTransaction(connection_id,
149 DOMStorageNamespace::TRANSACTION_CLEAR,
150 area->origin(), page_url, base::string16(),
151 base::NullableString16());
152 return true; 124 return true;
153 } 125 }
154 126
155 bool DOMStorageHost::HasAreaOpen( 127 bool DOMStorageHost::HasAreaOpen(
156 int64 namespace_id, const GURL& origin, int64* alias_namespace_id) const { 128 int namespace_id, const GURL& origin) const {
157 AreaMap::const_iterator it = connections_.begin(); 129 AreaMap::const_iterator it = connections_.begin();
158 for (; it != connections_.end(); ++it) { 130 for (; it != connections_.end(); ++it) {
159 if (namespace_id == it->second.area_->namespace_id() && 131 if (namespace_id == it->second.namespace_->namespace_id() &&
160 origin == it->second.area_->origin()) { 132 origin == it->second.area_->origin()) {
161 *alias_namespace_id = it->second.namespace_->namespace_id();
162 return true; 133 return true;
163 } 134 }
164 } 135 }
165 return false; 136 return false;
166 } 137 }
167 138
168 bool DOMStorageHost::ResetOpenAreasForNamespace(int64 namespace_id) {
169 bool result = false;
170 AreaMap::iterator it = connections_.begin();
171 for (; it != connections_.end(); ++it) {
172 if (namespace_id == it->second.namespace_->namespace_id()) {
173 GURL origin = it->second.area_->origin();
174 it->second.namespace_->CloseStorageArea(it->second.area_.get());
175 it->second.area_ = it->second.namespace_->OpenStorageArea(origin);
176 result = true;
177 }
178 }
179 return result;
180 }
181
182 DOMStorageArea* DOMStorageHost::GetOpenArea(int connection_id) { 139 DOMStorageArea* DOMStorageHost::GetOpenArea(int connection_id) {
183 AreaMap::iterator found = connections_.find(connection_id); 140 AreaMap::iterator found = connections_.find(connection_id);
184 if (found == connections_.end()) 141 if (found == connections_.end())
185 return NULL; 142 return NULL;
186 return found->second.area_.get(); 143 return found->second.area_.get();
187 } 144 }
188 145
189 DOMStorageNamespace* DOMStorageHost::GetNamespace(int connection_id) { 146 DOMStorageNamespace* DOMStorageHost::GetNamespace(int connection_id) {
190 AreaMap::iterator found = connections_.find(connection_id); 147 AreaMap::iterator found = connections_.find(connection_id);
191 if (found == connections_.end()) 148 if (found == connections_.end())
192 return NULL; 149 return NULL;
193 return found->second.namespace_.get(); 150 return found->second.namespace_.get();
194 } 151 }
195 152
196 void DOMStorageHost::MaybeLogTransaction(
197 int connection_id,
198 DOMStorageNamespace::LogType transaction_type,
199 const GURL& origin,
200 const GURL& page_url,
201 const base::string16& key,
202 const base::NullableString16& value) {
203 DOMStorageNamespace* ns = GetNamespace(connection_id);
204 DCHECK(ns);
205 if (!ns->IsLoggingRenderer(render_process_id_))
206 return;
207 DOMStorageNamespace::TransactionRecord transaction;
208 transaction.transaction_type = transaction_type;
209 transaction.origin = origin;
210 transaction.page_url = page_url;
211 transaction.key = key;
212 transaction.value = value;
213 ns->AddTransaction(render_process_id_, transaction);
214 }
215
216 // NamespaceAndArea 153 // NamespaceAndArea
217 154
218 DOMStorageHost::NamespaceAndArea::NamespaceAndArea() {} 155 DOMStorageHost::NamespaceAndArea::NamespaceAndArea() {}
219 DOMStorageHost::NamespaceAndArea::~NamespaceAndArea() {} 156 DOMStorageHost::NamespaceAndArea::~NamespaceAndArea() {}
220 157
221 } // namespace content 158 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_host.h ('k') | content/browser/dom_storage/dom_storage_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698