summaryrefslogtreecommitdiffstats
path: root/chrome/test/chromedriver/command_executor_impl.h
blob: 63cdc229802d2a12c909f7c7bd294b31c6fa5f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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.

#ifndef CHROME_TEST_CHROMEDRIVER_COMMAND_EXECUTOR_IMPL_H_
#define CHROME_TEST_CHROMEDRIVER_COMMAND_EXECUTOR_IMPL_H_

#include <map>
#include <string>

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "chrome/test/chromedriver/command_executor.h"
#include "chrome/test/chromedriver/status.h"

namespace base {
class DictionaryValue;
class Value;
}

class CommandExecutorImpl : public CommandExecutor {
 public:
  CommandExecutorImpl();
  virtual ~CommandExecutorImpl();

  // Overriden from CommandExecutor:
  virtual void ExecuteCommand(const std::string& name,
                              const base::DictionaryValue& params,
                              const std::string& session_id,
                              StatusCode* status_code,
                              scoped_ptr<base::Value>* value,
                              std::string* out_session_id) OVERRIDE;

 private:
  typedef base::Callback<void(
      const base::DictionaryValue& params,
      Status* status,
      scoped_ptr<base::Value>* value)>
          SessionCommandCallback;
  typedef std::map<std::string, SessionCommandCallback> SessionCommandMap;

  void ExecuteCommandInternal(
      const std::string& name,
      const base::DictionaryValue& params,
      const std::string& session_id,
      Status* status,
      scoped_ptr<base::Value>* value,
      std::string* out_session_id);

  void ExecuteNewSession(std::string* session_id);

  base::Lock lock_;
  int next_session_id_;
  SessionCommandMap session_command_map_;

  DISALLOW_COPY_AND_ASSIGN(CommandExecutorImpl);
};

#endif  // CHROME_TEST_CHROMEDRIVER_COMMAND_EXECUTOR_IMPL_H_