Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / dom_storage / dom_storage_namespace.h
blob5860685f8077ff6675bfbc686238122005cf2e1e
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "content/common/content_export.h"
14 #include "url/gurl.h"
16 namespace content {
18 class DOMStorageArea;
19 class DOMStorageTaskRunner;
20 class SessionStorageDatabase;
22 // Container for the set of per-origin Areas.
23 // See class comments for DOMStorageContextImpl for a larger overview.
24 class CONTENT_EXPORT DOMStorageNamespace
25 : public base::RefCountedThreadSafe<DOMStorageNamespace> {
26 public:
27 // Option for PurgeMemory.
28 enum PurgeOption {
29 // Purge unopened areas only.
30 PURGE_UNOPENED,
32 // Purge aggressively, i.e. discard cache even for areas that have
33 // non-zero open count.
34 PURGE_AGGRESSIVE,
37 // Constructor for a LocalStorage namespace with id of 0
38 // and an optional backing directory on disk.
39 DOMStorageNamespace(const base::FilePath& directory, // may be empty
40 DOMStorageTaskRunner* task_runner);
42 // Constructor for a SessionStorage namespace with a non-zero id and an
43 // optional backing on disk via |session_storage_database| (may be NULL).
44 DOMStorageNamespace(int64 namespace_id,
45 const std::string& persistent_namespace_id,
46 SessionStorageDatabase* session_storage_database,
47 DOMStorageTaskRunner* task_runner);
49 int64 namespace_id() const { return namespace_id_; }
50 const std::string& persistent_namespace_id() const {
51 return persistent_namespace_id_;
54 // Returns the storage area for the given origin,
55 // creating instance if needed. Each call to open
56 // must be balanced with a call to CloseStorageArea.
57 DOMStorageArea* OpenStorageArea(const GURL& origin);
58 void CloseStorageArea(DOMStorageArea* area);
60 // Returns the area for |origin| if it's open, otherwise NULL.
61 DOMStorageArea* GetOpenStorageArea(const GURL& origin);
63 // Creates a clone of |this| namespace including
64 // shallow copies of all contained areas.
65 // Should only be called for session storage namespaces.
66 DOMStorageNamespace* Clone(int64 clone_namespace_id,
67 const std::string& clone_persistent_namespace_id);
69 void DeleteLocalStorageOrigin(const GURL& origin);
70 void DeleteSessionStorageOrigin(const GURL& origin);
71 void PurgeMemory(PurgeOption purge);
72 void Shutdown();
74 unsigned int CountInMemoryAreas() const;
76 private:
77 friend class base::RefCountedThreadSafe<DOMStorageNamespace>;
79 // Struct to hold references to our contained areas and
80 // to keep track of how many tabs have a given area open.
81 struct AreaHolder {
82 scoped_refptr<DOMStorageArea> area_;
83 int open_count_;
84 AreaHolder();
85 AreaHolder(DOMStorageArea* area, int count);
86 ~AreaHolder();
88 typedef std::map<GURL, AreaHolder> AreaMap;
90 ~DOMStorageNamespace();
92 // Returns a pointer to the area holder in our map or NULL.
93 AreaHolder* GetAreaHolder(const GURL& origin);
95 int64 namespace_id_;
96 std::string persistent_namespace_id_;
97 base::FilePath directory_;
98 AreaMap areas_;
99 scoped_refptr<DOMStorageTaskRunner> task_runner_;
100 scoped_refptr<SessionStorageDatabase> session_storage_database_;
103 } // namespace content
106 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_