Fix duplicate samples to SetDefaultResult2 for multiple clicks on infobar

This is needed because it now is possible to click multiple times on the
infobar with the StickyDefaultBrowserPrompt experiment.

BUG=619145

Review-Url: https://codereview.chromium.org/2062313003
Cr-Commit-Position: refs/heads/master@{#400022}
diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc
index 21cbc71..87954bb 100644
--- a/chrome/browser/shell_integration_win.cc
+++ b/chrome/browser/shell_integration_win.cc
@@ -306,7 +306,10 @@
   // watched. The array must contain at least one element.
   static void Begin(const wchar_t* const protocols[],
                     const base::Closure& on_finished_callback) {
-    new OpenSystemSettingsHelper(protocols, on_finished_callback);
+    DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+
+    delete instance_;
+    instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback);
   }
 
  private:
@@ -366,7 +369,8 @@
         "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason,
         NUM_CONCLUDE_REASON_TYPES);
     on_finished_callback_.Run();
-    delete this;
+    delete instance_;
+    instance_ = nullptr;
   }
 
   // Helper function to create a registry watcher for a given |key_path|. Do
@@ -383,6 +387,9 @@
     }
   }
 
+  // Used to make sure only one instance is alive at the same time.
+  static OpenSystemSettingsHelper* instance_;
+
   // This is needed to make sure that Windows displays an entry for the protocol
   // inside the "Choose default apps by protocol" settings page.
   ScopedUserProtocolEntry scoped_user_protocol_entry_;
@@ -412,6 +419,8 @@
   DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper);
 };
 
+OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr;
+
 }  // namespace
 
 bool SetAsDefaultBrowser() {