summaryrefslogtreecommitdiffstats
path: root/webkit/dom_storage/dom_storage_map.h
blob: 5610824a10227a866f8561544372c105d4f2db62 (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
// Copyright (c) 2012 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 WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_
#define WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_
#pragma once

#include <map>

#include "base/memory/ref_counted.h"
#include "base/nullable_string16.h"
#include "base/string16.h"
#include "webkit/dom_storage/dom_storage_types.h"

class FilePath;
class GURL;

namespace dom_storage {

// A wrapper around a std::map that adds refcounting and
// imposes a limit on the total byte size of the keys/values.
// See class comments for DomStorageContext for a larger overview.
class DomStorageMap
    : public base::RefCountedThreadSafe<DomStorageMap> {
 public:
  DomStorageMap();

  unsigned Length() const;
  NullableString16 Key(unsigned index);
  NullableString16 GetItem(const string16& key) const;
  bool SetItem(const string16& key, const string16& value,
               NullableString16* old_value);
  bool RemoveItem(const string16& key, string16* old_value);

  void SwapValues(ValuesMap* map);
  DomStorageMap* DeepCopy() const;

 private:
  friend class base::RefCountedThreadSafe<DomStorageMap>;
  ~DomStorageMap();

  void ResetKeyIterator();

  ValuesMap values_;
  ValuesMap::const_iterator key_iterator_;
  unsigned last_key_index_;
  // TODO(benm): track usage and enforce a quota limit.
};

}  // namespace dom_storage

#endif  // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_