OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 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 "chrome/renderer/renderer_webstoragenamespace_impl.h" | 5 #include "chrome/renderer/renderer_webstoragenamespace_impl.h" |
6 | 6 |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/renderer/render_thread.h" | 8 #include "chrome/renderer/render_thread.h" |
9 #include "chrome/renderer/renderer_webstoragearea_impl.h" | 9 #include "chrome/renderer/renderer_webstoragearea_impl.h" |
10 | 10 |
11 using WebKit::WebStorageArea; | 11 using WebKit::WebStorageArea; |
12 using WebKit::WebStorageNamespace; | 12 using WebKit::WebStorageNamespace; |
13 using WebKit::WebString; | 13 using WebKit::WebString; |
14 | 14 |
15 RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl( | 15 RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl( |
16 DOMStorageType storage_type) | 16 DOMStorageType storage_type) |
17 : storage_type_(storage_type), | 17 : storage_type_(storage_type), |
18 namespace_id_(kUninitializedNamespaceId) { | 18 namespace_id_(kLocalStorageNamespaceId) { |
| 19 DCHECK(storage_type == DOM_STORAGE_LOCAL); |
19 } | 20 } |
20 | 21 |
21 RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl( | 22 RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl( |
22 DOMStorageType storage_type, int64 namespace_id) | 23 DOMStorageType storage_type, int64 namespace_id) |
23 : storage_type_(storage_type), | 24 : storage_type_(storage_type), |
24 namespace_id_(namespace_id) { | 25 namespace_id_(namespace_id) { |
25 DCHECK(namespace_id_ != kUninitializedNamespaceId); | 26 DCHECK(storage_type == DOM_STORAGE_SESSION); |
26 } | 27 } |
27 | 28 |
28 RendererWebStorageNamespaceImpl::~RendererWebStorageNamespaceImpl() { | 29 RendererWebStorageNamespaceImpl::~RendererWebStorageNamespaceImpl() { |
29 } | 30 } |
30 | 31 |
31 WebStorageArea* RendererWebStorageNamespaceImpl::createStorageArea( | 32 WebStorageArea* RendererWebStorageNamespaceImpl::createStorageArea( |
32 const WebString& origin) { | 33 const WebString& origin) { |
33 // This could be done async in the background (started when this class is | |
34 // first instantiated) rather than lazily on first use, but it's unclear | |
35 // whether it's worth the complexity. | |
36 if (namespace_id_ == kUninitializedNamespaceId) { | |
37 RenderThread::current()->Send( | |
38 new ViewHostMsg_DOMStorageNamespaceId(storage_type_, | |
39 &namespace_id_)); | |
40 DCHECK(namespace_id_ != kUninitializedNamespaceId); | |
41 } | |
42 // Ideally, we'd keep a hash map of origin to these objects. Unfortunately | 34 // Ideally, we'd keep a hash map of origin to these objects. Unfortunately |
43 // this doesn't seem practical because there's no good way to ref-count these | 35 // this doesn't seem practical because there's no good way to ref-count these |
44 // objects, and it'd be unclear who owned them. So, instead, we'll pay a | 36 // objects, and it'd be unclear who owned them. So, instead, we'll pay the |
45 // price for an allocaiton and IPC for each. | 37 // price in terms of wasted memory. |
46 return new RendererWebStorageAreaImpl(namespace_id_, origin); | 38 return new RendererWebStorageAreaImpl(namespace_id_, origin); |
47 } | 39 } |
48 | 40 |
49 WebStorageNamespace* RendererWebStorageNamespaceImpl::copy() { | 41 WebStorageNamespace* RendererWebStorageNamespaceImpl::copy() { |
50 // If we haven't been used yet, we might as well start out fresh (and lazy). | 42 NOTREACHED(); // We shouldn't ever reach this code in Chromium. |
51 if (namespace_id_ == kUninitializedNamespaceId) | 43 return NULL; |
52 return new RendererWebStorageNamespaceImpl(storage_type_); | |
53 | |
54 // This cannot easily be deferred because we need a snapshot in time. | |
55 int64 new_namespace_id; | |
56 RenderThread::current()->Send( | |
57 new ViewHostMsg_DOMStorageCloneNamespaceId(namespace_id_, | |
58 &new_namespace_id)); | |
59 return new RendererWebStorageNamespaceImpl(storage_type_, | |
60 new_namespace_id); | |
61 } | 44 } |
62 | 45 |
63 void RendererWebStorageNamespaceImpl::close() { | 46 void RendererWebStorageNamespaceImpl::close() { |
64 // This is called only on LocalStorage namespaces when WebKit thinks its | 47 // This is called only on LocalStorage namespaces when WebKit thinks its |
65 // shutting down. This has no impact on Chromium. | 48 // shutting down. This has no impact on Chromium. |
66 } | 49 } |
OLD | NEW |