Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / automation / automation_event_queue.h
blob7548ccce70337ecf20d05047620cd1268082172e
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_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_
6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_
8 #include <list>
9 #include <map>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
14 class AutomationEventObserver;
15 class AutomationJSONReply;
17 // AutomationEventQueue maintains a queue of unhandled automation events.
18 class AutomationEventQueue {
19 public:
20 AutomationEventQueue();
21 virtual ~AutomationEventQueue();
23 // AutomationEvent stores return data dictionay for a single event.
24 class AutomationEvent {
25 public:
26 AutomationEvent(int observer_id, base::DictionaryValue* event_value);
27 virtual ~AutomationEvent() {}
29 int GetId() const { return observer_id_; }
30 base::DictionaryValue* GetValue() { return event_value_.get(); }
31 base::DictionaryValue* ReleaseValue() { return event_value_.release(); }
33 private:
34 int observer_id_;
35 scoped_ptr<base::DictionaryValue> event_value_;
38 void GetNextEvent(AutomationJSONReply* reply,
39 int observer_id,
40 bool blocking);
41 void NotifyEvent(AutomationEvent* event);
42 void Clear();
43 bool IsEmpty() const;
44 AutomationEvent* PopEvent();
45 AutomationEvent* PopEvent(int observer_id);
47 int AddObserver(AutomationEventObserver* observer);
48 bool RemoveObserver(int observer_id);
50 private:
51 class CompareObserverId {
52 public:
53 explicit CompareObserverId(int id);
54 bool operator()(AutomationEvent* event) const;
56 private:
57 int id_;
60 void ClearEvents();
61 void ClearObservers();
62 bool CheckReturnEvent();
64 std::list<AutomationEvent*> event_queue_;
65 std::map<int, AutomationEventObserver*> observers_;
66 int observer_id_count_;
68 // These store the automation reply data when GetNextEvent is called with no
69 // matching event in the queue and blocking is requested.
70 scoped_ptr<AutomationJSONReply> wait_automation_reply_;
71 int wait_observer_id_;
73 DISALLOW_COPY_AND_ASSIGN(AutomationEventQueue);
76 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_