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

Side by Side Diff: webkit/dom_storage/dom_storage_namespace.cc

Issue 9146025: Framing for a DOMStorage backend that does not depend on in-process-webkit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 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) 2012 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 "webkit/dom_storage/dom_storage_namespace.h"
6 6
7 #include "base/file_path.h" 7 #include "base/basictypes.h"
8 #include "content/browser/in_process_webkit/dom_storage_area.h" 8 #include "base/logging.h"
9 #include "content/browser/in_process_webkit/dom_storage_context.h" 9 #include "webkit/dom_storage/dom_storage_area.h"
10 #include "content/browser/in_process_webkit/dom_storage_message_filter.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h "
13 #include "webkit/glue/webkit_glue.h"
14 10
15 using WebKit::WebStorageArea; 11 namespace dom_storage {
16 using WebKit::WebStorageNamespace;
17 using WebKit::WebString;
18 12
19 /* static */ 13 DomStorageNamespace::DomStorageNamespace(
20 DOMStorageNamespace* DOMStorageNamespace::CreateLocalStorageNamespace( 14 int64 namespace_id,
21 DOMStorageContext* dom_storage_context, const FilePath& data_dir_path) { 15 const FilePath& directory, // may be empty
22 int64 id = kLocalStorageNamespaceId; 16 DomStorageTaskRunner* task_runner)
23 DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); 17 : namespace_id_(namespace_id),
24 return new DOMStorageNamespace(dom_storage_context, id, 18 directory_(directory),
25 webkit_glue::FilePathToWebString(data_dir_path), DOM_STORAGE_LOCAL); 19 task_runner_(task_runner) {
26 } 20 }
27 21
28 /* static */ 22 DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) {
29 DOMStorageNamespace* DOMStorageNamespace::CreateSessionStorageNamespace( 23 if (AreaHolder* holder = GetAreaHolder(origin)) {
30 DOMStorageContext* dom_storage_context, int64 id) { 24 ++(holder->open_count_);
31 DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); 25 return holder->area_;
32 return new DOMStorageNamespace(dom_storage_context, id, WebString(), 26 }
33 DOM_STORAGE_SESSION); 27 // TODO(michaeln): Compute the right filepath.
benm (inactive) 2012/02/02 16:23:19 Do you mean whether there should be a backing file
michaeln 2012/02/03 00:33:42 Done. I see in your CL you've got the 'area' compu
28 DomStorageArea* area = new DomStorageArea(namespace_id_, origin,
29 FilePath(), task_runner_);
30 areas_[origin] = AreaHolder(area, 1);
31 return area;
34 } 32 }
35 33
36 DOMStorageNamespace::DOMStorageNamespace(DOMStorageContext* dom_storage_context, 34 void DomStorageNamespace::CloseStorageArea(DomStorageArea* area) {
37 int64 id, 35 AreaHolder* holder = GetAreaHolder(area->origin());
38 const WebString& data_dir_path, 36 DCHECK(holder);
39 DOMStorageType dom_storage_type) 37 DCHECK_EQ(holder->area_.get(), area);
40 : dom_storage_context_(dom_storage_context), 38 --(holder->open_count_);
41 id_(id), 39 // TODO(michaeln): Clean up areas that aren't needed in memory anymore.
42 data_dir_path_(data_dir_path), 40 // The in-process-webkit based impl didn't do this, but would be nice.
43 dom_storage_type_(dom_storage_type) {
44 DCHECK(dom_storage_context_);
45 } 41 }
46 42
47 DOMStorageNamespace::~DOMStorageNamespace() { 43 DomStorageNamespace* DomStorageNamespace::Clone(int64 clone_namespace_id) {
48 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need 44 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_);
49 // to do these calls. Maybe we should add a fast path? 45 DCHECK_NE(kLocalStorageNamespaceId, clone_namespace_id);
50 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); 46 DomStorageNamespace* clone =
51 iter != origin_to_storage_area_.end(); ++iter) { 47 new DomStorageNamespace(clone_namespace_id, FilePath(), task_runner_);
52 dom_storage_context_->UnregisterStorageArea(iter->second); 48 AreaMap::const_iterator it = areas_.begin();
53 delete iter->second; 49 for (; it != areas_.end(); ++it) {
50 DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id);
51 clone->areas_[it->first] = AreaHolder(area, 0);
54 } 52 }
53 return clone;
55 } 54 }
56 55
57 DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) { 56 DomStorageNamespace::AreaHolder*
58 // We may have already created it for another dispatcher host. 57 DomStorageNamespace::GetAreaHolder(const GURL& origin) {
59 OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); 58 AreaMap::iterator found = areas_.find(origin);
60 if (iter != origin_to_storage_area_.end()) 59 if (found == areas_.end())
61 return iter->second; 60 return NULL;
62 61 return &(found->second);
63 // We need to create a new one.
64 int64 id = dom_storage_context_->AllocateStorageAreaId();
65 DCHECK(!dom_storage_context_->GetStorageArea(id));
66 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this);
67 origin_to_storage_area_[origin] = storage_area;
68 dom_storage_context_->RegisterStorageArea(storage_area);
69 return storage_area;
70 } 62 }
71 63
72 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) {
73 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION);
74 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false));
75 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace(
76 dom_storage_context_, id, data_dir_path_, dom_storage_type_);
77 // If we haven't used the namespace yet, there's nothing to copy.
78 if (storage_namespace_.get())
79 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy());
80 return new_storage_namespace;
81 }
82 64
83 void DOMStorageNamespace::PurgeMemory() { 65 } // namespace dom_storage
84 DCHECK(dom_storage_type_ == DOM_STORAGE_LOCAL);
85 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin());
86 iter != origin_to_storage_area_.end(); ++iter)
87 iter->second->PurgeMemory();
88 storage_namespace_.reset();
89 }
90
91 WebStorageArea* DOMStorageNamespace::CreateWebStorageArea(
92 const string16& origin) {
93 CreateWebStorageNamespaceIfNecessary();
94 return storage_namespace_->createStorageArea(origin);
95 }
96
97 void DOMStorageNamespace::CreateWebStorageNamespaceIfNecessary() {
98 if (storage_namespace_.get())
99 return;
100
101 if (dom_storage_type_ == DOM_STORAGE_LOCAL) {
102 storage_namespace_.reset(
103 WebStorageNamespace::createLocalStorageNamespace(data_dir_path_,
104 WebStorageNamespace::m_localStorageQuota));
105 } else {
106 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace(
107 WebStorageNamespace::m_sessionStorageQuota));
108 }
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698