- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / dom_storage / dom_storage_session.h
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.
4
5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_SESSION_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_SESSION_H_
7
8 #include <string>
9
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"
14
15 namespace content {
16
17 class DOMStorageContextImpl;
18
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> {
25  public:
26   // Constructs a |DOMStorageSession| and allocates new IDs for it.
27   explicit DOMStorageSession(DOMStorageContextImpl* context);
28
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);
33
34   int64 namespace_id() const { return namespace_id_; }
35   const std::string& persistent_namespace_id() const {
36     return persistent_namespace_id_;
37   }
38   void SetShouldPersist(bool should_persist);
39   bool should_persist() const;
40   bool IsFromContext(DOMStorageContextImpl* context);
41   DOMStorageSession* Clone();
42
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);
47
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);
53
54  private:
55   friend class base::RefCountedThreadSafe<DOMStorageSession>;
56
57   DOMStorageSession(DOMStorageContextImpl* context,
58                     int64 namespace_id,
59                     const std::string& persistent_namespace_id);
60   ~DOMStorageSession();
61
62   scoped_refptr<DOMStorageContextImpl> context_;
63   int64 namespace_id_;
64   std::string persistent_namespace_id_;
65   bool should_persist_;
66
67   DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageSession);
68 };
69
70 }  // namespace content
71
72 #endif  // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_SESSION_H_