OLD | NEW |
(Empty) | |
| 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 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 10 |
| 11 using WebKit::WebIDBKeyPath; |
| 12 using WebKit::WebString; |
| 13 using WebKit::WebVector; |
| 14 |
| 15 IndexedDBKeyPath::IndexedDBKeyPath() |
| 16 : type_(WebIDBKeyPath::NullType) { |
| 17 } |
| 18 |
| 19 IndexedDBKeyPath::IndexedDBKeyPath(const WebIDBKeyPath& key) { |
| 20 Set(key); |
| 21 } |
| 22 |
| 23 IndexedDBKeyPath::~IndexedDBKeyPath() { |
| 24 } |
| 25 |
| 26 void IndexedDBKeyPath::SetNull() { |
| 27 type_ = WebIDBKeyPath::NullType; |
| 28 } |
| 29 |
| 30 void IndexedDBKeyPath::SetArray(const std::vector<string16>& array) { |
| 31 type_ = WebIDBKeyPath::ArrayType; |
| 32 array_ = array; |
| 33 } |
| 34 |
| 35 void IndexedDBKeyPath::SetString(const string16& string) { |
| 36 type_ = WebIDBKeyPath::StringType; |
| 37 string_ = string; |
| 38 } |
| 39 |
| 40 void IndexedDBKeyPath::Set(const WebIDBKeyPath& keyPath) { |
| 41 type_ = keyPath.type(); |
| 42 array_.clear(); |
| 43 string_.clear(); |
| 44 switch (type_) { |
| 45 case WebIDBKeyPath::ArrayType: |
| 46 { |
| 47 WebVector<WebString> array = keyPath.array(); |
| 48 for (size_t i = 0; i < array.size(); ++i) |
| 49 array_.push_back(static_cast<string16>(array[i])); |
| 50 break; |
| 51 } |
| 52 case WebIDBKeyPath::NullType: |
| 53 break; |
| 54 case WebIDBKeyPath::StringType: |
| 55 string_ = static_cast<string16>(keyPath.string()); |
| 56 } |
| 57 } |
| 58 |
| 59 bool IndexedDBKeyPath::IsValid() const { |
| 60 WebIDBKeyPath key_path = *this; |
| 61 return key_path.isValid(); |
| 62 } |
| 63 |
| 64 IndexedDBKeyPath::operator WebIDBKeyPath() const { |
| 65 switch (type_) { |
| 66 case WebIDBKeyPath::ArrayType: |
| 67 return WebIDBKeyPath::create(array_); |
| 68 case WebIDBKeyPath::StringType: |
| 69 return WebIDBKeyPath::create(WebString(string_)); |
| 70 case WebIDBKeyPath::NullType: |
| 71 return WebIDBKeyPath::createNull(); |
| 72 } |
| 73 NOTREACHED(); |
| 74 return WebIDBKeyPath::createNull(); |
| 75 } |
OLD | NEW |