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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/common/indexed_db/indexed_db_key_path.cc
diff --git a/content/common/indexed_db/indexed_db_key_path.cc b/content/common/indexed_db/indexed_db_key_path.cc
new file mode 100644
index 0000000000000000000000000000000000000000..196b8d747ee92ea03f0ae84205900b9a17563b32
--- /dev/null
+++ b/content/common/indexed_db/indexed_db_key_path.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/indexed_db/indexed_db_key_path.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
+
+using WebKit::WebIDBKeyPath;
+using WebKit::WebString;
+using WebKit::WebVector;
+
+IndexedDBKeyPath::IndexedDBKeyPath()
+ : type_(WebIDBKeyPath::NullType) {
+}
+
+IndexedDBKeyPath::IndexedDBKeyPath(const WebIDBKeyPath& key) {
+ Set(key);
+}
+
+IndexedDBKeyPath::~IndexedDBKeyPath() {
+}
+
+void IndexedDBKeyPath::SetNull() {
+ type_ = WebIDBKeyPath::NullType;
+}
+
+void IndexedDBKeyPath::SetArray(const std::vector<string16>& array) {
+ type_ = WebIDBKeyPath::ArrayType;
+ array_ = array;
+}
+
+void IndexedDBKeyPath::SetString(const string16& string) {
+ type_ = WebIDBKeyPath::StringType;
+ string_ = string;
+}
+
+void IndexedDBKeyPath::Set(const WebIDBKeyPath& keyPath) {
+ type_ = keyPath.type();
+ array_.clear();
+ 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.
+ WebVector<WebString> array = keyPath.array();
+ for (size_t i = 0; i < array.size(); ++i) {
+ array_.push_back(static_cast<string16>(array[i]));
+ }
+ }
+ string_ = keyPath.type() == WebIDBKeyPath::StringType ?
+ static_cast<string16>(keyPath.string()) : string16();
+}
+
+bool IndexedDBKeyPath::IsValid() const {
+ WebIDBKeyPath key_path = *this;
+ return key_path.isValid();
+}
+
+IndexedDBKeyPath::operator WebIDBKeyPath() const {
+ switch (type_) {
+ case WebIDBKeyPath::ArrayType:
+ return WebIDBKeyPath::create(array_);
+ case WebIDBKeyPath::StringType:
+ 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.
+ case WebIDBKeyPath::NullType:
+ return WebIDBKeyPath::createNull();
+ }
+ NOTREACHED();
+ return WebIDBKeyPath::createNull();
+}

Powered by Google App Engine
This is Rietveld 408576698