Add support for a "split" incognito behavior for extensions.
- On by default for apps, off by default for extensions.
- Split mode means "run incognito extensions in a separate process if the user
says OK, and the two processes can only see their own profile."
- Spanning mode is what we have now, and means "run a single extension process,
but allow it to access both profiles if the user says OK."

BUG=49232
BUG=49114
TEST=extensions still work in incognito when you check "Allow in Incognito".

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58033 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h
index 5f71806..d284275 100644
--- a/chrome/browser/extensions/extension_process_manager.h
+++ b/chrome/browser/extensions/extension_process_manager.h
@@ -24,17 +24,18 @@
 class RenderProcessHost;
 class SiteInstance;
 
-// Manages dynamic state of running Chromium extensions.  There is one instance
-// of this class per Profile (including OTR).
+// Manages dynamic state of running Chromium extensions. There is one instance
+// of this class per Profile. OTR Profiles have a separate instance that keeps
+// track of split-mode extensions only.
 class ExtensionProcessManager : public NotificationObserver {
  public:
-  explicit ExtensionProcessManager(Profile* profile);
-  ~ExtensionProcessManager();
+  static ExtensionProcessManager* Create(Profile* profile);
+  virtual ~ExtensionProcessManager();
 
   // Creates a new ExtensionHost with its associated view, grouping it in the
   // appropriate SiteInstance (and therefore process) based on the URL and
   // profile.
-  ExtensionHost* CreateView(Extension* extension,
+  virtual ExtensionHost* CreateView(Extension* extension,
                             const GURL& url,
                             Browser* browser,
                             ViewType::Type view_type);
@@ -51,19 +52,19 @@
   ExtensionHost* CreateInfobar(const GURL& url,
                                Browser* browser);
 
-  // Creates a new UI-less extension instance.  Like CreateView, but not
-  // displayed anywhere.
-  ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url);
-
   // Open the extension's options page.
   void OpenOptionsPage(Extension* extension, Browser* browser);
 
+  // Creates a new UI-less extension instance.  Like CreateView, but not
+  // displayed anywhere.
+  virtual void CreateBackgroundHost(Extension* extension, const GURL& url);
+
   // Gets the ExtensionHost for the background page for an extension, or NULL if
   // the extension isn't running or doesn't have a background page.
   ExtensionHost* GetBackgroundHostForExtension(Extension* extension);
 
   // Returns the SiteInstance that the given URL belongs to.
-  SiteInstance* GetSiteInstanceForURL(const GURL& url);
+  virtual SiteInstance* GetSiteInstanceForURL(const GURL& url);
 
   // Registers an extension process by |extension_id| and specifying which
   // |process_id| it belongs to.
@@ -74,33 +75,33 @@
   void UnregisterExtensionProcess(int process_id);
 
   // Returns the extension process that |url| is associated with if it exists.
-  RenderProcessHost* GetExtensionProcess(const GURL& url);
+  virtual RenderProcessHost* GetExtensionProcess(const GURL& url);
 
   // Returns the process that the extension with the given ID is running in.
-  // NOTE: This does not currently handle app processes with no
-  // ExtensionFunctionDispatcher objects.
   RenderProcessHost* GetExtensionProcess(const std::string& extension_id);
 
   // Returns true if |host| is managed by this process manager.
   bool HasExtensionHost(ExtensionHost* host) const;
 
-  // NotificationObserver:
-  virtual void Observe(NotificationType type,
-                       const NotificationSource& source,
-                       const NotificationDetails& details);
-
   typedef std::set<ExtensionHost*> ExtensionHostSet;
   typedef ExtensionHostSet::const_iterator const_iterator;
   const_iterator begin() const { return all_hosts_.begin(); }
   const_iterator end() const { return all_hosts_.end(); }
 
- private:
+ protected:
+  explicit ExtensionProcessManager(Profile* profile);
+
   // Called just after |host| is created so it can be registered in our lists.
   void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
 
   // Called on browser shutdown to close our extension hosts.
   void CloseBackgroundHosts();
 
+  // NotificationObserver:
+  virtual void Observe(NotificationType type,
+                       const NotificationSource& source,
+                       const NotificationDetails& details);
+
   NotificationRegistrar registrar_;
 
   // The set of all ExtensionHosts managed by this process manager.