Chromium Code Reviews| Index: ios/chrome/browser/passwords/password_controller.mm |
| diff --git a/ios/chrome/browser/passwords/password_controller.mm b/ios/chrome/browser/passwords/password_controller.mm |
| index 2545cb32daa4731de8d79738b855fadfcc8b7946..4cd3e30c2fcde01d45df2bd850e9798903b04472 100644 |
| --- a/ios/chrome/browser/passwords/password_controller.mm |
| +++ b/ios/chrome/browser/passwords/password_controller.mm |
| @@ -12,11 +12,9 @@ |
| #include <utility> |
| #include <vector> |
| -#import "base/ios/weak_nsobject.h" |
| #include "base/json/json_reader.h" |
| #include "base/json/json_writer.h" |
| #include "base/mac/foundation_util.h" |
| -#include "base/mac/scoped_nsobject.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/sys_string_conversions.h" |
| @@ -46,6 +44,10 @@ |
| #import "ios/web/public/web_state/web_state.h" |
| #include "url/gurl.h" |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| using password_manager::PasswordFormManager; |
| using password_manager::PasswordGenerationManager; |
| using password_manager::PasswordManager; |
| @@ -62,6 +64,9 @@ enum class PasswordInfoBarType { SAVE, UPDATE }; |
| // This is set to YES as soon as the associated WebState is destroyed. |
| @property(readonly) BOOL isWebStateDestroyed; |
| +// Accessor for property inside block. |
| +@property(readonly) PasswordManager* passwordManager; |
| + |
| @end |
| @interface PasswordController ()<FormSuggestionProvider> |
| @@ -253,7 +258,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| std::unique_ptr<PasswordGenerationManager> passwordGenerationManager_; |
| std::unique_ptr<PasswordManagerClient> passwordManagerClient_; |
| std::unique_ptr<PasswordManagerDriver> passwordManagerDriver_; |
| - base::scoped_nsobject<PasswordGenerationAgent> passwordGenerationAgent_; |
| + PasswordGenerationAgent* passwordGenerationAgent_; |
| JsPasswordManager* passwordJsManager_; // weak |
| web::WebState* webState_; // weak |
| @@ -293,11 +298,11 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| !passwordManagerClient_->IsIncognito()) { |
| passwordGenerationManager_.reset(new PasswordGenerationManager( |
| passwordManagerClient_.get(), passwordManagerDriver_.get())); |
| - passwordGenerationAgent_.reset([[PasswordGenerationAgent alloc] |
| + passwordGenerationAgent_ = [[PasswordGenerationAgent alloc] |
| initWithWebState:webState |
| passwordManager:passwordManager_.get() |
| passwordManagerDriver:passwordManagerDriver_.get() |
| - passwordsUiDelegate:UIDelegate]); |
| + passwordsUiDelegate:UIDelegate]; |
| } |
| passwordJsManager_ = base::mac::ObjCCastStrict<JsPasswordManager>( |
| @@ -316,7 +321,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| - (void)dealloc { |
| [self detach]; |
| - [super dealloc]; |
| + ; |
|
vabr (Chromium)
2017/06/13 15:23:52
nit: Should this whole line be deleted?
marq (ping after 24h)
2017/06/13 17:39:04
Done.
|
| } |
| - (ios::ChromeBrowserState*)browserState { |
| @@ -334,7 +339,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| - (void)detach { |
| webState_ = nullptr; |
| webStateObserverBridge_.reset(); |
| - passwordGenerationAgent_.reset(); |
| + passwordGenerationAgent_ = nil; |
| passwordGenerationManager_.reset(); |
| passwordManagerDriver_.reset(); |
| passwordManager_.reset(); |
| @@ -391,7 +396,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| // Read all password forms from the page and send them to the password |
| // manager. |
| - base::WeakNSObject<PasswordController> weakSelf(self); |
| + __weak PasswordController* weakSelf = self; |
| [self findPasswordFormsWithCompletionHandler:^( |
| const std::vector<autofill::PasswordForm>& forms) { |
| [weakSelf didFinishPasswordFormExtraction:forms]; |
| @@ -401,15 +406,16 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| - (void)webState:(web::WebState*)webState |
| didSubmitDocumentWithFormNamed:(const std::string&)formName |
| userInitiated:(BOOL)userInitiated { |
| - base::WeakNSObject<PasswordController> weakSelf(self); |
| + __weak PasswordController* weakSelf = self; |
| // This code is racing against the new page loading and will not get the |
| // password form data if the page has changed. In most cases this code wins |
| // the race. |
| // TODO(crbug.com/418827): Fix this by passing in more data from the JS side. |
| id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) { |
| - if (weakSelf && ![weakSelf isWebStateDestroyed]) { |
| - weakSelf.get()->passwordManager_->OnPasswordFormSubmitted( |
| - weakSelf.get()->passwordManagerDriver_.get(), form); |
| + PasswordController* strongSelf = weakSelf; |
| + if (strongSelf && ![strongSelf isWebStateDestroyed]) { |
| + strongSelf.passwordManager->OnPasswordFormSubmitted( |
| + strongSelf.passwordManagerDriver, form); |
| } |
| }; |
| [self extractSubmittedPasswordForm:formName |
| @@ -434,7 +440,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| return; |
| } |
| - base::WeakNSObject<PasswordController> weakSelf(self); |
| + __weak PasswordController* weakSelf = self; |
|
vabr (Chromium)
2017/06/13 15:23:52
Just wondering why we use "__weak T* var" instead
marq (ping after 24h)
2017/06/13 17:39:04
I prefer having it as a prefix, so it's positioned
vabr (Chromium)
2017/06/13 17:49:52
Acknowledged. Since this goes against Apple's advi
|
| [passwordJsManager_ findPasswordFormsWithCompletionHandler:^( |
| NSString* jsonString) { |
| std::vector<autofill::PasswordForm> forms; |
| @@ -496,7 +502,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| return; |
| } |
| - base::WeakNSObject<PasswordController> weakSelf(self); |
| + __weak PasswordController* weakSelf = self; |
| id extractSubmittedFormCompletionHandler = ^(NSString* jsonString) { |
| autofill::PasswordForm form; |
| BOOL found = [weakSelf getPasswordForm:&form |
| @@ -827,7 +833,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| } |
| - (PasswordGenerationAgent*)passwordGenerationAgent { |
| - return passwordGenerationAgent_.get(); |
| + return passwordGenerationAgent_; |
| } |
| - (PasswordGenerationManager*)passwordGenerationManager { |