Home | History | Annotate | Download | only in indexed_db
      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 CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_
      6 #define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/scoped_vector.h"
     13 #include "base/strings/string16.h"
     14 #include "content/common/content_export.h"
     15 #include "third_party/WebKit/public/platform/WebIDBTypes.h"
     16 
     17 namespace blink {
     18 class WebIDBKey;
     19 }
     20 
     21 namespace content {
     22 
     23 class CONTENT_EXPORT IndexedDBKey {
     24  public:
     25   typedef std::vector<IndexedDBKey> KeyArray;
     26 
     27   IndexedDBKey();  // Defaults to blink::WebIDBKeyTypeInvalid.
     28   explicit IndexedDBKey(blink::WebIDBKeyType);  // must be Null or Invalid
     29   explicit IndexedDBKey(const KeyArray& array);
     30   explicit IndexedDBKey(const std::string& binary);
     31   explicit IndexedDBKey(const base::string16& string);
     32   IndexedDBKey(double number,
     33                blink::WebIDBKeyType type);  // must be date or number
     34   ~IndexedDBKey();
     35 
     36   bool IsValid() const;
     37 
     38   bool IsLessThan(const IndexedDBKey& other) const;
     39   bool Equals(const IndexedDBKey& other) const;
     40 
     41   blink::WebIDBKeyType type() const { return type_; }
     42   const std::vector<IndexedDBKey>& array() const { return array_; }
     43   const std::string& binary() const { return binary_; }
     44   const base::string16& string() const { return string_; }
     45   double date() const { return date_; }
     46   double number() const { return number_; }
     47 
     48   size_t size_estimate() const { return size_estimate_; }
     49 
     50  private:
     51   int CompareTo(const IndexedDBKey& other) const;
     52 
     53   blink::WebIDBKeyType type_;
     54   std::vector<IndexedDBKey> array_;
     55   std::string binary_;
     56   base::string16 string_;
     57   double date_;
     58   double number_;
     59 
     60   size_t size_estimate_;
     61 };
     62 
     63 }  // namespace content
     64 
     65 #endif  // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_
     66