OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include "content/browser/in_process_webkit/dom_storage_namespace.h" | 5 #include "content/browser/in_process_webkit/dom_storage_namespace.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "content/browser/in_process_webkit/dom_storage_area.h" | 8 #include "content/browser/in_process_webkit/dom_storage_area.h" |
9 #include "content/browser/in_process_webkit/dom_storage_context.h" | 9 #include "content/browser/in_process_webkit/dom_storage_context.h" |
10 #include "content/browser/in_process_webkit/dom_storage_message_filter.h" | 10 #include "content/browser/in_process_webkit/dom_storage_message_filter.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 } | 34 } |
35 | 35 |
36 DOMStorageNamespace::DOMStorageNamespace(DOMStorageContext* dom_storage_context, | 36 DOMStorageNamespace::DOMStorageNamespace(DOMStorageContext* dom_storage_context, |
37 int64 id, | 37 int64 id, |
38 const WebString& data_dir_path, | 38 const WebString& data_dir_path, |
39 DOMStorageType dom_storage_type) | 39 DOMStorageType dom_storage_type) |
40 : dom_storage_context_(dom_storage_context), | 40 : dom_storage_context_(dom_storage_context), |
41 id_(id), | 41 id_(id), |
42 data_dir_path_(data_dir_path), | 42 data_dir_path_(data_dir_path), |
43 dom_storage_type_(dom_storage_type) { | 43 dom_storage_type_(dom_storage_type) { |
44 if (dom_storage_type == DOM_STORAGE_LOCAL && !data_dir_path.isEmpty()) { | |
45 // This DOMStorageNamespace represents a permanent localStorage; create a | |
46 // sibling namespace that represents the corresponding session-only storage. | |
47 session_only_local_storage_.reset( | |
michaeln
2011/08/02 19:47:41
can this be more lazily created, i imagine most us
marja
2011/08/03 09:14:15
Done.
| |
48 new DOMStorageNamespace(dom_storage_context, | |
49 id, | |
50 WebString(), | |
51 dom_storage_type)); | |
52 } | |
44 DCHECK(dom_storage_context_); | 53 DCHECK(dom_storage_context_); |
45 } | 54 } |
46 | 55 |
47 DOMStorageNamespace::~DOMStorageNamespace() { | 56 DOMStorageNamespace::~DOMStorageNamespace() { |
48 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need | 57 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need |
49 // to do these calls. Maybe we should add a fast path? | 58 // to do these calls. Maybe we should add a fast path? |
50 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); | 59 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); |
51 iter != origin_to_storage_area_.end(); ++iter) { | 60 iter != origin_to_storage_area_.end(); ++iter) { |
52 dom_storage_context_->UnregisterStorageArea(iter->second); | 61 dom_storage_context_->UnregisterStorageArea(iter->second); |
53 delete iter->second; | 62 delete iter->second; |
54 } | 63 } |
55 } | 64 } |
56 | 65 |
57 DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) { | 66 DOMStorageArea* DOMStorageNamespace::GetStorageArea( |
67 const string16& origin, | |
68 bool allow_permanent_storage) { | |
58 // We may have already created it for another dispatcher host. | 69 // We may have already created it for another dispatcher host. |
59 OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); | 70 DOMStorageArea* storage_area = GetExistingStorageArea(origin); |
60 if (iter != origin_to_storage_area_.end()) | 71 if (storage_area) |
61 return iter->second; | 72 return storage_area; |
62 | 73 |
63 // We need to create a new one. | 74 // Also, our session-only sibling might have it. (This is independent of what |
64 int64 id = dom_storage_context_->AllocateStorageAreaId(); | 75 // the content settings say; it might be that the settings were changed after |
65 DCHECK(!dom_storage_context_->GetStorageArea(id)); | 76 // the DOMStorageArea was created.) |
michaeln
2011/08/02 19:47:41
This blurs the lines between the sessionOnly and l
marja
2011/08/03 09:14:15
I guess that would confuse some web pages, if the
| |
66 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); | 77 if (session_only_local_storage_.get()) { |
67 origin_to_storage_area_[origin] = storage_area; | 78 storage_area = session_only_local_storage_->GetExistingStorageArea(origin); |
68 dom_storage_context_->RegisterStorageArea(storage_area); | 79 if (storage_area) |
69 return storage_area; | 80 return storage_area; |
81 } | |
82 | |
83 // Else, we need to create a new DOMStorageArea. | |
84 if (!allow_permanent_storage && session_only_local_storage_.get()) { | |
85 return session_only_local_storage_->CreateStorageArea(origin); | |
86 } | |
87 return CreateStorageArea(origin); | |
70 } | 88 } |
71 | 89 |
72 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { | 90 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { |
73 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION); | 91 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION); |
74 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false)); | 92 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false)); |
75 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace( | 93 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace( |
76 dom_storage_context_, id, data_dir_path_, dom_storage_type_); | 94 dom_storage_context_, id, data_dir_path_, dom_storage_type_); |
77 // If we haven't used the namespace yet, there's nothing to copy. | 95 // If we haven't used the namespace yet, there's nothing to copy. |
78 if (storage_namespace_.get()) | 96 if (storage_namespace_.get()) |
79 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy()); | 97 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy()); |
(...skipping 20 matching lines...) Expand all Loading... | |
100 | 118 |
101 if (dom_storage_type_ == DOM_STORAGE_LOCAL) { | 119 if (dom_storage_type_ == DOM_STORAGE_LOCAL) { |
102 storage_namespace_.reset( | 120 storage_namespace_.reset( |
103 WebStorageNamespace::createLocalStorageNamespace(data_dir_path_, | 121 WebStorageNamespace::createLocalStorageNamespace(data_dir_path_, |
104 WebStorageNamespace::m_localStorageQuota)); | 122 WebStorageNamespace::m_localStorageQuota)); |
105 } else { | 123 } else { |
106 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace( | 124 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace( |
107 WebStorageNamespace::m_sessionStorageQuota)); | 125 WebStorageNamespace::m_sessionStorageQuota)); |
108 } | 126 } |
109 } | 127 } |
128 | |
129 DOMStorageArea* DOMStorageNamespace::GetExistingStorageArea( | |
130 const string16& origin) { | |
131 OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); | |
132 if (iter != origin_to_storage_area_.end()) | |
133 return iter->second; | |
134 return NULL; | |
135 } | |
136 | |
137 DOMStorageArea* DOMStorageNamespace::CreateStorageArea(const string16& origin) { | |
138 int64 id = dom_storage_context_->AllocateStorageAreaId(); | |
139 DCHECK(!dom_storage_context_->GetStorageArea(id)); | |
140 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); | |
141 origin_to_storage_area_[origin] = storage_area; | |
142 dom_storage_context_->RegisterStorageArea(storage_area); | |
143 return storage_area; | |
144 } | |
OLD | NEW |