summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/renderer_webstoragenamespace_impl.cc
blob: 41a8c6c9c8b9fb4585dd31b0bcf3f3dc927c09a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2009 The Chromium Authors. All rights reserved.  Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.

#include "chrome/renderer/renderer_webstoragenamespace_impl.h"

#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/renderer_webstoragearea_impl.h"

using WebKit::WebStorageArea;
using WebKit::WebStorageNamespace;
using WebKit::WebString;

RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl(
    DOMStorageType storage_type)
    : storage_type_(storage_type),
      namespace_id_(kUninitializedNamespaceId) {
}

RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl(
    DOMStorageType storage_type, int64 namespace_id)
    : storage_type_(storage_type),
      namespace_id_(namespace_id) {
  DCHECK(namespace_id_ != kUninitializedNamespaceId);
}

RendererWebStorageNamespaceImpl::~RendererWebStorageNamespaceImpl() {
}

WebStorageArea* RendererWebStorageNamespaceImpl::createStorageArea(
    const WebString& origin) {
  // This could be done async in the background (started when this class is
  // first instantiated) rather than lazily on first use, but it's unclear
  // whether it's worth the complexity.
  if (namespace_id_ == kUninitializedNamespaceId) {
    RenderThread::current()->Send(
        new ViewHostMsg_DOMStorageNamespaceId(storage_type_,
                                              &namespace_id_));
    DCHECK(namespace_id_ != kUninitializedNamespaceId);
  }
  // Ideally, we'd keep a hash map of origin to these objects.  Unfortunately
  // this doesn't seem practical because there's no good way to ref-count these
  // objects, and it'd be unclear who owned them.  So, instead, we'll pay a
  // price for an allocaiton and IPC for each.
  return new RendererWebStorageAreaImpl(namespace_id_, origin);
}

WebStorageNamespace* RendererWebStorageNamespaceImpl::copy() {
  // If we haven't been used yet, we might as well start out fresh (and lazy).
  if (namespace_id_ == kUninitializedNamespaceId)
    return new RendererWebStorageNamespaceImpl(storage_type_);

  // This cannot easily be deferred because we need a snapshot in time.
  int64 new_namespace_id;
  RenderThread::current()->Send(
      new ViewHostMsg_DOMStorageCloneNamespaceId(namespace_id_,
                                                 &new_namespace_id));
  return new RendererWebStorageNamespaceImpl(storage_type_,
                                             new_namespace_id);
}

void RendererWebStorageNamespaceImpl::close() {
  // This is called only on LocalStorage namespaces when WebKit thinks its
  // shutting down.  This has no impact on Chromium.
}