OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_dialog_controller_mac.h" | 5 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" |
6 #include "app/l10n_util.h" | 6 #include "app/l10n_util.h" |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/lazy_instance.h" |
8 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
9 #include "base/singleton.h" | |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
11 #import "chrome/browser/autofill/autofill_address_model_mac.h" | 11 #import "chrome/browser/autofill/autofill_address_model_mac.h" |
12 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" | 12 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" |
13 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | 13 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" |
14 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" | 14 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" |
15 #import "chrome/browser/autofill/personal_data_manager.h" | 15 #import "chrome/browser/autofill/personal_data_manager.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" | 17 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
22 #include "chrome/common/notification_details.h" | 22 #include "chrome/common/notification_details.h" |
23 #include "chrome/common/notification_observer.h" | 23 #include "chrome/common/notification_observer.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
26 #include "grit/app_resources.h" | 26 #include "grit/app_resources.h" |
27 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Type for singleton object that contains the instance of the visible | 31 // Type for singleton object that contains the instance of the visible |
32 // dialog. | 32 // dialog. |
33 typedef std::map<Profile*, AutoFillDialogController*> ProfileControllerMap; | 33 typedef std::map<Profile*, AutoFillDialogController*> ProfileControllerMap; |
34 | 34 |
| 35 static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
| 36 base::LINKER_INITIALIZED); |
| 37 |
35 } // namespace | 38 } // namespace |
36 | 39 |
37 // Delegate protocol that needs to be in place for the AutoFillTableView's | 40 // Delegate protocol that needs to be in place for the AutoFillTableView's |
38 // handling of delete and backspace keys. | 41 // handling of delete and backspace keys. |
39 @protocol DeleteKeyDelegate | 42 @protocol DeleteKeyDelegate |
40 - (IBAction)deleteSelection:(id)sender; | 43 - (IBAction)deleteSelection:(id)sender; |
41 @end | 44 @end |
42 | 45 |
43 // A subclass of NSTableView that allows for deleting selected elements using | 46 // A subclass of NSTableView that allows for deleting selected elements using |
44 // the delete or backspace keys. | 47 // the delete or backspace keys. |
(...skipping 216 matching lines...) Loading... |
261 } | 264 } |
262 | 265 |
263 // NSWindow Delegate callback. When the window closes the controller can | 266 // NSWindow Delegate callback. When the window closes the controller can |
264 // be released. | 267 // be released. |
265 - (void)windowWillClose:(NSNotification *)notification { | 268 - (void)windowWillClose:(NSNotification *)notification { |
266 [tableView_ setDataSource:nil]; | 269 [tableView_ setDataSource:nil]; |
267 [tableView_ setDelegate:nil]; | 270 [tableView_ setDelegate:nil]; |
268 [self autorelease]; | 271 [self autorelease]; |
269 | 272 |
270 // Remove ourself from the map. | 273 // Remove ourself from the map. |
271 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); | 274 ProfileControllerMap* map = g_profile_controller_map.Pointer(); |
272 ProfileControllerMap::iterator it = map->find(profile_); | 275 ProfileControllerMap::iterator it = map->find(profile_); |
273 if (it != map->end()) { | 276 if (it != map->end()) { |
274 map->erase(it); | 277 map->erase(it); |
275 } | 278 } |
276 } | 279 } |
277 | 280 |
278 // Invokes the "Add" sheet for address information. If user saves then the new | 281 // Invokes the "Add" sheet for address information. If user saves then the new |
279 // information is added to |profiles_| in |addressAddDidEnd:| method. | 282 // information is added to |profiles_| in |addressAddDidEnd:| method. |
280 - (IBAction)addNewAddress:(id)sender { | 283 - (IBAction)addNewAddress:(id)sender { |
281 DCHECK(!addressSheetController.get()); | 284 DCHECK(!addressSheetController.get()); |
(...skipping 344 matching lines...) Loading... |
626 | 629 |
627 @end | 630 @end |
628 | 631 |
629 @implementation AutoFillDialogController (ExposedForUnitTests) | 632 @implementation AutoFillDialogController (ExposedForUnitTests) |
630 | 633 |
631 + (AutoFillDialogController*) | 634 + (AutoFillDialogController*) |
632 controllerWithObserver:(AutoFillDialogObserver*)observer | 635 controllerWithObserver:(AutoFillDialogObserver*)observer |
633 profile:(Profile*)profile { | 636 profile:(Profile*)profile { |
634 profile = profile->GetOriginalProfile(); | 637 profile = profile->GetOriginalProfile(); |
635 | 638 |
636 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); | 639 ProfileControllerMap* map = g_profile_controller_map.Pointer(); |
637 DCHECK(map != NULL); | 640 DCHECK(map != NULL); |
638 ProfileControllerMap::iterator it = map->find(profile); | 641 ProfileControllerMap::iterator it = map->find(profile); |
639 if (it == map->end()) { | 642 if (it == map->end()) { |
640 // We should have exactly 1 or 0 entry in the map, no more. That is, | 643 // We should have exactly 1 or 0 entry in the map, no more. That is, |
641 // only one profile can have the AutoFill dialog up at a time. | 644 // only one profile can have the AutoFill dialog up at a time. |
642 DCHECK_EQ(map->size(), 0U); | 645 DCHECK_EQ(map->size(), 0U); |
643 | 646 |
644 // Deallocation is done upon window close. See |windowWillClose:|. | 647 // Deallocation is done upon window close. See |windowWillClose:|. |
645 AutoFillDialogController* controller = | 648 AutoFillDialogController* controller = |
646 [[self alloc] initWithObserver:observer profile:profile]; | 649 [[self alloc] initWithObserver:observer profile:profile]; |
(...skipping 255 matching lines...) Loading... |
902 if (!image) { | 905 if (!image) { |
903 image = rb.GetNativeImageNamed(IDR_INPUT_GOOD); | 906 image = rb.GetNativeImageNamed(IDR_INPUT_GOOD); |
904 DCHECK(image); | 907 DCHECK(image); |
905 return image; | 908 return image; |
906 } | 909 } |
907 | 910 |
908 return nil; | 911 return nil; |
909 } | 912 } |
910 | 913 |
911 @end | 914 @end |
OLD | NEW |