Remove NOTIFICATION_SESSION_RESTORE_DONE from src/extensions

src/extensions should not listen for notifications from
src/chrome.

NOTIFICATION_SESSION_RESTORE_DONE is used by state_store.cc
to load per-extension state from a database at startup. 
Refactor this so Chrome explicitly requests the StateStore 
to initialize. Other embedders (like app_shell) don't need 
this behavior.

BUG=392660
TEST=browser_tests *Extension*

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286429 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/extensions/browser/state_store.cc b/extensions/browser/state_store.cc
index 82d7caa..3dff825d 100644
--- a/extensions/browser/state_store.cc
+++ b/extensions/browser/state_store.cc
@@ -6,7 +6,6 @@
 
 #include "base/bind.h"
 #include "base/message_loop/message_loop.h"
-#include "chrome/browser/chrome_notification_types.h"
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/notification_types.h"
@@ -74,15 +73,12 @@
   extension_registry_observer_.Add(ExtensionRegistry::Get(context));
 
   if (deferred_load) {
-    // Don't Init until the first page is loaded or the session restored.
+    // Don't Init() until the first page is loaded or the embedder explicitly
+    // requests it.
     registrar_.Add(
         this,
         content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
         content::NotificationService::AllBrowserContextsAndSources());
-    registrar_.Add(
-        this,
-        chrome::NOTIFICATION_SESSION_RESTORE_DONE,
-        content::NotificationService::AllBrowserContextsAndSources());
   } else {
     Init();
   }
@@ -102,6 +98,10 @@
 StateStore::~StateStore() {
 }
 
+void StateStore::RequestInitAfterDelay() {
+  InitAfterDelay();
+}
+
 void StateStore::RegisterKey(const std::string& key) {
   registered_keys_.insert(key);
 }
@@ -138,14 +138,9 @@
 void StateStore::Observe(int type,
                          const content::NotificationSource& source,
                          const content::NotificationDetails& details) {
-  DCHECK(type == chrome::NOTIFICATION_SESSION_RESTORE_DONE ||
-         type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
+  DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
   registrar_.RemoveAll();
-
-  base::MessageLoop::current()->PostDelayedTask(
-      FROM_HERE,
-      base::Bind(&StateStore::Init, AsWeakPtr()),
-      base::TimeDelta::FromSeconds(kInitDelaySeconds));
+  InitAfterDelay();
 }
 
 void StateStore::OnExtensionWillBeInstalled(
@@ -165,11 +160,26 @@
 }
 
 void StateStore::Init() {
+  // Could be called twice if InitAfterDelay() is requested explicitly by the
+  // embedder in addition to internally after first page load.
+  if (IsInitialized())
+    return;
+
   if (!db_path_.empty())
     store_.Init(db_path_);
   task_queue_->SetReady();
 }
 
+void StateStore::InitAfterDelay() {
+  if (IsInitialized())
+    return;
+
+  base::MessageLoop::current()->PostDelayedTask(
+      FROM_HERE,
+      base::Bind(&StateStore::Init, AsWeakPtr()),
+      base::TimeDelta::FromSeconds(kInitDelaySeconds));
+}
+
 void StateStore::RemoveKeysForExtension(const std::string& extension_id) {
   for (std::set<std::string>::iterator key = registered_keys_.begin();
        key != registered_keys_.end();