1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <map>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <set>
10f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include <string>
11f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include <utility>
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/basictypes.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/files/file_path.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/ref_counted.h"
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/browser/indexed_db/indexed_db_callbacks.h"
18ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "content/browser/indexed_db/indexed_db_database.h"
19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/browser/indexed_db/indexed_db_database_callbacks.h"
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/common/content_export.h"
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "url/gurl.h"
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
23a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace net {
24a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass URLRequestContext;
25a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
26a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace content {
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexedDBBackingStore;
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct IndexedDBPendingConnection;
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class CONTENT_EXPORT IndexedDBFactory
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) {
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap;
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef OriginDBMap::const_iterator OriginDBMapIterator;
375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  typedef std::pair<OriginDBMapIterator, OriginDBMapIterator> OriginDBs;
385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier,
405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                               bool forcedClose) = 0;
415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks,
435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                const GURL& origin_url,
445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                const base::FilePath& data_directory,
455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                net::URLRequestContext* request_context) = 0;
465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void Open(const base::string16& name,
475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                    const IndexedDBPendingConnection& connection,
485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                    net::URLRequestContext* request_context,
495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                    const GURL& origin_url,
505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                    const base::FilePath& data_directory) = 0;
515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void DeleteDatabase(const base::string16& name,
535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                              net::URLRequestContext* request_context,
545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                              scoped_refptr<IndexedDBCallbacks> callbacks,
555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                              const GURL& origin_url,
565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                              const base::FilePath& data_directory) = 0;
575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void HandleBackingStoreFailure(const GURL& origin_url) = 0;
595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void HandleBackingStoreCorruption(
605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const GURL& origin_url,
615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const IndexedDBDatabaseError& error) = 0;
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual OriginDBs GetOpenDatabasesForOrigin(const GURL& origin_url) const = 0;
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void ForceClose(const GURL& origin_url) = 0;
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Called by the IndexedDBContext destructor so the factory can do cleanup.
685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void ContextDestroyed() = 0;
69ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
70c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Called by the IndexedDBActiveBlobRegistry.
71c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void ReportOutstandingBlobs(const GURL& origin_url,
725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                      bool blobs_outstanding) = 0;
73c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by an IndexedDBDatabase when it is actually deleted.
755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void DatabaseDeleted(
765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const IndexedDBDatabase::Identifier& identifier) = 0;
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual size_t GetConnectionCount(const GURL& origin_url) const = 0;
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected:
81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  friend class base::RefCountedThreadSafe<IndexedDBFactory>;
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  IndexedDBFactory() {}
845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual ~IndexedDBFactory() {}
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const GURL& origin_url,
88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const base::FilePath& data_directory,
89a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      net::URLRequestContext* request_context,
90f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      blink::WebIDBDataLoss* data_loss,
910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      std::string* data_loss_reason,
92116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      bool* disk_full,
935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      leveldb::Status* status) = 0;
94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      const GURL& origin_url,
975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      const base::FilePath& data_directory,
985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      net::URLRequestContext* request_context,
995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      blink::WebIDBDataLoss* data_loss,
1005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      std::string* data_loss_message,
1015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      bool* disk_full,
102116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      bool first_time,
1035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      leveldb::Status* status) = 0;
10458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
106f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory);
107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace content
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
112