summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation/automation_provider_json.h
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-11 06:48:40 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-11 06:48:40 +0000
commitd1c458a237273c3804131db7fc9a55aa67af48b6 (patch)
treebc65d32671df767b9b28c22e67a6d39a5ec05f4a /chrome/browser/automation/automation_provider_json.h
parenteb5a99382badcaa174272a2a7c5b3ac11286d6e5 (diff)
downloadchromium_src-d1c458a237273c3804131db7fc9a55aa67af48b6.zip
chromium_src-d1c458a237273c3804131db7fc9a55aa67af48b6.tar.gz
chromium_src-d1c458a237273c3804131db7fc9a55aa67af48b6.tar.bz2
Refactor json automation interface for pyauto hooks.
Reduces the number of lines you need to add per new automation hook. Shaves off several lines of code. Refactor pyauto.py to obviate raising exception in case the json interfaces produces an error string. Review URL: http://codereview.chromium.org/2898001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52054 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_provider_json.h')
-rw-r--r--chrome/browser/automation/automation_provider_json.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider_json.h b/chrome/browser/automation/automation_provider_json.h
new file mode 100644
index 0000000..58f2c1f
--- /dev/null
+++ b/chrome/browser/automation/automation_provider_json.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2010 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.
+
+// Support utilities for the JSON automation interface used by PyAuto.
+// Automation call is initiated by SendJSONRequest() in browser_proxy.h which
+// is serviced by handlers in automation_provider.cc and the resulting
+// success/error reply is sent using AutomationJSONReply defined here.
+
+#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
+#define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
+
+#include <string>
+
+#include "base/values.h"
+#include "ipc/ipc_message.h"
+#include "chrome/browser/automation/automation_provider.h"
+
+// Represent a reply on the JSON Automation interface used by PyAuto.
+class AutomationJSONReply {
+
+ public:
+ // Creates a new reply object for the IPC message |reply_message| for
+ // |provider|.
+ AutomationJSONReply(AutomationProvider* provider,
+ IPC::Message* reply_message);
+
+ ~AutomationJSONReply();
+
+ // Send a success reply along with data contained in |value|.
+ // An empty message will be sent if |value| is NULL.
+ void SendSuccess(const Value* value);
+
+ // Send an error reply along with error message |error_mesg|.
+ void SendError(const std::string& error_mesg);
+
+ private:
+ // Util for creating a JSON error return string (dict with key
+ // 'error' and error string value). No need to quote input.
+ static std::string JSONErrorString(const std::string& err);
+
+ AutomationProvider* provider_;
+ IPC::Message* message_;
+};
+
+#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
+