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_SESSION_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_SESSION_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
13 #include "content/common/content_export.h"
17 class DOMStorageContextImpl;
19 // This refcounted class determines the lifetime of a session
20 // storage namespace and provides an interface to Clone() an
21 // existing session storage namespace. It may be used on any thread.
22 // See class comments for DOMStorageContextImpl for a larger overview.
23 class CONTENT_EXPORT DOMStorageSession
24 : public base::RefCountedThreadSafe<DOMStorageSession> {
26 // Constructs a |DOMStorageSession| and allocates new IDs for it.
27 explicit DOMStorageSession(DOMStorageContextImpl* context);
29 // Constructs a |DOMStorageSession| and assigns |persistent_namespace_id|
30 // to it. Allocates a new non-persistent ID.
31 DOMStorageSession(DOMStorageContextImpl* context,
32 const std::string& persistent_namespace_id);
34 int64 namespace_id() const { return namespace_id_; }
35 const std::string& persistent_namespace_id() const {
36 return persistent_namespace_id_;
38 void SetShouldPersist(bool should_persist);
39 bool should_persist() const;
40 bool IsFromContext(DOMStorageContextImpl* context);
41 DOMStorageSession* Clone();
43 // Constructs a |DOMStorageSession| by cloning
44 // |namespace_id_to_clone|. Allocates new IDs for it.
45 static DOMStorageSession* CloneFrom(DOMStorageContextImpl* context,
46 int64 namepace_id_to_clone);
48 void AddTransactionLogProcessId(int process_id);
49 void RemoveTransactionLogProcessId(int process_id);
50 void CanMerge(int process_id,
51 DOMStorageSession* other,
52 const SessionStorageNamespace::MergeResultCallback& callback);
55 friend class base::RefCountedThreadSafe<DOMStorageSession>;
57 DOMStorageSession(DOMStorageContextImpl* context,
59 const std::string& persistent_namespace_id);
62 scoped_refptr<DOMStorageContextImpl> context_;
64 std::string persistent_namespace_id_;
67 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageSession);
70 } // namespace content
72 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_SESSION_H_