1// Copyright 2013 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(function(){ 6 7window.buildbot = window.buildbot || {}; 8 9buildbot.ActiveIssues = function() { 10 this.issues_ = {}; 11 this.eventCallback_ = null; 12}; 13 14buildbot.ActiveIssues.prototype = { 15 forEach: function(callback) { 16 for (var key in this.issues_) 17 callback(this.issues_[key]); 18 }, 19 20 getIssue: function(number) { 21 return this.issues_[number]; 22 }, 23 24 updateIssue: function(issue) { 25 var eventType = this.issues_.hasOwnProperty(issue.issue) ? 26 "issueUpdated" : "issueAdded"; 27 this.issues_[issue.issue] = issue; 28 this.postEvent_({event: eventType, issue: issue.issue}); 29 }, 30 31 removeIssue: function(issue) { 32 delete this.issues_[issue.issue]; 33 this.postEvent_({event: "issueRemoved", issue: issue.issue}); 34 }, 35 36 setEventCallback: function(callback) { 37 this.eventCallback_ = callback; 38 }, 39 40 postEvent_: function(obj) { 41 if (this.eventCallback_) 42 this.eventCallback_(obj); 43 } 44}; 45 46buildbot.getActiveIssues = function() { 47 var background = chrome.extension.getBackgroundPage(); 48 if (!background.buildbot.hasOwnProperty("activeIssues")) 49 background.buildbot.activeIssues = new buildbot.ActiveIssues; 50 51 return background.buildbot.activeIssues; 52}; 53 54})(); 55