automation_provider_json.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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// Support utilities for the JSON automation interface used by PyAuto.
6
7#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
8#define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
9
10#include <string>
11
12#include "base/values.h"
13#include "ipc/ipc_message.h"
14#include "chrome/browser/automation/automation_provider.h"
15
16// Helper to ensure we always send a reply message for JSON automation requests.
17class AutomationJSONReply {
18 public:
19  // Creates a new reply object for the IPC message |reply_message| for
20  // |provider|. The caller is expected to call SendSuccess() or SendError()
21  // before destroying this object.
22  AutomationJSONReply(AutomationProvider* provider,
23                      IPC::Message* reply_message);
24
25  ~AutomationJSONReply();
26
27  // Send a success reply along with data contained in |value|.
28  // An empty message will be sent if |value| is NULL.
29  void SendSuccess(const Value* value);
30
31  // Send an error reply along with error message |error_message|.
32  void SendError(const std::string& error_message);
33
34 private:
35  AutomationProvider* provider_;
36  IPC::Message* message_;
37};
38
39#endif  // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
40
41