OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/indexed_db/indexed_db_key_path.h" | 5 #include "content/common/indexed_db/indexed_db_key_path.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/WebKit/public/platform/WebString.h" | 8 #include "third_party/WebKit/public/platform/WebString.h" |
9 #include "third_party/WebKit/public/platform/WebVector.h" | 9 #include "third_party/WebKit/public/platform/WebVector.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 using WebKit::WebIDBKeyPath; | 13 using WebKit::WebIDBKeyPath; |
| 14 using WebKit::WebIDBKeyPathTypeArray; |
| 15 using WebKit::WebIDBKeyPathTypeNull; |
| 16 using WebKit::WebIDBKeyPathTypeString; |
14 using WebKit::WebString; | 17 using WebKit::WebString; |
15 using WebKit::WebVector; | 18 using WebKit::WebVector; |
16 | 19 |
17 namespace { | 20 namespace { |
18 static std::vector<string16> CopyArray(const WebVector<WebString>& array) { | 21 static std::vector<string16> CopyArray(const WebVector<WebString>& array) { |
19 std::vector<string16> copy(array.size()); | 22 std::vector<string16> copy(array.size()); |
20 for (size_t i = 0; i < array.size(); ++i) | 23 for (size_t i = 0; i < array.size(); ++i) |
21 copy[i] = array[i]; | 24 copy[i] = array[i]; |
22 return copy; | 25 return copy; |
23 } | 26 } |
24 } // namespace | 27 } // namespace |
25 | 28 |
26 IndexedDBKeyPath::IndexedDBKeyPath() : type_(WebIDBKeyPath::NullType) {} | 29 IndexedDBKeyPath::IndexedDBKeyPath() : type_(WebIDBKeyPathTypeNull) {} |
27 | 30 |
28 IndexedDBKeyPath::IndexedDBKeyPath(const string16& string) | 31 IndexedDBKeyPath::IndexedDBKeyPath(const string16& string) |
29 : type_(WebIDBKeyPath::StringType), string_(string) {} | 32 : type_(WebIDBKeyPathTypeString), string_(string) {} |
30 | 33 |
31 IndexedDBKeyPath::IndexedDBKeyPath(const std::vector<string16>& array) | 34 IndexedDBKeyPath::IndexedDBKeyPath(const std::vector<string16>& array) |
32 : type_(WebIDBKeyPath::ArrayType), array_(array) {} | 35 : type_(WebIDBKeyPathTypeArray), array_(array) {} |
33 | 36 |
34 IndexedDBKeyPath::IndexedDBKeyPath(const WebIDBKeyPath& other) | 37 IndexedDBKeyPath::IndexedDBKeyPath(const WebIDBKeyPath& other) |
35 : type_(other.type()), | 38 : type_(other.keyPathType()), |
36 string_(type_ == WebIDBKeyPath::StringType | 39 string_(type_ == WebIDBKeyPathTypeString |
37 ? static_cast<string16>(other.string()) : string16()), | 40 ? static_cast<string16>(other.string()) : string16()), |
38 array_(type_ == WebIDBKeyPath::ArrayType | 41 array_(type_ == WebIDBKeyPathTypeArray |
39 ? CopyArray(other.array()) : std::vector<string16>()) {} | 42 ? CopyArray(other.array()) : std::vector<string16>()) {} |
40 | 43 |
41 IndexedDBKeyPath::~IndexedDBKeyPath() {} | 44 IndexedDBKeyPath::~IndexedDBKeyPath() {} |
42 | 45 |
43 bool IndexedDBKeyPath::IsValid() const { | 46 bool IndexedDBKeyPath::IsValid() const { |
44 WebIDBKeyPath key_path = *this; | 47 WebIDBKeyPath key_path = *this; |
45 return key_path.isValid(); | 48 return key_path.isValid(); |
46 } | 49 } |
47 | 50 |
48 const std::vector<string16>& IndexedDBKeyPath::array() const { | 51 const std::vector<string16>& IndexedDBKeyPath::array() const { |
49 DCHECK(type_ == WebKit::WebIDBKeyPath::ArrayType); | 52 DCHECK(type_ == WebKit::WebIDBKeyPathTypeArray); |
50 return array_; | 53 return array_; |
51 } | 54 } |
52 | 55 |
53 const string16& IndexedDBKeyPath::string() const { | 56 const string16& IndexedDBKeyPath::string() const { |
54 DCHECK(type_ == WebKit::WebIDBKeyPath::StringType); | 57 DCHECK(type_ == WebKit::WebIDBKeyPathTypeString); |
55 return string_; | 58 return string_; |
56 } | 59 } |
57 | 60 |
58 bool IndexedDBKeyPath::operator==(const IndexedDBKeyPath& other) const { | 61 bool IndexedDBKeyPath::operator==(const IndexedDBKeyPath& other) const { |
59 if (type_ != other.type_) | 62 if (type_ != other.type_) |
60 return false; | 63 return false; |
61 | 64 |
62 switch (type_) { | 65 switch (type_) { |
63 case WebIDBKeyPath::NullType: | 66 case WebIDBKeyPathTypeNull: |
64 return true; | 67 return true; |
65 case WebIDBKeyPath::StringType: | 68 case WebIDBKeyPathTypeString: |
66 return string_ == other.string_; | 69 return string_ == other.string_; |
67 case WebIDBKeyPath::ArrayType: | 70 case WebIDBKeyPathTypeArray: |
68 return array_ == other.array_; | 71 return array_ == other.array_; |
69 } | 72 } |
70 NOTREACHED(); | 73 NOTREACHED(); |
71 return false; | 74 return false; |
72 } | 75 } |
73 | 76 |
74 IndexedDBKeyPath::operator WebIDBKeyPath() const { | 77 IndexedDBKeyPath::operator WebIDBKeyPath() const { |
75 switch (type_) { | 78 switch (type_) { |
76 case WebIDBKeyPath::ArrayType: | 79 case WebIDBKeyPathTypeArray: |
77 return WebIDBKeyPath::create(array_); | 80 return WebIDBKeyPath::create(array_); |
78 case WebIDBKeyPath::StringType: | 81 case WebIDBKeyPathTypeString: |
79 return WebIDBKeyPath::create(WebString(string_)); | 82 return WebIDBKeyPath::create(WebString(string_)); |
80 case WebIDBKeyPath::NullType: | 83 case WebIDBKeyPathTypeNull: |
81 return WebIDBKeyPath::createNull(); | 84 return WebIDBKeyPath::createNull(); |
82 } | 85 } |
83 NOTREACHED(); | 86 NOTREACHED(); |
84 return WebIDBKeyPath::createNull(); | 87 return WebIDBKeyPath::createNull(); |
85 } | 88 } |
86 | 89 |
87 } // namespace content | 90 } // namespace content |
OLD | NEW |