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

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

Issue 10086018: More DomStorage house cleaning (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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
(Empty)
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
3 // LICENSE file.
4
5 #include "content/browser/in_process_webkit/dom_storage_namespace.h"
6
7 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND
8 // This class is no longer applicable.
9 #else
10
11 #include "base/file_path.h"
12 #include "content/browser/in_process_webkit/dom_storage_area.h"
13 #include "content/browser/in_process_webkit/dom_storage_context_impl.h"
14 #include "content/browser/in_process_webkit/dom_storage_message_filter.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h "
17 #include "webkit/glue/webkit_glue.h"
18
19 using WebKit::WebStorageArea;
20 using WebKit::WebStorageNamespace;
21 using WebKit::WebString;
22
23 /* static */
24 DOMStorageNamespace* DOMStorageNamespace::CreateLocalStorageNamespace(
25 DOMStorageContextImpl* dom_storage_context, const FilePath& data_dir_path) {
26 int64 id = kLocalStorageNamespaceId;
27 DCHECK(!dom_storage_context->GetStorageNamespace(id, false));
28 return new DOMStorageNamespace(dom_storage_context, id,
29 webkit_glue::FilePathToWebString(data_dir_path), DOM_STORAGE_LOCAL);
30 }
31
32 /* static */
33 DOMStorageNamespace* DOMStorageNamespace::CreateSessionStorageNamespace(
34 DOMStorageContextImpl* dom_storage_context, int64 id) {
35 DCHECK(!dom_storage_context->GetStorageNamespace(id, false));
36 return new DOMStorageNamespace(dom_storage_context, id, WebString(),
37 DOM_STORAGE_SESSION);
38 }
39
40 DOMStorageNamespace::DOMStorageNamespace(
41 DOMStorageContextImpl* dom_storage_context,
42 int64 id,
43 const WebString& data_dir_path,
44 DOMStorageType dom_storage_type)
45 : dom_storage_context_(dom_storage_context),
46 id_(id),
47 data_dir_path_(data_dir_path),
48 dom_storage_type_(dom_storage_type) {
49 DCHECK(dom_storage_context_);
50 }
51
52 DOMStorageNamespace::~DOMStorageNamespace() {
53 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need
54 // to do these calls. Maybe we should add a fast path?
55 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin());
56 iter != origin_to_storage_area_.end(); ++iter) {
57 dom_storage_context_->UnregisterStorageArea(iter->second);
58 delete iter->second;
59 }
60 }
61
62 DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) {
63 // We may have already created it for another dispatcher host.
64 OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin);
65 if (iter != origin_to_storage_area_.end())
66 return iter->second;
67
68 // We need to create a new one.
69 int64 id = dom_storage_context_->AllocateStorageAreaId();
70 DCHECK(!dom_storage_context_->GetStorageArea(id));
71 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this);
72 origin_to_storage_area_[origin] = storage_area;
73 dom_storage_context_->RegisterStorageArea(storage_area);
74 return storage_area;
75 }
76
77 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) {
78 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION);
79 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false));
80 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace(
81 dom_storage_context_, id, data_dir_path_, dom_storage_type_);
82 // If we haven't used the namespace yet, there's nothing to copy.
83 if (storage_namespace_.get())
84 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy());
85 return new_storage_namespace;
86 }
87
88 void DOMStorageNamespace::PurgeMemory() {
89 DCHECK(dom_storage_type_ == DOM_STORAGE_LOCAL);
90 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin());
91 iter != origin_to_storage_area_.end(); ++iter)
92 iter->second->PurgeMemory();
93 storage_namespace_.reset();
94 }
95
96 WebStorageArea* DOMStorageNamespace::CreateWebStorageArea(
97 const string16& origin) {
98 CreateWebStorageNamespaceIfNecessary();
99 return storage_namespace_->createStorageArea(origin);
100 }
101
102 void DOMStorageNamespace::CreateWebStorageNamespaceIfNecessary() {
103 if (storage_namespace_.get())
104 return;
105
106 if (dom_storage_type_ == DOM_STORAGE_LOCAL) {
107 storage_namespace_.reset(
108 WebStorageNamespace::createLocalStorageNamespace(data_dir_path_,
109 WebStorageNamespace::m_localStorageQuota));
110 } else {
111 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace(
112 WebStorageNamespace::m_sessionStorageQuota));
113 }
114 }
115
116 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND
117
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/dom_storage_namespace.h ('k') | content/browser/in_process_webkit/dom_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698