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

Unified Diff: chrome/browser/devtools/list_value_parser.h

Issue 22972007: Migrate DevToolsWindow from specific to opaque frontend host messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
« no previous file with comments | « chrome/browser/devtools/devtools_window.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/list_value_parser.h
diff --git a/chrome/browser/devtools/list_value_parser.h b/chrome/browser/devtools/list_value_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..ce44a0647f0d69bc00df9f9a94073af84ca0e27b
--- /dev/null
+++ b/chrome/browser/devtools/list_value_parser.h
@@ -0,0 +1,128 @@
+// Copyright (c) 2013 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 "base/bind.h"
+#include "base/callback.h"
+#include "base/values.h"
+
+#ifndef CHROME_BROWSER_DEVTOOLS_LIST_VALUE_PARSER_H_
+#define CHROME_BROWSER_DEVTOOLS_LIST_VALUE_PARSER_H_
+
+namespace internal {
pfeldman 2013/08/23 11:29:43 Use anonymous namespace
Vladislav Kaznacheev 2013/08/23 13:44:17 Done.
+
+bool GetValue(const base::ListValue& list, int pos, std::string& value) {
+ return list.GetString(pos, &value);
+}
+
+bool GetValue(const base::ListValue& list, int pos, int& value) {
+ return list.GetInteger(pos, &value);
+}
+
+bool GetValue(const base::ListValue& list, int pos, bool& value) {
+ return list.GetBoolean(pos, &value);
+}
+
+template <typename T>
+struct StorageTraits {
+ typedef T StorageType;
+};
+
+template <typename T>
+struct StorageTraits<const T&> {
+ typedef T StorageType;
+};
+
+template <class A>
+class Argument {
+ public:
+ typedef typename StorageTraits<A>::StorageType ValueType;
+
+ Argument(const base::ListValue& list, int pos) {
+ valid_ = GetValue(list, pos, value_);
+ }
+
+ ValueType value() const { return value_; }
+ bool valid() const { return valid_; }
+
+ private:
+ ValueType value_;
+ bool valid_;
+};
+
+bool ParseAndHandle0(const base::Callback<void(void)>& handler,
+ const base::ListValue& list) {
+ handler.Run();
+ return true;
+}
+
+template <class A1>
+bool ParseAndHandle1(const base::Callback<void(A1)>& handler,
+ const base::ListValue& list) {
+ if (list.GetSize() != 1)
+ return false;
+ Argument<A1> arg1(list, 0);
+ if (!arg1.valid())
+ return false;
+ handler.Run(arg1.value());
+ return true;
+}
+
+template <class A1, class A2>
+bool ParseAndHandle2(const base::Callback<void(A1, A2)>& handler,
+ const base::ListValue& list) {
+ if (list.GetSize() != 2)
+ return false;
+ Argument<A1> arg1(list, 0);
+ if (!arg1.valid())
+ return false;
+ Argument<A2> arg2(list, 1);
+ if (!arg2.valid())
+ return false;
+ handler.Run(arg1.value(), arg2.value());
+ return true;
+}
+
+template <class A1, class A2, class A3>
+bool ParseAndHandle3(const base::Callback<void(A1, A2, A3)>& handler,
+ const base::ListValue& list) {
+ if (list.GetSize() != 3)
+ return false;
+ Argument<A1> arg1(list, 0);
+ if (!arg1.valid())
+ return false;
+ Argument<A2> arg2(list, 1);
+ if (!arg2.valid())
+ return false;
+ Argument<A3> arg3(list, 2);
+ if (!arg3.valid())
+ return false;
+ handler.Run(arg1.value(), arg2.value(), arg3.value());
+ return true;
+}
+
+} // namespace internal
+
+typedef base::Callback<bool(const base::ListValue&)> ListValueParser;
+
+ListValueParser BindToListParser(const base::Callback<void()>& handler) {
+ return base::Bind(&internal::ParseAndHandle0, handler);
+}
+
+template <class A1>
+ListValueParser BindToListParser(const base::Callback<void(A1)>& handler) {
+ return base::Bind(&internal::ParseAndHandle1<A1>, handler);
+}
+
+template <class A1, class A2>
+ListValueParser BindToListParser(const base::Callback<void(A1,A2)>& handler) {
+ return base::Bind(&internal::ParseAndHandle2<A1, A2>, handler);
+}
+
+template <class A1, class A2, class A3>
+ListValueParser BindToListParser(
+ const base::Callback<void(A1,A2,A3)>& handler) {
+ return base::Bind(&internal::ParseAndHandle3<A1, A2, A3>, handler);
+}
+
+#endif // CHROME_BROWSER_DEVTOOLS_LIST_VALUE_PARSER_H_
« no previous file with comments | « chrome/browser/devtools/devtools_window.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698