Minor cleanup. Converts Browser from storing a vector of pending
updates to a map. This simplifies processing and removal.

BUG=1209369
TEST=none

Review URL: http://codereview.chromium.org/250003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27228 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 3875081..9f39153 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -154,19 +154,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-struct Browser::UIUpdate {
-  UIUpdate(const TabContents* src, unsigned flags)
-      : source(src),
-        changed_flags(flags) {
-  }
-
-  // The source of the update.
-  const TabContents* source;
-
-  // What changed in the UI.
-  unsigned changed_flags;
-};
-
 namespace {
 
 // Returns true if the specified TabContents has unload listeners registered.
@@ -2477,7 +2464,7 @@
     return;
 
   // Save the dirty bits.
-  scheduled_updates_.push_back(UIUpdate(source, changed_flags));
+  scheduled_updates_[source] |= changed_flags;
 
   if (chrome_updater_factory_.empty()) {
     // No task currently scheduled, start another.
@@ -2493,11 +2480,11 @@
   // Validate that all tabs we have pending updates for exist. This is scary
   // because the pending list must be kept in sync with any detached or
   // deleted tabs. This code does not dereference any TabContents pointers.
-  for (size_t i = 0; i < scheduled_updates_.size(); i++) {
+  for (UpdateMap::const_iterator i = scheduled_updates_.begin();
+       i != scheduled_updates_.end(); ++i) {
     bool found = false;
     for (int tab = 0; tab < tab_count(); tab++) {
-      if (&GetTabContentsAt(tab)->controller() ==
-          &scheduled_updates_[i].source->controller()) {
+      if (&GetTabContentsAt(tab)->controller() == &i->first->controller()) {
         found = true;
         break;
       }
@@ -2508,29 +2495,11 @@
 
   chrome_updater_factory_.RevokeAll();
 
-  // We could have many updates for the same thing in the queue. This map
-  // tracks the bits of the stuff we've already updated for each TabContents so
-  // we don't update again.
-  typedef std::map<const TabContents*, unsigned> UpdateTracker;
-  UpdateTracker updated_stuff;
-
-  for (size_t i = 0; i < scheduled_updates_.size(); i++) {
+  for (UpdateMap::const_iterator i = scheduled_updates_.begin();
+       i != scheduled_updates_.end(); ++i) {
     // Do not dereference |contents|, it may be out-of-date!
-    const TabContents* contents = scheduled_updates_[i].source;
-    unsigned flags = scheduled_updates_[i].changed_flags;
-
-    // Remove any bits we have already updated, and save the new bits.
-    UpdateTracker::iterator updated = updated_stuff.find(contents);
-    if (updated != updated_stuff.end()) {
-      // Turn off bits already set.
-      flags &= ~updated->second;
-      if (!flags)
-        continue;
-
-      updated->second |= flags;
-    } else {
-      updated_stuff[contents] = flags;
-    }
+    const TabContents* contents = i->first;
+    unsigned flags = i->second;
 
     if (flags & TabContents::INVALIDATE_PAGE_ACTIONS)
       window()->GetLocationBar()->UpdatePageActions();
@@ -2563,15 +2532,9 @@
   if (!contents)
     return;
 
-  // Remove any pending UI updates for the detached tab.
-  UpdateVector::iterator cur_update = scheduled_updates_.begin();
-  while (cur_update != scheduled_updates_.end()) {
-    if (cur_update->source == contents) {
-      cur_update = scheduled_updates_.erase(cur_update);
-    } else {
-      ++cur_update;
-    }
-  }
+  UpdateMap::iterator i = scheduled_updates_.find(contents);
+  if (i != scheduled_updates_.end())
+    scheduled_updates_.erase(i);
 }