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 #include "content/common/indexed_db/indexed_db_key_path.h" 6 7 #include "base/logging.h" 8 9 namespace content { 10 11 using WebKit::WebIDBKeyPathTypeArray; 12 using WebKit::WebIDBKeyPathTypeNull; 13 using WebKit::WebIDBKeyPathTypeString; 14 15 IndexedDBKeyPath::IndexedDBKeyPath() : type_(WebIDBKeyPathTypeNull) {} 16 17 IndexedDBKeyPath::IndexedDBKeyPath(const string16& string) 18 : type_(WebIDBKeyPathTypeString), string_(string) {} 19 20 IndexedDBKeyPath::IndexedDBKeyPath(const std::vector<string16>& array) 21 : type_(WebIDBKeyPathTypeArray), array_(array) {} 22 23 IndexedDBKeyPath::~IndexedDBKeyPath() {} 24 25 const std::vector<string16>& IndexedDBKeyPath::array() const { 26 DCHECK(type_ == WebKit::WebIDBKeyPathTypeArray); 27 return array_; 28 } 29 30 const string16& IndexedDBKeyPath::string() const { 31 DCHECK(type_ == WebKit::WebIDBKeyPathTypeString); 32 return string_; 33 } 34 35 bool IndexedDBKeyPath::operator==(const IndexedDBKeyPath& other) const { 36 if (type_ != other.type_) 37 return false; 38 39 switch (type_) { 40 case WebIDBKeyPathTypeNull: 41 return true; 42 case WebIDBKeyPathTypeString: 43 return string_ == other.string_; 44 case WebIDBKeyPathTypeArray: 45 return array_ == other.array_; 46 } 47 NOTREACHED(); 48 return false; 49 } 50 51 } // namespace content 52