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_INDEX_WRITER_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_INDEX_WRITER_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <map>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <vector>
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/basictypes.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/scoped_vector.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/browser/indexed_db/indexed_db_backing_store.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/browser/indexed_db/indexed_db_database.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/browser/indexed_db/indexed_db_metadata.h"
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/common/indexed_db/indexed_db_key_path.h"
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace content {
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexedDBTransaction;
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)struct IndexedDBObjectStoreMetadata;
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexWriter {
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  explicit IndexWriter(const IndexedDBIndexMetadata& index_metadata);
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IndexWriter(const IndexedDBIndexMetadata& index_metadata,
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)              const IndexedDBDatabase::IndexKeys& index_keys);
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool VerifyIndexKeys(IndexedDBBackingStore* store,
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       IndexedDBBackingStore::Transaction* transaction,
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       int64 database_id,
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       int64 object_store_id,
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       int64 index_id,
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       bool* can_add_keys,
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       const IndexedDBKey& primary_key,
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                       base::string16* error_message) const WARN_UNUSED_RESULT;
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void WriteIndexKeys(const IndexedDBBackingStore::RecordIdentifier& record,
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                      IndexedDBBackingStore* store,
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                      IndexedDBBackingStore::Transaction* transaction,
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                      int64 database_id,
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                      int64 object_store_id) const;
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ~IndexWriter();
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool AddingKeyAllowed(IndexedDBBackingStore* store,
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        IndexedDBBackingStore::Transaction* transaction,
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        int64 database_id,
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        int64 object_store_id,
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        int64 index_id,
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        const IndexedDBKey& index_key,
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        const IndexedDBKey& primary_key,
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        bool* allowed) const WARN_UNUSED_RESULT;
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const IndexedDBIndexMetadata index_metadata_;
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IndexedDBDatabase::IndexKeys index_keys_;
59f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
60f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(IndexWriter);
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool MakeIndexWriters(
64c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    IndexedDBTransaction* transaction,
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    IndexedDBBackingStore* store,
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    int64 database_id,
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const IndexedDBObjectStoreMetadata& metadata,
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const IndexedDBKey& primary_key,
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    bool key_was_generated,
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const std::vector<IndexedDBDatabase::IndexKeys>& index_keys,
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ScopedVector<IndexWriter>* index_writers,
72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    base::string16* error_message,
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    bool* completed) WARN_UNUSED_RESULT;
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace content
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_INDEX_WRITER_H_
78