Home | History | Annotate | Download | only in indexed_db
      1 // Copyright (c) 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_INDEXED_DB_INDEXED_DB_FACTORY_H_
      6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
      7 
      8 #include <map>
      9 #include <set>
     10 #include <string>
     11 #include <utility>
     12 
     13 #include "base/basictypes.h"
     14 #include "base/files/file_path.h"
     15 #include "base/memory/ref_counted.h"
     16 #include "base/strings/string16.h"
     17 #include "content/browser/indexed_db/indexed_db_callbacks.h"
     18 #include "content/browser/indexed_db/indexed_db_database.h"
     19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
     20 #include "content/common/content_export.h"
     21 #include "url/gurl.h"
     22 
     23 namespace net {
     24 class URLRequestContext;
     25 }
     26 
     27 namespace content {
     28 
     29 class IndexedDBBackingStore;
     30 struct IndexedDBPendingConnection;
     31 
     32 class CONTENT_EXPORT IndexedDBFactory
     33     : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) {
     34  public:
     35   typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap;
     36   typedef OriginDBMap::const_iterator OriginDBMapIterator;
     37   typedef std::pair<OriginDBMapIterator, OriginDBMapIterator> OriginDBs;
     38 
     39   virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier,
     40                                bool forcedClose) = 0;
     41 
     42   virtual void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks,
     43                                 const GURL& origin_url,
     44                                 const base::FilePath& data_directory,
     45                                 net::URLRequestContext* request_context) = 0;
     46   virtual void Open(const base::string16& name,
     47                     const IndexedDBPendingConnection& connection,
     48                     net::URLRequestContext* request_context,
     49                     const GURL& origin_url,
     50                     const base::FilePath& data_directory) = 0;
     51 
     52   virtual void DeleteDatabase(const base::string16& name,
     53                               net::URLRequestContext* request_context,
     54                               scoped_refptr<IndexedDBCallbacks> callbacks,
     55                               const GURL& origin_url,
     56                               const base::FilePath& data_directory) = 0;
     57 
     58   virtual void HandleBackingStoreFailure(const GURL& origin_url) = 0;
     59   virtual void HandleBackingStoreCorruption(
     60       const GURL& origin_url,
     61       const IndexedDBDatabaseError& error) = 0;
     62 
     63   virtual OriginDBs GetOpenDatabasesForOrigin(const GURL& origin_url) const = 0;
     64 
     65   virtual void ForceClose(const GURL& origin_url) = 0;
     66 
     67   // Called by the IndexedDBContext destructor so the factory can do cleanup.
     68   virtual void ContextDestroyed() = 0;
     69 
     70   // Called by the IndexedDBActiveBlobRegistry.
     71   virtual void ReportOutstandingBlobs(const GURL& origin_url,
     72                                       bool blobs_outstanding) = 0;
     73 
     74   // Called by an IndexedDBDatabase when it is actually deleted.
     75   virtual void DatabaseDeleted(
     76       const IndexedDBDatabase::Identifier& identifier) = 0;
     77 
     78   virtual size_t GetConnectionCount(const GURL& origin_url) const = 0;
     79 
     80  protected:
     81   friend class base::RefCountedThreadSafe<IndexedDBFactory>;
     82 
     83   IndexedDBFactory() {}
     84   virtual ~IndexedDBFactory() {}
     85 
     86   virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
     87       const GURL& origin_url,
     88       const base::FilePath& data_directory,
     89       net::URLRequestContext* request_context,
     90       blink::WebIDBDataLoss* data_loss,
     91       std::string* data_loss_reason,
     92       bool* disk_full,
     93       leveldb::Status* status) = 0;
     94 
     95   virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
     96       const GURL& origin_url,
     97       const base::FilePath& data_directory,
     98       net::URLRequestContext* request_context,
     99       blink::WebIDBDataLoss* data_loss,
    100       std::string* data_loss_message,
    101       bool* disk_full,
    102       bool first_time,
    103       leveldb::Status* status) = 0;
    104 
    105  private:
    106   DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory);
    107 };
    108 
    109 }  // namespace content
    110 
    111 #endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
    112