Replace Profile with content::BrowserContext in menu related extension classes

BUG=388383,397320
[email protected]

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286055 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/context_menu_matcher.cc b/chrome/browser/extensions/context_menu_matcher.cc
index 0e7adbd..0fef92a 100644
--- a/chrome/browser/extensions/context_menu_matcher.cc
+++ b/chrome/browser/extensions/context_menu_matcher.cc
@@ -2,12 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "chrome/browser/extensions/context_menu_matcher.h"
+
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/extensions/context_menu_matcher.h"
 #include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/extensions/extension_util.h"
-#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/browser_context.h"
 #include "content/public/common/context_menu_params.h"
 #include "extensions/browser/extension_system.h"
 #include "ui/gfx/favicon_size.h"
@@ -19,11 +20,13 @@
 const size_t ContextMenuMatcher::kMaxExtensionItemTitleLength = 75;
 
 ContextMenuMatcher::ContextMenuMatcher(
-    Profile* profile,
+    content::BrowserContext* browser_context,
     ui::SimpleMenuModel::Delegate* delegate,
     ui::SimpleMenuModel* menu_model,
     const base::Callback<bool(const MenuItem*)>& filter)
-    : profile_(profile), menu_model_(menu_model), delegate_(delegate),
+    : browser_context_(browser_context),
+      menu_model_(menu_model),
+      delegate_(delegate),
       filter_(filter) {
 }
 
@@ -139,8 +142,8 @@
   if (!item)
     return;
 
-  MenuManager* manager = MenuManager::Get(profile_);
-  manager->ExecuteCommand(profile_, web_contents, params, item->id());
+  MenuManager* manager = MenuManager::Get(browser_context_);
+  manager->ExecuteCommand(browser_context_, web_contents, params, item->id());
 }
 
 bool ContextMenuMatcher::GetRelevantExtensionTopLevelItems(
@@ -149,19 +152,19 @@
     bool* can_cross_incognito,
     MenuItem::List& items) {
   ExtensionService* service =
-      extensions::ExtensionSystem::Get(profile_)->extension_service();
+      extensions::ExtensionSystem::Get(browser_context_)->extension_service();
   *extension = service->GetExtensionById(extension_key.extension_id, false);
 
   if (!*extension)
     return false;
 
   // Find matching items.
-  MenuManager* manager = MenuManager::Get(profile_);
+  MenuManager* manager = MenuManager::Get(browser_context_);
   const MenuItem::List* all_items = manager->MenuItems(extension_key);
   if (!all_items || all_items->empty())
     return false;
 
-  *can_cross_incognito = util::CanCrossIncognito(*extension, profile_);
+  *can_cross_incognito = util::CanCrossIncognito(*extension, browser_context_);
   items = GetRelevantExtensionItems(*all_items,
                                     *can_cross_incognito);
 
@@ -179,7 +182,7 @@
     if (!filter_.Run(item))
       continue;
 
-    if (item->id().incognito == profile_->IsOffTheRecord() ||
+    if (item->id().incognito == browser_context_->IsOffTheRecord() ||
         can_cross_incognito)
       result.push_back(*i);
   }
@@ -246,7 +249,7 @@
 }
 
 MenuItem* ContextMenuMatcher::GetExtensionMenuItem(int id) const {
-  MenuManager* manager = MenuManager::Get(profile_);
+  MenuManager* manager = MenuManager::Get(browser_context_);
   std::map<int, MenuItem::Id>::const_iterator i =
       extension_item_map_.find(id);
   if (i != extension_item_map_.end()) {
@@ -258,7 +261,7 @@
 }
 
 void ContextMenuMatcher::SetExtensionIcon(const std::string& extension_id) {
-  MenuManager* menu_manager = MenuManager::Get(profile_);
+  MenuManager* menu_manager = MenuManager::Get(browser_context_);
 
   int index = menu_model_->GetItemCount() - 1;
   DCHECK_GE(index, 0);
diff --git a/chrome/browser/extensions/context_menu_matcher.h b/chrome/browser/extensions/context_menu_matcher.h
index 782b8d3f..bb08510 100644
--- a/chrome/browser/extensions/context_menu_matcher.h
+++ b/chrome/browser/extensions/context_menu_matcher.h
@@ -14,7 +14,10 @@
 #include "ui/base/models/simple_menu_model.h"
 
 class ExtensionContextMenuBrowserTest;
-class Profile;
+
+namespace content {
+class BrowserContext;
+}
 
 namespace extensions {
 
@@ -26,7 +29,7 @@
 
   // The |filter| will be called on possibly matching menu items, and its
   // result is used to determine which items to actually append to the menu.
-  ContextMenuMatcher(Profile* profile,
+  ContextMenuMatcher(content::BrowserContext* context,
                      ui::SimpleMenuModel::Delegate* delegate,
                      ui::SimpleMenuModel* menu_model,
                      const base::Callback<bool(const MenuItem*)>& filter);
@@ -78,7 +81,7 @@
   // This will set the icon on the most recently-added item in the menu_model_.
   void SetExtensionIcon(const std::string& extension_id);
 
-  Profile* profile_;
+  content::BrowserContext* browser_context_;
   ui::SimpleMenuModel* menu_model_;
   ui::SimpleMenuModel::Delegate* delegate_;
 
diff --git a/chrome/browser/extensions/menu_manager.cc b/chrome/browser/extensions/menu_manager.cc
index 49e7f90..b102eb14 100644
--- a/chrome/browser/extensions/menu_manager.cc
+++ b/chrome/browser/extensions/menu_manager.cc
@@ -303,9 +303,11 @@
 const char MenuManager::kOnWebviewContextMenus[] =
     "webViewInternal.contextMenus";
 
-MenuManager::MenuManager(Profile* profile, StateStore* store)
-    : extension_registry_observer_(this), profile_(profile), store_(store) {
-  extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
+MenuManager::MenuManager(content::BrowserContext* context, StateStore* store)
+    : extension_registry_observer_(this),
+      browser_context_(context),
+      store_(store) {
+  extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
   registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
                  content::NotificationService::AllSources());
   if (store_)
@@ -320,8 +322,8 @@
 }
 
 // static
-MenuManager* MenuManager::Get(Profile* profile) {
-  return MenuManagerFactory::GetForProfile(profile);
+MenuManager* MenuManager::Get(content::BrowserContext* context) {
+  return MenuManagerFactory::GetForBrowserContext(context);
 }
 
 std::set<MenuItem::ExtensionKey> MenuManager::ExtensionIds() {
@@ -364,7 +366,7 @@
 
   // If this is the first item for this extension, start loading its icon.
   if (first_item)
-    icon_manager_.LoadIcon(profile_, extension);
+    icon_manager_.LoadIcon(browser_context_, extension);
 
   return true;
 }
@@ -602,11 +604,11 @@
     dictionary->SetString(key, url.possibly_invalid_spec());
 }
 
-void MenuManager::ExecuteCommand(Profile* profile,
+void MenuManager::ExecuteCommand(content::BrowserContext* context,
                                  WebContents* web_contents,
                                  const content::ContextMenuParams& params,
                                  const MenuItem::Id& menu_item_id) {
-  EventRouter* event_router = EventRouter::Get(profile);
+  EventRouter* event_router = EventRouter::Get(context);
   if (!event_router)
     return;
 
@@ -616,7 +618,7 @@
 
   // ExtensionService/Extension can be NULL in unit tests :(
   ExtensionService* service =
-      ExtensionSystem::Get(profile_)->extension_service();
+      ExtensionSystem::Get(browser_context_)->extension_service();
   const Extension* extension =
       service ? service->extensions()->GetByID(item->extension_id()) : NULL;
 
@@ -703,7 +705,7 @@
         new Event(webview_guest ? kOnWebviewContextMenus
                                 : kOnContextMenus,
                   scoped_ptr<base::ListValue>(args->DeepCopy())));
-    event->restrict_to_browser_context = profile;
+    event->restrict_to_browser_context = context;
     event->user_gesture = EventRouter::USER_GESTURE_ENABLED;
     event_router->DispatchEventToExtension(item->extension_id(), event.Pass());
   }
@@ -713,7 +715,7 @@
         new Event(webview_guest ? web_view::OnClicked::kEventName
                                 : context_menus::OnClicked::kEventName,
                   args.Pass()));
-    event->restrict_to_browser_context = profile;
+    event->restrict_to_browser_context = context;
     event->user_gesture = EventRouter::USER_GESTURE_ENABLED;
     if (webview_guest)
       event->filter_info.SetInstanceID(webview_guest->view_instance_id());
@@ -802,9 +804,10 @@
 
 void MenuManager::ReadFromStorage(const std::string& extension_id,
                                   scoped_ptr<base::Value> value) {
-  const Extension* extension =
-      ExtensionSystem::Get(profile_)->extension_service()->extensions()->
-          GetByID(extension_id);
+  const Extension* extension = ExtensionSystem::Get(browser_context_)
+                                   ->extension_service()
+                                   ->extensions()
+                                   ->GetByID(extension_id);
   if (!extension)
     return;
 
@@ -857,7 +860,7 @@
   // We cannot use profile_->HasOffTheRecordProfile as it may already be
   // false at this point, if for example the incognito profile was destroyed
   // using DestroyOffTheRecordProfile.
-  if (profile->GetOriginalProfile() == profile_ &&
+  if (profile->GetOriginalProfile() == browser_context_ &&
       profile->GetOriginalProfile() != profile) {
     RemoveAllIncognitoContextItems();
   }
diff --git a/chrome/browser/extensions/menu_manager.h b/chrome/browser/extensions/menu_manager.h
index c94ffd0..23a922a 100644
--- a/chrome/browser/extensions/menu_manager.h
+++ b/chrome/browser/extensions/menu_manager.h
@@ -25,10 +25,10 @@
 #include "extensions/browser/extension_registry_observer.h"
 #include "extensions/common/url_pattern_set.h"
 
-class Profile;
 class SkBitmap;
 
 namespace content {
+class BrowserContext;
 class WebContents;
 struct ContextMenuParams;
 }
@@ -275,11 +275,11 @@
   static const char kOnContextMenus[];
   static const char kOnWebviewContextMenus[];
 
-  MenuManager(Profile* profile, StateStore* store_);
+  MenuManager(content::BrowserContext* context, StateStore* store_);
   virtual ~MenuManager();
 
-  // Convenience function to get the MenuManager for a Profile.
-  static MenuManager* Get(Profile* profile);
+  // Convenience function to get the MenuManager for a browser context.
+  static MenuManager* Get(content::BrowserContext* context);
 
   // Returns the keys of extensions which have menu items registered.
   std::set<MenuItem::ExtensionKey> ExtensionIds();
@@ -327,7 +327,7 @@
   bool ItemUpdated(const MenuItem::Id& id);
 
   // Called when a menu item is clicked on by the user.
-  void ExecuteCommand(Profile* profile,
+  void ExecuteCommand(content::BrowserContext* context,
                       content::WebContents* web_contents,
                       const content::ContextMenuParams& params,
                       const MenuItem::Id& menu_item_id);
@@ -395,7 +395,7 @@
 
   ExtensionIconManager icon_manager_;
 
-  Profile* profile_;
+  content::BrowserContext* browser_context_;
 
   // Owned by ExtensionSystem.
   StateStore* store_;
diff --git a/chrome/browser/extensions/menu_manager_factory.cc b/chrome/browser/extensions/menu_manager_factory.cc
index c90d888a..60fa844d 100644
--- a/chrome/browser/extensions/menu_manager_factory.cc
+++ b/chrome/browser/extensions/menu_manager_factory.cc
@@ -14,10 +14,10 @@
 namespace extensions {
 
 // static
-MenuManager* MenuManagerFactory::GetForProfile(
-    Profile* profile) {
+MenuManager* MenuManagerFactory::GetForBrowserContext(
+    content::BrowserContext* context) {
   return static_cast<MenuManager*>(
-      GetInstance()->GetServiceForBrowserContext(profile, true));
+      GetInstance()->GetServiceForBrowserContext(context, true));
 }
 
 // static
diff --git a/chrome/browser/extensions/menu_manager_factory.h b/chrome/browser/extensions/menu_manager_factory.h
index 72c64d9..cdfdfa4 100644
--- a/chrome/browser/extensions/menu_manager_factory.h
+++ b/chrome/browser/extensions/menu_manager_factory.h
@@ -9,14 +9,16 @@
 #include "base/memory/singleton.h"
 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
 
-class Profile;
+namespace content {
+class BrowserContext;
+}
 
 namespace extensions {
 class MenuManager;
 
 class MenuManagerFactory : public BrowserContextKeyedServiceFactory {
  public:
-  static MenuManager* GetForProfile(Profile* profile);
+  static MenuManager* GetForBrowserContext(content::BrowserContext* context);
 
   static MenuManagerFactory* GetInstance();
 
@@ -27,7 +29,7 @@
   virtual ~MenuManagerFactory();
 
   virtual KeyedService* BuildServiceInstanceFor(
-      content::BrowserContext* profile) const OVERRIDE;
+      content::BrowserContext* context) const OVERRIDE;
   virtual content::BrowserContext* GetBrowserContextToUse(
       content::BrowserContext* context) const OVERRIDE;
   virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE;