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_
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
{
20 AutomationEventQueue();
21 virtual ~AutomationEventQueue();
23 // AutomationEvent stores return data dictionay for a single event.
24 class AutomationEvent
{
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(); }
35 scoped_ptr
<base::DictionaryValue
> event_value_
;
38 void GetNextEvent(AutomationJSONReply
* reply
,
41 void NotifyEvent(AutomationEvent
* event
);
44 AutomationEvent
* PopEvent();
45 AutomationEvent
* PopEvent(int observer_id
);
47 int AddObserver(AutomationEventObserver
* observer
);
48 bool RemoveObserver(int observer_id
);
51 class CompareObserverId
{
53 explicit CompareObserverId(int id
);
54 bool operator()(AutomationEvent
* event
) const;
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_