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