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

Side by Side Diff: content/browser/in_process_webkit/dom_storage_namespace.cc

Issue 7480041: Adding session-only localStorage. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Oops. Fixing unit_tests which didn't build after the previous change. Created 9 years, 4 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
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 DOMStorageNamespace::~DOMStorageNamespace() { 47 DOMStorageNamespace::~DOMStorageNamespace() {
48 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need 48 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need
49 // to do these calls. Maybe we should add a fast path? 49 // to do these calls. Maybe we should add a fast path?
50 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); 50 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin());
51 iter != origin_to_storage_area_.end(); ++iter) { 51 iter != origin_to_storage_area_.end(); ++iter) {
52 dom_storage_context_->UnregisterStorageArea(iter->second); 52 dom_storage_context_->UnregisterStorageArea(iter->second);
53 delete iter->second; 53 delete iter->second;
54 } 54 }
55 } 55 }
56 56
57 DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) { 57 DOMStorageArea* DOMStorageNamespace::GetStorageArea(
58 const string16& origin,
59 bool enforce_session_only_storage) {
58 // We may have already created it for another dispatcher host. 60 // We may have already created it for another dispatcher host.
59 OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); 61 DOMStorageArea* storage_area = GetExistingStorageArea(origin);
60 if (iter != origin_to_storage_area_.end()) 62 if (storage_area)
61 return iter->second; 63 return storage_area;
62 64
63 // We need to create a new one. 65 // Also, our session-only sibling might have it. (This is independent of what
64 int64 id = dom_storage_context_->AllocateStorageAreaId(); 66 // the content settings say; it might be that the settings were changed after
65 DCHECK(!dom_storage_context_->GetStorageArea(id)); 67 // the DOMStorageArea was created.)
66 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); 68 if (session_only_local_storage_.get()) {
67 origin_to_storage_area_[origin] = storage_area; 69 storage_area = session_only_local_storage_->GetExistingStorageArea(origin);
68 dom_storage_context_->RegisterStorageArea(storage_area); 70 if (storage_area)
69 return storage_area; 71 return storage_area;
72 }
73
74 // Else, we need to create a new DOMStorageArea.
75 if (enforce_session_only_storage && ShouldHaveSessionOnlyLocalStorage()) {
76 EnsureSessionOnlyLocalStorageCreated();
77 return session_only_local_storage_->CreateStorageArea(origin);
78 }
79 return CreateStorageArea(origin);
70 } 80 }
71 81
72 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { 82 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) {
73 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION); 83 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION);
74 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false)); 84 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false));
75 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace( 85 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace(
76 dom_storage_context_, id, data_dir_path_, dom_storage_type_); 86 dom_storage_context_, id, data_dir_path_, dom_storage_type_);
77 // If we haven't used the namespace yet, there's nothing to copy. 87 // If we haven't used the namespace yet, there's nothing to copy.
78 if (storage_namespace_.get()) 88 if (storage_namespace_.get())
79 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy()); 89 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy());
(...skipping 20 matching lines...) Expand all
100 110
101 if (dom_storage_type_ == DOM_STORAGE_LOCAL) { 111 if (dom_storage_type_ == DOM_STORAGE_LOCAL) {
102 storage_namespace_.reset( 112 storage_namespace_.reset(
103 WebStorageNamespace::createLocalStorageNamespace(data_dir_path_, 113 WebStorageNamespace::createLocalStorageNamespace(data_dir_path_,
104 WebStorageNamespace::m_localStorageQuota)); 114 WebStorageNamespace::m_localStorageQuota));
105 } else { 115 } else {
106 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace( 116 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace(
107 WebStorageNamespace::m_sessionStorageQuota)); 117 WebStorageNamespace::m_sessionStorageQuota));
108 } 118 }
109 } 119 }
120
121 DOMStorageArea* DOMStorageNamespace::GetExistingStorageArea(
122 const string16& origin) {
123 OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin);
124 if (iter != origin_to_storage_area_.end())
125 return iter->second;
126 return NULL;
127 }
128
129 DOMStorageArea* DOMStorageNamespace::CreateStorageArea(const string16& origin) {
130 int64 id = dom_storage_context_->AllocateStorageAreaId();
131 DCHECK(!dom_storage_context_->GetStorageArea(id));
132 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this);
133 origin_to_storage_area_[origin] = storage_area;
134 dom_storage_context_->RegisterStorageArea(storage_area);
135 return storage_area;
136 }
137
138 bool DOMStorageNamespace::ShouldHaveSessionOnlyLocalStorage() const {
139 if (dom_storage_type_ == DOM_STORAGE_LOCAL && !data_dir_path_.isEmpty()) {
140 // This DOMStorageNamespace represents a permanent localStorage; it should
141 // have a sibling DOMStorageNamespace that represents the corresponding
142 // session-only storage.
143 return true;
michaeln 2011/08/04 20:21:51 maybe simplify as return (type == LOCAL) && !path.
marja 2011/08/05 13:15:53 Done.
144 }
145 return false;
146 }
147
148 void DOMStorageNamespace::EnsureSessionOnlyLocalStorageCreated() {
149 if (session_only_local_storage_.get() == NULL) {
150 session_only_local_storage_.reset(
151 new DOMStorageNamespace(dom_storage_context_,
152 id_,
153 WebString(),
154 dom_storage_type_));
155 }
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698