Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / dom_storage / dom_storage_session.h
blob065e75d5eb38178abbb3a928229f98e8d57b06ad
1 // Copyright (c) 2012 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 WEBKIT_DOM_STORAGE_DOM_STORAGE_SESSION_H_
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_SESSION_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "webkit/storage/webkit_storage_export.h"
14 namespace dom_storage {
16 class DomStorageContext;
18 // This refcounted class determines the lifetime of a session
19 // storage namespace and provides an interface to Clone() an
20 // existing session storage namespace. It may be used on any thread.
21 // See class comments for DomStorageContext for a larger overview.
22 class WEBKIT_STORAGE_EXPORT DomStorageSession
23 : public base::RefCountedThreadSafe<DomStorageSession> {
24 public:
25 // Constructs a |DomStorageSession| and allocates new IDs for it.
26 explicit DomStorageSession(DomStorageContext* context);
28 // Constructs a |DomStorageSession| and assigns |persistent_namespace_id|
29 // to it. Allocates a new non-persistent ID.
30 DomStorageSession(DomStorageContext* context,
31 const std::string& persistent_namespace_id);
33 int64 namespace_id() const { return namespace_id_; }
34 const std::string& persistent_namespace_id() const {
35 return persistent_namespace_id_;
37 void SetShouldPersist(bool should_persist);
38 bool should_persist() const;
39 bool IsFromContext(DomStorageContext* context);
40 DomStorageSession* Clone();
42 // Constructs a |DomStorageSession| by cloning
43 // |namespace_id_to_clone|. Allocates new IDs for it.
44 static DomStorageSession* CloneFrom(DomStorageContext* context,
45 int64 namepace_id_to_clone);
47 private:
48 friend class base::RefCountedThreadSafe<DomStorageSession>;
50 DomStorageSession(DomStorageContext* context,
51 int64 namespace_id,
52 const std::string& persistent_namespace_id);
53 ~DomStorageSession();
55 scoped_refptr<DomStorageContext> context_;
56 int64 namespace_id_;
57 std::string persistent_namespace_id_;
58 bool should_persist_;
60 DISALLOW_IMPLICIT_CONSTRUCTORS(DomStorageSession);
63 } // namespace dom_storage
65 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_SESSION_H_