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

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: Formatting nit. Created 8 years, 8 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 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698