Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2897)

Unified Diff: chrome/browser/cocoa/keyword_editor_cocoa_controller.mm

Issue 220040: [Mac] Enable "Edit Search Engines" in Omnibox context menu. (Closed)
Patch Set: nop to make sure I'm logging in. Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
diff --git a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
index 4d90f15ccb72ef8138b4f198cd13ccafa754671d..4e6a265c054051a3341817041863accc316c2aa7 100644
--- a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
+++ b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
@@ -51,8 +51,52 @@ void KeywordEditorModelObserver::OnEditedKeyword(
// KeywordEditorCocoaController -----------------------------------------------
+namespace {
+
+typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap;
+
+} // namespace
+
@implementation KeywordEditorCocoaController
++ (KeywordEditorCocoaController*)sharedInstanceForProfile:(Profile*)profile {
+ ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
+ DCHECK(map != NULL);
+ ProfileControllerMap::iterator it = map->find(profile);
+ if (it != map->end()) {
+ return it->second;
+ }
+ return nil;
+}
+
+// TODO(shess): The Windows code watches a single global window which
+// is not distinguished by profile. This code could distinguish by
+// profile by checking the controller's class and profile.
++ (void)showKeywordEditor:(Profile*)profile {
+ // http://crbug.com/23359 describes a case where this panel is
+ // opened from an incognito window, which can leave the panel
+ // holding onto a stale profile. Since the same panel is used
+ // either way, arrange to use the original profile instead.
+ if (profile->IsOffTheRecord()) {
+ profile = profile->GetOriginalProfile();
+ }
+
+ ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
+ DCHECK(map != NULL);
+ ProfileControllerMap::iterator it = map->find(profile);
+ if (it == map->end()) {
+ // Since we don't currently support multiple profiles, this class
+ // has not been tested against them, so document that assumption.
+ DCHECK_EQ(map->size(), 0U);
+
+ KeywordEditorCocoaController* controller =
+ [[self alloc] initWithProfile:profile];
+ it = map->insert(std::make_pair(profile, controller)).first;
+ }
+
+ [it->second showWindow:nil];
+}
+
- (id)initWithProfile:(Profile*)profile {
DCHECK(profile);
NSString* nibpath = [mac_util::MainAppBundle()
@@ -96,6 +140,16 @@ void KeywordEditorModelObserver::OnEditedKeyword(
// When the window closes, clean ourselves up.
- (void)windowWillClose:(NSNotification*)notif {
[self autorelease];
+
+ ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
+ ProfileControllerMap::iterator it = map->find(profile_);
+ // It should not be possible for this to be missing.
+ // TODO(shess): Except that the unit test reaches in directly.
+ // Consider circling around and refactoring that.
+ //DCHECK(it != map->end());
+ if (it != map->end()) {
+ map->erase(it);
+ }
}
// The last page info window that was moved will determine the location of the

Powered by Google App Engine
This is Rietveld 408576698