| OLD | NEW | 
 | (Empty) | 
|    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 WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |  | 
|    6 #define WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |  | 
|    7  |  | 
|    8 #include <map> |  | 
|    9  |  | 
|   10 #include "base/basictypes.h" |  | 
|   11 #include "base/files/file_path.h" |  | 
|   12 #include "base/memory/ref_counted.h" |  | 
|   13 #include "webkit/browser/webkit_storage_browser_export.h" |  | 
|   14  |  | 
|   15 class GURL; |  | 
|   16  |  | 
|   17 namespace dom_storage { |  | 
|   18  |  | 
|   19 class DomStorageArea; |  | 
|   20 class DomStorageTaskRunner; |  | 
|   21 class SessionStorageDatabase; |  | 
|   22  |  | 
|   23 // Container for the set of per-origin Areas. |  | 
|   24 // See class comments for DomStorageContext for a larger overview. |  | 
|   25 class WEBKIT_STORAGE_BROWSER_EXPORT DomStorageNamespace |  | 
|   26     : public base::RefCountedThreadSafe<DomStorageNamespace> { |  | 
|   27  public: |  | 
|   28   // Option for PurgeMemory. |  | 
|   29   enum PurgeOption { |  | 
|   30     // Purge unopened areas only. |  | 
|   31     PURGE_UNOPENED, |  | 
|   32  |  | 
|   33     // Purge aggressively, i.e. discard cache even for areas that have |  | 
|   34     // non-zero open count. |  | 
|   35     PURGE_AGGRESSIVE, |  | 
|   36   }; |  | 
|   37  |  | 
|   38   // Constructor for a LocalStorage namespace with id of 0 |  | 
|   39   // and an optional backing directory on disk. |  | 
|   40   DomStorageNamespace(const base::FilePath& directory,  // may be empty |  | 
|   41                       DomStorageTaskRunner* task_runner); |  | 
|   42  |  | 
|   43   // Constructor for a SessionStorage namespace with a non-zero id and an |  | 
|   44   // optional backing on disk via |session_storage_database| (may be NULL). |  | 
|   45   DomStorageNamespace(int64 namespace_id, |  | 
|   46                       const std::string& persistent_namespace_id, |  | 
|   47                       SessionStorageDatabase* session_storage_database, |  | 
|   48                       DomStorageTaskRunner* task_runner); |  | 
|   49  |  | 
|   50   int64 namespace_id() const { return namespace_id_; } |  | 
|   51   const std::string& persistent_namespace_id() const { |  | 
|   52     return persistent_namespace_id_; |  | 
|   53   } |  | 
|   54  |  | 
|   55   // Returns the storage area for the given origin, |  | 
|   56   // creating instance if needed. Each call to open |  | 
|   57   // must be balanced with a call to CloseStorageArea. |  | 
|   58   DomStorageArea* OpenStorageArea(const GURL& origin); |  | 
|   59   void CloseStorageArea(DomStorageArea* area); |  | 
|   60  |  | 
|   61   // Returns the area for |origin| if it's open, otherwise NULL. |  | 
|   62   DomStorageArea* GetOpenStorageArea(const GURL& origin); |  | 
|   63  |  | 
|   64   // Creates a clone of |this| namespace including |  | 
|   65   // shallow copies of all contained areas. |  | 
|   66   // Should only be called for session storage namespaces. |  | 
|   67   DomStorageNamespace* Clone(int64 clone_namespace_id, |  | 
|   68                              const std::string& clone_persistent_namespace_id); |  | 
|   69  |  | 
|   70   void DeleteLocalStorageOrigin(const GURL& origin); |  | 
|   71   void DeleteSessionStorageOrigin(const GURL& origin); |  | 
|   72   void PurgeMemory(PurgeOption purge); |  | 
|   73   void Shutdown(); |  | 
|   74  |  | 
|   75   unsigned int CountInMemoryAreas() const; |  | 
|   76  |  | 
|   77  private: |  | 
|   78   friend class base::RefCountedThreadSafe<DomStorageNamespace>; |  | 
|   79  |  | 
|   80   // Struct to hold references to our contained areas and |  | 
|   81   // to keep track of how many tabs have a given area open. |  | 
|   82   struct AreaHolder { |  | 
|   83     scoped_refptr<DomStorageArea> area_; |  | 
|   84     int open_count_; |  | 
|   85     AreaHolder(); |  | 
|   86     AreaHolder(DomStorageArea* area, int count); |  | 
|   87     ~AreaHolder(); |  | 
|   88   }; |  | 
|   89   typedef std::map<GURL, AreaHolder> AreaMap; |  | 
|   90  |  | 
|   91   ~DomStorageNamespace(); |  | 
|   92  |  | 
|   93   // Returns a pointer to the area holder in our map or NULL. |  | 
|   94   AreaHolder* GetAreaHolder(const GURL& origin); |  | 
|   95  |  | 
|   96   int64 namespace_id_; |  | 
|   97   std::string persistent_namespace_id_; |  | 
|   98   base::FilePath directory_; |  | 
|   99   AreaMap areas_; |  | 
|  100   scoped_refptr<DomStorageTaskRunner> task_runner_; |  | 
|  101   scoped_refptr<SessionStorageDatabase> session_storage_database_; |  | 
|  102 }; |  | 
|  103  |  | 
|  104 }  // namespace dom_storage |  | 
|  105  |  | 
|  106  |  | 
|  107 #endif  // WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |  | 
| OLD | NEW |