Lands http://codereview.chromium.org/9316065/ for Marja. I reviewed
this, so I'm using TBR to land it.

Don't crash if multiple SessionRestoreImpl:s refer to the same
Profile.

It shouldn't ever happen but it seems to happen anyway.

BUG=111238
TEST=NONE
TBR=sky@chromium.org
R=marja@chromium.org

Review URL: https://chromiumcodereview.appspot.com/9343005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120648 0039d316-1c4b-4281-b951-d872f2087c98
  SessionRestoreImpl(Profile* profile,
                     Browser* browser,
                     bool synchronous,
                     bool clobber_existing_tab,
                     bool always_create_tabbed_browser,
                     const std::vector<GURL>& urls_to_open)
      : profile_(profile),
        browser_(browser),
        synchronous_(synchronous),
        clobber_existing_tab_(clobber_existing_tab),
        always_create_tabbed_browser_(always_create_tabbed_browser),
         urls_to_open_(urls_to_open),
         restore_started_(base::TimeTicks::Now()),
         browser_shown_(false) {
 
    // Iterate the active session restorers to find if there is a
    // SessionRestoreImpl referring the same profile. This should not happen but
    // for some reason it happens still. TODO(marja): figure out why.
    if (active_session_restorers == NULL)
      active_session_restorers = new std::set<SessionRestoreImpl*>();

    std::set<SessionRestoreImpl*>::const_iterator it;
    for (it = active_session_restorers->begin();
         it != active_session_restorers->end(); ++it) {
      if ((*it)->profile_ == profile)
        break;
    }
    DCHECK(it == active_session_restorers->end());

    active_session_restorers->insert(this);
 
    g_browser_process->AddRefModule();
  }

  SessionRestoreImpl(Profile* profile,
                     Browser* browser,
                     bool synchronous,
                     bool clobber_existing_tab,
                     bool always_create_tabbed_browser,
                     const std::vector<GURL>& urls_to_open)
      : profile_(profile),
        browser_(browser),
        synchronous_(synchronous),
        clobber_existing_tab_(clobber_existing_tab),
        always_create_tabbed_browser_(always_create_tabbed_browser),
         urls_to_open_(urls_to_open),
         restore_started_(base::TimeTicks::Now()),
         browser_shown_(false) {
    if (profiles_getting_restored == NULL)
      profiles_getting_restored = new std::set<const Profile*>();
 
    CHECK(profiles_getting_restored->find(profile) ==
          profiles_getting_restored->end());
 
    profiles_getting_restored->insert(profile);
    g_browser_process->AddRefModule();
  }
