Fix crash caused by dup-sections in Passwords VC.

Currently, activating search bar in PasswordsTableViewController will
remove the "save passwords" switch section, and deactivating the search
bar will add it back.

However, PasswordsTableViewController.loadModel doesn't check the
status of search bar when adding switch section, so dup-sections
will happen in this scenario:

1. PasswordsTableViewController is inited;
2. Switch section is added in |loadModel|;
3. User activates the search bar;
4. Switch section is removed in |willPresentSearchController|;
5. |onGetPasswordStoreResults| is called, which will call |loadModel|;
6. |loadModel| adds the switch section;
7. User deactivates the search bar;
8. Another switch section is added back in |willDismissSearchController|.

And dup switch sections will cause a crash in following steps:
1. User taps "Edit";
2. User selects the switch item in the second switch section;
3. User taps "Delete".

The crash happens because the SettingsSwitchItem will be cast to
Passwords SavedFormContentItem, which leads to corrupted memory.

Bug: 943649
Change-Id: Ic486886cefb1aceda3a8a986502a8ffb1a34e019
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1533945
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Auto-Submit: Yi Su <mrsuyi@chromium.org>
Reviewed-by: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643106}
1 file changed