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_
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "content/common/content_export.h"
20 class DOMStorageTaskRunner
;
21 class SessionStorageDatabase
;
23 // Container for the set of per-origin Areas.
24 // See class comments for DOMStorageContextImpl for a larger overview.
25 class CONTENT_EXPORT DOMStorageNamespace
26 : public base::RefCountedThreadSafe
<DOMStorageNamespace
> {
28 // Option for PurgeMemory.
30 // Purge unopened areas only.
33 // Purge aggressively, i.e. discard cache even for areas that have
34 // non-zero open count.
38 // Constructor for a LocalStorage namespace with id of 0
39 // and an optional backing directory on disk.
40 DOMStorageNamespace(const base::FilePath
& directory
, // may be empty
41 DOMStorageTaskRunner
* task_runner
);
43 // Constructor for a SessionStorage namespace with a non-zero id and an
44 // optional backing on disk via |session_storage_database| (may be NULL).
45 DOMStorageNamespace(int64 namespace_id
,
46 const std::string
& persistent_namespace_id
,
47 SessionStorageDatabase
* session_storage_database
,
48 DOMStorageTaskRunner
* task_runner
);
50 int64
namespace_id() const { return namespace_id_
; }
51 const std::string
& persistent_namespace_id() const {
52 return persistent_namespace_id_
;
55 // Returns the storage area for the given origin,
56 // creating instance if needed. Each call to open
57 // must be balanced with a call to CloseStorageArea.
58 DOMStorageArea
* OpenStorageArea(const GURL
& origin
);
59 void CloseStorageArea(DOMStorageArea
* area
);
61 // Returns the area for |origin| if it's open, otherwise NULL.
62 DOMStorageArea
* GetOpenStorageArea(const GURL
& origin
);
64 // Creates a clone of |this| namespace including
65 // shallow copies of all contained areas.
66 // Should only be called for session storage namespaces.
67 DOMStorageNamespace
* Clone(int64 clone_namespace_id
,
68 const std::string
& clone_persistent_namespace_id
);
70 void DeleteLocalStorageOrigin(const GURL
& origin
);
71 void DeleteSessionStorageOrigin(const GURL
& origin
);
72 void PurgeMemory(PurgeOption purge
);
76 unsigned int CountInMemoryAreas() const;
79 friend class base::RefCountedThreadSafe
<DOMStorageNamespace
>;
81 // Struct to hold references to our contained areas and
82 // to keep track of how many tabs have a given area open.
84 scoped_refptr
<DOMStorageArea
> area_
;
87 AreaHolder(DOMStorageArea
* area
, int count
);
90 typedef std::map
<GURL
, AreaHolder
> AreaMap
;
92 ~DOMStorageNamespace();
94 // Returns a pointer to the area holder in our map or NULL.
95 AreaHolder
* GetAreaHolder(const GURL
& origin
);
98 std::string persistent_namespace_id_
;
99 base::FilePath directory_
;
101 scoped_refptr
<DOMStorageTaskRunner
> task_runner_
;
102 scoped_refptr
<SessionStorageDatabase
> session_storage_database_
;
105 } // namespace content
108 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_