summaryrefslogtreecommitdiffstats
path: root/content/browser/in_process_webkit/dom_storage_namespace.h
blob: 3abe33436bc2ce10a17079ddf6870a8fb314ed14 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2010 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 CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_NAMESPACE_H_
#define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_NAMESPACE_H_
#pragma once

#include "base/hash_tables.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "content/common/dom_storage_common.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"

class DOMStorageArea;
class DOMStorageContext;
class FilePath;
class HostContentSettingsMap;

namespace WebKit {
class WebStorageArea;
class WebStorageNamespace;
}

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

  ~DOMStorageNamespace();

  DOMStorageArea* GetStorageArea(const string16& origin,
                                 HostContentSettingsMap* map);
  DOMStorageNamespace* Copy(int64 clone_namespace_id);

  void PurgeMemory();

  const DOMStorageContext* dom_storage_context() const {
    return dom_storage_context_;
  }
  int64 id() const { return id_; }
  const WebKit::WebString& data_dir_path() const { return data_dir_path_; }
  DOMStorageType dom_storage_type() const { return dom_storage_type_; }

  // Creates a WebStorageArea for the given origin.  This should only be called
  // by an owned DOMStorageArea.
  WebKit::WebStorageArea* CreateWebStorageArea(const string16& origin);

 private:
  // Called by the static factory methods above.
  DOMStorageNamespace(DOMStorageContext* dom_storage_context,
                      int64 id,
                      const WebKit::WebString& data_dir_path,
                      DOMStorageType storage_type);

  // Creates the underlying WebStorageNamespace on demand.
  void CreateWebStorageNamespaceIfNecessary();

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

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

  // The WebKit storage namespace we manage.
  scoped_ptr<WebKit::WebStorageNamespace> storage_namespace_;

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

  // The path used to create us, so we can recreate our WebStorageNamespace on
  // demand.
  WebKit::WebString data_dir_path_;

  // SessionStorage vs. LocalStorage.
  const DOMStorageType dom_storage_type_;

  DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageNamespace);
};

#endif  // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_NAMESPACE_H_