summaryrefslogtreecommitdiffstats
path: root/chrome/browser/in_process_webkit/storage_area.cc
blob: 1b8ea599ef296c388ecb3d5241e1099271b50a2a (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/browser/in_process_webkit/storage_area.h"

#include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h"
#include "chrome/browser/in_process_webkit/storage_namespace.h"
#include "third_party/WebKit/WebKit/chromium/public/WebStorageArea.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"

using WebKit::WebStorageArea;
using WebKit::WebURL;

StorageArea::StorageArea(const string16& origin,
                         int64 id,
                         StorageNamespace* owner)
    : origin_(origin),
      id_(id),
      owner_(owner) {
  DCHECK(owner_);
}

StorageArea::~StorageArea() {
}

unsigned StorageArea::Length() {
  CreateWebStorageAreaIfNecessary();
  return storage_area_->length();
}

NullableString16 StorageArea::Key(unsigned index) {
  CreateWebStorageAreaIfNecessary();
  return storage_area_->key(index);
}

NullableString16 StorageArea::GetItem(const string16& key) {
  CreateWebStorageAreaIfNecessary();
  return storage_area_->getItem(key);
}

void StorageArea::SetItem(const string16& key, const string16& value,
                          bool* quota_exception) {
  CreateWebStorageAreaIfNecessary();
  storage_area_->setItem(key, value, WebURL(), *quota_exception);
}

void StorageArea::RemoveItem(const string16& key) {
  CreateWebStorageAreaIfNecessary();
  storage_area_->removeItem(key, WebURL());
}

void StorageArea::Clear() {
  CreateWebStorageAreaIfNecessary();
  storage_area_->clear(WebURL());
}

void StorageArea::PurgeMemory() {
  storage_area_.reset();
}

void StorageArea::CreateWebStorageAreaIfNecessary() {
  if (!storage_area_.get())
    storage_area_.reset(owner_->CreateWebStorageArea(origin_));
}