summaryrefslogtreecommitdiffstats
path: root/chrome/browser/in_process_webkit/storage_namespace.h
blob: 856f5de0536b7d2d11220258c5da27b92fcd8be6 (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_NAMESPACE_H_
#define CHROME_BROWSER_IN_PROCESS_WEBKIT_STORAGE_NAMESPACE_H_

#include "base/string16.h"
#include "base/hash_tables.h"
#include "chrome/common/dom_storage_type.h"

class DOMStorageContext;
class FilePath;
class StorageArea;

namespace WebKit {
class WebStorageNamespace;
}

// Only to be used on the WebKit thread.
class StorageNamespace {
 public:
  static StorageNamespace* CreateLocalStorageNamespace(
      DOMStorageContext* dom_storage_context, const FilePath& data_dir_path);
  static StorageNamespace* CreateSessionStorageNamespace(
      DOMStorageContext* dom_storage_context);

  ~StorageNamespace();

  StorageArea* GetStorageArea(const string16& origin);
  StorageNamespace* Copy();
  void Close();

  const DOMStorageContext* dom_storage_context() const {
    return dom_storage_context_;
  }
  int64 id() const { return id_; }
  DOMStorageType dom_storage_type() const { return dom_storage_type_; }

 private:
  // Called by the static factory methods above.
  StorageNamespace(DOMStorageContext* dom_storage_context,
                   WebKit::WebStorageNamespace* web_storage_namespace,
                   int64 id, DOMStorageType storage_type);

  // All the storage areas we own.
  typedef base::hash_map<string16, StorageArea*> OriginToStorageAreaMap;
  OriginToStorageAreaMap origin_to_storage_area_;

  // The DOMStorageContext that owns us.
  DOMStorageContext* dom_storage_context_;

  // The WebKit storage namespace we manage.
  WebKit::WebStorageNamespace* storage_namespace_;

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

  // SessionStorage vs. LocalStorage.
  const DOMStorageType dom_storage_type_;

  // The quota for each storage area.  Suggested by the spec.
  static const unsigned kLocalStorageQuota = 5 * 1024 * 1024;

  DISALLOW_IMPLICIT_CONSTRUCTORS(StorageNamespace);
};

#endif  // CHROME_BROWSER_IN_PROCESS_WEBKIT_STORAGE_NAMESPACE_H_