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.
5 #ifndef CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_CLIENT_H_
6 #define CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_CLIENT_H_
10 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h"
14 class DictionaryValue;
18 class DevToolsEventListener;
21 // A DevTools client of a single DevTools debugger.
22 class DevToolsClient {
24 typedef base::Callback<Status(bool* is_condition_met)> ConditionalFunc;
26 virtual ~DevToolsClient() {}
28 virtual const std::string& GetId() = 0;
30 virtual bool WasCrashed() = 0;
32 // Connect to DevTools if the DevToolsClient is disconnected.
33 virtual Status ConnectIfNecessary() = 0;
35 virtual Status SendCommand(const std::string& method,
36 const base::DictionaryValue& params) = 0;
37 virtual Status SendCommandAndGetResult(
38 const std::string& method,
39 const base::DictionaryValue& params,
40 scoped_ptr<base::DictionaryValue>* result) = 0;
42 // Adds a listener. This must only be done when the client is disconnected.
43 virtual void AddListener(DevToolsEventListener* listener) = 0;
45 // Handles events until the given function reports the condition is met
46 // and there are no more received events to handle. If the given
47 // function ever returns an error, returns immediately with the error.
48 // If the condition is not met within |timeout|, kTimeout status
49 // is returned eventually. If |timeout| is 0, this function will not block.
50 virtual Status HandleEventsUntil(const ConditionalFunc& conditional_func,
51 const base::TimeDelta& timeout) = 0;
53 // Handles events that have been received but not yet handled.
54 virtual Status HandleReceivedEvents() = 0;
57 #endif // CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_CLIENT_H_