- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / automation / automation_event_queue.h
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.
4
5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_
6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_
7
8 #include <list>
9 #include <map>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13
14 class AutomationEventObserver;
15 class AutomationJSONReply;
16
17 // AutomationEventQueue maintains a queue of unhandled automation events.
18 class AutomationEventQueue {
19  public:
20   AutomationEventQueue();
21   virtual ~AutomationEventQueue();
22
23   // AutomationEvent stores return data dictionay for a single event.
24   class AutomationEvent {
25    public:
26     AutomationEvent(int observer_id, DictionaryValue* event_value);
27     virtual ~AutomationEvent() {}
28
29     int GetId() const { return observer_id_; }
30     DictionaryValue* GetValue() { return event_value_.get(); }
31     DictionaryValue* ReleaseValue() { return event_value_.release(); }
32
33    private:
34     int observer_id_;
35     scoped_ptr<DictionaryValue> event_value_;
36   };
37
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);
46
47   int AddObserver(AutomationEventObserver* observer);
48   bool RemoveObserver(int observer_id);
49
50  private:
51   class CompareObserverId {
52    public:
53     explicit CompareObserverId(int id);
54     bool operator()(AutomationEvent* event) const;
55
56    private:
57     int id_;
58   };
59
60   void ClearEvents();
61   void ClearObservers();
62   bool CheckReturnEvent();
63
64   std::list<AutomationEvent*> event_queue_;
65   std::map<int, AutomationEventObserver*> observers_;
66   int observer_id_count_;
67
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_;
72
73   DISALLOW_COPY_AND_ASSIGN(AutomationEventQueue);
74 };
75
76 #endif  // CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_