Home | History | Annotate | Download | only in browser
      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.
      4 
      5 #ifndef CONTENT_PUBLIC_BROWSER_SESSION_STORAGE_NAMESPACE_H_
      6 #define CONTENT_PUBLIC_BROWSER_SESSION_STORAGE_NAMESPACE_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/callback.h"
     13 #include "base/memory/ref_counted.h"
     14 
     15 namespace content {
     16 
     17 // This is a ref-counted class that represents a SessionStorageNamespace.
     18 // On destruction it ensures that the storage namespace is destroyed.
     19 class SessionStorageNamespace
     20     : public base::RefCountedThreadSafe<SessionStorageNamespace> {
     21  public:
     22   // Returns the ID of the |SessionStorageNamespace|. The ID is unique among all
     23   // SessionStorageNamespace objects, but not unique across browser runs.
     24   virtual int64 id() const = 0;
     25 
     26   // Returns the persistent ID for the |SessionStorageNamespace|. The ID is
     27   // unique across browser runs.
     28   virtual const std::string& persistent_id() const = 0;
     29 
     30   // For marking that the sessionStorage will be needed or won't be needed by
     31   // session restore.
     32   virtual void SetShouldPersist(bool should_persist) = 0;
     33 
     34   virtual bool should_persist() const = 0;
     35 
     36   // SessionStorageNamespaces can be merged. These merges happen based on
     37   // a transaction log of operations on the session storage namespace since
     38   // this function has been called. Transaction logging will be restricted
     39   // to the processes indicated.
     40   virtual void AddTransactionLogProcessId(int process_id) = 0;
     41 
     42   // When transaction logging for a process is no longer required, the log
     43   // can be removed to save space.
     44   virtual void RemoveTransactionLogProcessId(int process_id) = 0;
     45 
     46   // Creates a new session storage namespace which is an alias of the current
     47   // instance.
     48   virtual SessionStorageNamespace* CreateAlias() = 0;
     49 
     50   enum MergeResult {
     51     MERGE_RESULT_NAMESPACE_NOT_FOUND,
     52     MERGE_RESULT_NAMESPACE_NOT_ALIAS,
     53     MERGE_RESULT_NOT_LOGGING,
     54     MERGE_RESULT_NO_TRANSACTIONS,
     55     MERGE_RESULT_TOO_MANY_TRANSACTIONS,
     56     MERGE_RESULT_NOT_MERGEABLE,
     57     MERGE_RESULT_MERGEABLE,
     58     MERGE_RESULT_MAX_VALUE
     59   };
     60 
     61   typedef base::Callback<void(MergeResult)> MergeResultCallback;
     62 
     63   // Determines whether the transaction log for the process specified can
     64   // be merged into the other session storage namespace supplied.
     65   // If actually_merge is set to true, the merge will actually be performed,
     66   // if possible, and the result of the merge will be returned.
     67   // If actually_merge is set to false, the result of whether a merge would be
     68   // possible is returned.
     69   virtual void Merge(bool actually_merge,
     70                      int process_id,
     71                      SessionStorageNamespace* other,
     72                      const MergeResultCallback& callback) = 0;
     73 
     74   // Indicates whether this SessionStorageNamespace is an alias of |other|,
     75   // i.e. whether they point to the same underlying data.
     76   virtual bool IsAliasOf(SessionStorageNamespace* other) = 0;
     77 
     78  protected:
     79   friend class base::RefCountedThreadSafe<SessionStorageNamespace>;
     80   virtual ~SessionStorageNamespace() {}
     81 };
     82 
     83 // Used to store mappings of StoragePartition id to SessionStorageNamespace.
     84 typedef std::map<std::string, scoped_refptr<SessionStorageNamespace> >
     85     SessionStorageNamespaceMap;
     86 
     87 }  // namespace content
     88 
     89 #endif  // CONTENT_PUBLIC_BROWSER_SESSION_STORAGE_NAMESPACE_H_
     90