diff options
author | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-06 01:42:39 +0000 |
---|---|---|
committer | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-06 01:42:39 +0000 |
commit | 5cb5ff33998335f9f3be415bfe211c16e76c49a9 (patch) | |
tree | 6f65eda745eb68461597f35f62446e722b55841b /chrome/browser/automation/automation_event_queue.h | |
parent | f37d483f4ce280edd3dad6a4f59b38e3b0cd94e2 (diff) | |
download | chromium_src-5cb5ff33998335f9f3be415bfe211c16e76c49a9.zip chromium_src-5cb5ff33998335f9f3be415bfe211c16e76c49a9.tar.gz chromium_src-5cb5ff33998335f9f3be415bfe211c16e76c49a9.tar.bz2 |
Implementation of AutomationEventQueue and associated framework to support generic non-blocking automation events.
Change-Id: I39f50d1d5b321a863572eec6c61e11923092ed47
BUG=98289
TEST=functional/apptest.py
Review URL: http://codereview.chromium.org/9372120
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_event_queue.h')
-rw-r--r-- | chrome/browser/automation/automation_event_queue.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_event_queue.h b/chrome/browser/automation/automation_event_queue.h new file mode 100644 index 0000000..1633e8a --- /dev/null +++ b/chrome/browser/automation/automation_event_queue.h @@ -0,0 +1,76 @@ +// 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_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_ +#define CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_ + +#include <list> +#include <map> + +#include "base/memory/scoped_ptr.h" +#include "base/values.h" + +class AutomationEventObserver; +class AutomationJSONReply; + +// AutomationEventQueue maintains a queue of unhandled automation events. +class AutomationEventQueue { + public: + AutomationEventQueue(); + virtual ~AutomationEventQueue(); + + // AutomationEvent stores return data dictionay for a single event. + class AutomationEvent { + public: + AutomationEvent(int observer_id, DictionaryValue* event_value); + virtual ~AutomationEvent() {} + + int GetId() const { return observer_id_; } + DictionaryValue* GetValue() { return event_value_.get(); } + DictionaryValue* ReleaseValue() { return event_value_.release(); } + + private: + int observer_id_; + scoped_ptr<DictionaryValue> event_value_; + }; + + void GetNextEvent(AutomationJSONReply* reply, + int observer_id, + bool blocking); + void NotifyEvent(AutomationEvent* event); + void Clear(); + bool IsEmpty() const; + AutomationEvent* PopEvent(); + AutomationEvent* PopEvent(int observer_id); + + int AddObserver(AutomationEventObserver* observer); + bool RemoveObserver(int observer_id); + + private: + class CompareObserverId { + public: + explicit CompareObserverId(int id); + bool operator()(AutomationEvent* event) const; + + private: + int id_; + }; + + void ClearEvents(); + void ClearObservers(); + bool CheckReturnEvent(); + + std::list<AutomationEvent*> event_queue_; + std::map<int, AutomationEventObserver*> observers_; + int observer_id_count_; + + // These store the automation reply data when GetNextEvent is called with no + // matching event in the queue and blocking is requested. + scoped_ptr<AutomationJSONReply> wait_automation_reply_; + int wait_observer_id_; + + DISALLOW_COPY_AND_ASSIGN(AutomationEventQueue); +}; + +#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_QUEUE_H_ |