Chromium Code Reviews| 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 if (keyPath.type() == WebIDBKeyPath::ArrayType) { | |
|
michaeln
2012/04/24 21:08:53
nit: might be more readable as a switch statement
jsbell
2012/04/25 21:49:46
Done.
| |
| 44 WebVector<WebString> array = keyPath.array(); | |
| 45 for (size_t i = 0; i < array.size(); ++i) { | |
| 46 array_.push_back(static_cast<string16>(array[i])); | |
| 47 } | |
| 48 } | |
| 49 string_ = keyPath.type() == WebIDBKeyPath::StringType ? | |
| 50 static_cast<string16>(keyPath.string()) : string16(); | |
| 51 } | |
| 52 | |
| 53 bool IndexedDBKeyPath::IsValid() const { | |
| 54 WebIDBKeyPath key_path = *this; | |
| 55 return key_path.isValid(); | |
| 56 } | |
| 57 | |
| 58 IndexedDBKeyPath::operator WebIDBKeyPath() const { | |
| 59 switch (type_) { | |
| 60 case WebIDBKeyPath::ArrayType: | |
| 61 return WebIDBKeyPath::create(array_); | |
| 62 case WebIDBKeyPath::StringType: | |
| 63 return WebIDBKeyPath::create(static_cast<WebString>(string_)); | |
|
michaeln
2012/04/24 21:08:53
Is this static_cast correct/needed?
Looks like yo
jsbell
2012/04/25 21:49:46
Done.
| |
| 64 case WebIDBKeyPath::NullType: | |
| 65 return WebIDBKeyPath::createNull(); | |
| 66 } | |
| 67 NOTREACHED(); | |
| 68 return WebIDBKeyPath::createNull(); | |
| 69 } | |
| OLD | NEW |