OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.h" | 7 #import "chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.h" |
8 | 8 |
9 #import "base/mac_util.h" | 9 #import "base/mac_util.h" |
10 #include "base/singleton.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/search_engines/template_url_model.h" | 15 #include "chrome/browser/search_engines/template_url_model.h" |
16 #include "chrome/browser/search_engines/template_url_table_model.h" | 16 #include "chrome/browser/search_engines/template_url_table_model.h" |
17 #import "chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller.h" | 17 #import "chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller.h" |
18 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" | 18 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
(...skipping 73 matching lines...) Loading... |
94 NSImage* KeywordEditorModelObserver::GetImageForRow(int row) { | 94 NSImage* KeywordEditorModelObserver::GetImageForRow(int row) { |
95 return icon_cache_.GetImageForRow(row); | 95 return icon_cache_.GetImageForRow(row); |
96 } | 96 } |
97 | 97 |
98 // KeywordEditorCocoaController ----------------------------------------------- | 98 // KeywordEditorCocoaController ----------------------------------------------- |
99 | 99 |
100 namespace { | 100 namespace { |
101 | 101 |
102 typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap; | 102 typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap; |
103 | 103 |
| 104 static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
| 105 base::LINKER_INITIALIZED); |
| 106 |
104 } // namespace | 107 } // namespace |
105 | 108 |
106 @implementation KeywordEditorCocoaController | 109 @implementation KeywordEditorCocoaController |
107 | 110 |
108 + (KeywordEditorCocoaController*)sharedInstanceForProfile:(Profile*)profile { | 111 + (KeywordEditorCocoaController*)sharedInstanceForProfile:(Profile*)profile { |
109 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); | 112 ProfileControllerMap* map = g_profile_controller_map.Pointer(); |
110 DCHECK(map != NULL); | 113 DCHECK(map != NULL); |
111 ProfileControllerMap::iterator it = map->find(profile); | 114 ProfileControllerMap::iterator it = map->find(profile); |
112 if (it != map->end()) { | 115 if (it != map->end()) { |
113 return it->second; | 116 return it->second; |
114 } | 117 } |
115 return nil; | 118 return nil; |
116 } | 119 } |
117 | 120 |
118 // TODO(shess): The Windows code watches a single global window which | 121 // TODO(shess): The Windows code watches a single global window which |
119 // is not distinguished by profile. This code could distinguish by | 122 // is not distinguished by profile. This code could distinguish by |
120 // profile by checking the controller's class and profile. | 123 // profile by checking the controller's class and profile. |
121 + (void)showKeywordEditor:(Profile*)profile { | 124 + (void)showKeywordEditor:(Profile*)profile { |
122 // http://crbug.com/23359 describes a case where this panel is | 125 // http://crbug.com/23359 describes a case where this panel is |
123 // opened from an incognito window, which can leave the panel | 126 // opened from an incognito window, which can leave the panel |
124 // holding onto a stale profile. Since the same panel is used | 127 // holding onto a stale profile. Since the same panel is used |
125 // either way, arrange to use the original profile instead. | 128 // either way, arrange to use the original profile instead. |
126 profile = profile->GetOriginalProfile(); | 129 profile = profile->GetOriginalProfile(); |
127 | 130 |
128 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); | 131 ProfileControllerMap* map = g_profile_controller_map.Pointer(); |
129 DCHECK(map != NULL); | 132 DCHECK(map != NULL); |
130 ProfileControllerMap::iterator it = map->find(profile); | 133 ProfileControllerMap::iterator it = map->find(profile); |
131 if (it == map->end()) { | 134 if (it == map->end()) { |
132 // Since we don't currently support multiple profiles, this class | 135 // Since we don't currently support multiple profiles, this class |
133 // has not been tested against them, so document that assumption. | 136 // has not been tested against them, so document that assumption. |
134 DCHECK_EQ(map->size(), 0U); | 137 DCHECK_EQ(map->size(), 0U); |
135 | 138 |
136 KeywordEditorCocoaController* controller = | 139 KeywordEditorCocoaController* controller = |
137 [[self alloc] initWithProfile:profile]; | 140 [[self alloc] initWithProfile:profile]; |
138 it = map->insert(std::make_pair(profile, controller)).first; | 141 it = map->insert(std::make_pair(profile, controller)).first; |
(...skipping 48 matching lines...) Loading... |
187 | 190 |
188 [self adjustEditingButtons]; | 191 [self adjustEditingButtons]; |
189 [tableView_ setDoubleAction:@selector(editKeyword:)]; | 192 [tableView_ setDoubleAction:@selector(editKeyword:)]; |
190 [tableView_ setTarget:self]; | 193 [tableView_ setTarget:self]; |
191 } | 194 } |
192 | 195 |
193 // When the window closes, clean ourselves up. | 196 // When the window closes, clean ourselves up. |
194 - (void)windowWillClose:(NSNotification*)notif { | 197 - (void)windowWillClose:(NSNotification*)notif { |
195 [self autorelease]; | 198 [self autorelease]; |
196 | 199 |
197 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); | 200 ProfileControllerMap* map = g_profile_controller_map.Pointer(); |
198 ProfileControllerMap::iterator it = map->find(profile_); | 201 ProfileControllerMap::iterator it = map->find(profile_); |
199 // It should not be possible for this to be missing. | 202 // It should not be possible for this to be missing. |
200 // TODO(shess): Except that the unit test reaches in directly. | 203 // TODO(shess): Except that the unit test reaches in directly. |
201 // Consider circling around and refactoring that. | 204 // Consider circling around and refactoring that. |
202 //DCHECK(it != map->end()); | 205 //DCHECK(it != map->end()); |
203 if (it != map->end()) { | 206 if (it != map->end()) { |
204 map->erase(it); | 207 map->erase(it); |
205 } | 208 } |
206 } | 209 } |
207 | 210 |
(...skipping 205 matching lines...) Loading... |
413 controller_->table_model()->last_search_engine_index() + 1; | 416 controller_->table_model()->last_search_engine_index() + 1; |
414 DCHECK_NE(row, otherGroupId); | 417 DCHECK_NE(row, otherGroupId); |
415 if (row >= otherGroupId) { | 418 if (row >= otherGroupId) { |
416 return row - 2; // Other group. | 419 return row - 2; // Other group. |
417 } else { | 420 } else { |
418 return row - 1; // Default group. | 421 return row - 1; // Default group. |
419 } | 422 } |
420 } | 423 } |
421 | 424 |
422 @end | 425 @end |
OLD | NEW |