Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: content/common/indexed_db/indexed_db_key_path.cc

Issue 10204003: Use WebIDBKeyPath type in WebKit API, implement IndexedDBKeyPath type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move IndexedDBKeyPath to content namespace, formatting nits. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 namespace content {
12
13 using WebKit::WebIDBKeyPath;
14 using WebKit::WebString;
15 using WebKit::WebVector;
16
17 IndexedDBKeyPath::IndexedDBKeyPath()
18 : type_(WebIDBKeyPath::NullType) {
19 }
20
21 IndexedDBKeyPath::IndexedDBKeyPath(const WebIDBKeyPath& key) {
22 Set(key);
23 }
24
25 IndexedDBKeyPath::~IndexedDBKeyPath() {
26 }
27
28 void IndexedDBKeyPath::SetNull() {
29 type_ = WebIDBKeyPath::NullType;
30 }
31
32 void IndexedDBKeyPath::SetArray(const std::vector<string16>& array) {
33 type_ = WebIDBKeyPath::ArrayType;
34 array_ = array;
35 }
36
37 void IndexedDBKeyPath::SetString(const string16& string) {
38 type_ = WebIDBKeyPath::StringType;
39 string_ = string;
40 }
41
42 void IndexedDBKeyPath::Set(const WebIDBKeyPath& keyPath) {
43 type_ = keyPath.type();
44 array_.clear();
45 string_.clear();
46 switch (type_) {
47 case WebIDBKeyPath::ArrayType: {
48 WebVector<WebString> array = keyPath.array();
49 for (size_t i = 0; i < array.size(); ++i)
50 array_.push_back(static_cast<string16>(array[i]));
51 break;
52 }
53 case WebIDBKeyPath::NullType:
54 break;
55 case WebIDBKeyPath::StringType:
56 string_ = static_cast<string16>(keyPath.string());
57 }
58 }
59
60 bool IndexedDBKeyPath::IsValid() const {
61 WebIDBKeyPath key_path = *this;
62 return key_path.isValid();
63 }
64
65 IndexedDBKeyPath::operator WebIDBKeyPath() const {
66 switch (type_) {
67 case WebIDBKeyPath::ArrayType:
68 return WebIDBKeyPath::create(array_);
69 case WebIDBKeyPath::StringType:
70 return WebIDBKeyPath::create(WebString(string_));
71 case WebIDBKeyPath::NullType:
72 return WebIDBKeyPath::createNull();
73 }
74 NOTREACHED();
75 return WebIDBKeyPath::createNull();
76 }
77
78 } // namespace content
OLDNEW
« no previous file with comments | « content/common/indexed_db/indexed_db_key_path.h ('k') | content/common/indexed_db/indexed_db_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698