summaryrefslogtreecommitdiffstats
path: root/chrome/browser/in_process_webkit/storage_area.h
blob: 7875137146a507ea18e952660ae0e1b7adecb612 (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
67
68
// 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.

#ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_STORAGE_AREA_H_
#define CHROME_BROWSER_IN_PROCESS_WEBKIT_STORAGE_AREA_H_

#include "base/hash_tables.h"
#include "base/nullable_string16.h"
#include "base/scoped_ptr.h"

class StorageNamespace;

namespace WebKit {
class WebStorageArea;
}

// Only use on the WebKit thread.  StorageNamespace manages our registration
// with DOMStorageContext.
class StorageArea {
 public:
  StorageArea(const string16& origin, int64 id, StorageNamespace* owner);
  ~StorageArea();

  unsigned Length();
  NullableString16 Key(unsigned index);
  NullableString16 GetItem(const string16& key);
  void SetItem(const string16& key, const string16& value,
               bool* quota_xception);
  void RemoveItem(const string16& key);
  void Clear();
  void PurgeMemory();

  int64 id() const { return id_; }

 private:
  // Creates the underlying WebStorageArea on demand.
  void CreateWebStorageAreaIfNecessary();

  // The origin this storage area represents.
  string16 origin_;

  // The storage area we wrap.
  scoped_ptr<WebKit::WebStorageArea> storage_area_;

  // Our storage area id.  Unique to our parent WebKitContext.
  int64 id_;

  // The StorageNamespace that owns us.
  StorageNamespace* owner_;

  DISALLOW_IMPLICIT_CONSTRUCTORS(StorageArea);
};

#if defined(COMPILER_GCC)
namespace __gnu_cxx {

template<>
struct hash<StorageArea*> {
  std::size_t operator()(StorageArea* const& p) const {
    return reinterpret_cast<std::size_t>(p);
  }
};

}  // namespace __gnu_cxx
#endif

#endif  // CHROME_BROWSER_IN_PROCESS_WEBKIT_STORAGE_AREA_H_