Make LoadMonitoringExtensionHostQueue remove itself as an ExtensionHost observer at the correct time.

"Extensions.ExtensionHostMonitoring.NumLoaded" UMA is now correctly recorded.

I also cleaned up ExtensionHost and its Start/Stop events a little to make it
more obvious, but in a way that my previous attempt at this (r320536) won't
cause crashes.

[email protected]
[email protected]

Review URL: https://codereview.chromium.org/1016473002

Cr-Commit-Position: refs/heads/master@{#320806}
diff --git a/extensions/browser/extension_host.h b/extensions/browser/extension_host.h
index 9926161..83d3f119 100644
--- a/extensions/browser/extension_host.h
+++ b/extensions/browser/extension_host.h
@@ -59,7 +59,7 @@
   content::WebContents* host_contents() const { return host_contents_.get(); }
   content::RenderViewHost* render_view_host() const;
   content::RenderProcessHost* render_process_host() const;
-  bool did_stop_loading() const { return did_stop_loading_; }
+  bool has_loaded_once() const { return has_loaded_once_; }
   bool document_element_available() const {
     return document_element_available_;
   }
@@ -131,9 +131,9 @@
                            UnloadedExtensionInfo::Reason reason) override;
 
  protected:
-  // Called after the extension page finishes loading but before the
-  // EXTENSION_HOST_DID_STOP_LOADING notification is sent.
-  virtual void OnDidStopLoading();
+  // Called each time this ExtensionHost completes a load finishes loading,
+  // before any stop-loading notifications or observer methods are called.
+  virtual void OnDidStopFirstLoad();
 
   // Navigates to the initial page.
   virtual void LoadInitialURL();
@@ -155,6 +155,9 @@
   void OnIncrementLazyKeepaliveCount();
   void OnDecrementLazyKeepaliveCount();
 
+  // Records UMA for load events.
+  void RecordStopLoadingUMA();
+
   // Delegate for functionality that cannot exist in the extensions module.
   scoped_ptr<ExtensionHostDelegate> delegate_;
 
@@ -175,8 +178,10 @@
   // host, so we can send messages to it before it finishes loading.
   content::RenderViewHost* render_view_host_;
 
-  // Whether the RenderWidget has reported that it has stopped loading.
-  bool did_stop_loading_;
+  // Whether the ExtensionHost has finished loading some content at least once.
+  // There may be subsequent loads - such as reloads and navigations - and this
+  // will not affect its value (it will remain true).
+  bool has_loaded_once_;
 
   // True if the main frame has finished parsing.
   bool document_element_available_;