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.
5 #ifndef CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_
6 #define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/strings/string16.h"
15 #include "content/common/content_export.h"
16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
24 class CONTENT_EXPORT IndexedDBKey
{
26 typedef std::vector
<IndexedDBKey
> KeyArray
;
28 IndexedDBKey(); // Defaults to blink::WebIDBKeyTypeInvalid.
29 explicit IndexedDBKey(blink::WebIDBKeyType
); // must be Null or Invalid
30 explicit IndexedDBKey(const KeyArray
& array
);
31 explicit IndexedDBKey(const std::string
& binary
);
32 explicit IndexedDBKey(const base::string16
& string
);
33 IndexedDBKey(double number
,
34 blink::WebIDBKeyType type
); // must be date or number
35 IndexedDBKey(const IndexedDBKey
& other
);
37 IndexedDBKey
& operator=(const IndexedDBKey
& other
);
41 bool IsLessThan(const IndexedDBKey
& other
) const;
42 bool Equals(const IndexedDBKey
& other
) const;
44 blink::WebIDBKeyType
type() const { return type_
; }
45 const std::vector
<IndexedDBKey
>& array() const {
46 DCHECK_EQ(type_
, blink::WebIDBKeyTypeArray
);
49 const std::string
& binary() const {
50 DCHECK_EQ(type_
, blink::WebIDBKeyTypeBinary
);
53 const base::string16
& string() const {
54 DCHECK_EQ(type_
, blink::WebIDBKeyTypeString
);
58 DCHECK_EQ(type_
, blink::WebIDBKeyTypeDate
);
61 double number() const {
62 DCHECK_EQ(type_
, blink::WebIDBKeyTypeNumber
);
66 size_t size_estimate() const { return size_estimate_
; }
69 int CompareTo(const IndexedDBKey
& other
) const;
71 blink::WebIDBKeyType type_
;
72 std::vector
<IndexedDBKey
> array_
;
74 base::string16 string_
;
77 size_t size_estimate_
;
80 } // namespace content
82 #endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_