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

Side by Side Diff: ios/chrome/browser/passwords/password_controller.mm

Issue 1941363002: PasswordController should give up on WebState destruction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: isBeingDestroyed Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "ios/chrome/browser/passwords/password_controller.h" 5 #import "ios/chrome/browser/passwords/password_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } // namespace 227 } // namespace
228 228
229 @implementation PasswordController { 229 @implementation PasswordController {
230 std::unique_ptr<PasswordManager> passwordManager_; 230 std::unique_ptr<PasswordManager> passwordManager_;
231 std::unique_ptr<PasswordGenerationManager> passwordGenerationManager_; 231 std::unique_ptr<PasswordGenerationManager> passwordGenerationManager_;
232 std::unique_ptr<PasswordManagerClient> passwordManagerClient_; 232 std::unique_ptr<PasswordManagerClient> passwordManagerClient_;
233 std::unique_ptr<PasswordManagerDriver> passwordManagerDriver_; 233 std::unique_ptr<PasswordManagerDriver> passwordManagerDriver_;
234 base::scoped_nsobject<PasswordGenerationAgent> passwordGenerationAgent_; 234 base::scoped_nsobject<PasswordGenerationAgent> passwordGenerationAgent_;
235 235
236 JsPasswordManager* passwordJsManager_; // weak 236 JsPasswordManager* passwordJsManager_; // weak
237 web::WebState* webState_; // weak
237 238
238 // The pending form data. 239 // The pending form data.
239 std::unique_ptr<autofill::PasswordFormFillData> formData_; 240 std::unique_ptr<autofill::PasswordFormFillData> formData_;
240 241
241 // Bridge to observe WebState from Objective-C. 242 // Bridge to observe WebState from Objective-C.
242 std::unique_ptr<web::WebStateObserverBridge> webStateObserverBridge_; 243 std::unique_ptr<web::WebStateObserverBridge> webStateObserverBridge_;
243 } 244 }
244 245
246 @synthesize isBeingDestroyed = isBeingDestroyed_;
Eugene But (OOO till 7-30) 2016/05/03 17:49:49 Sorry the name I suggested was not very good. isWe
vabr (Chromium) 2016/05/04 15:03:46 Done.
247
245 - (instancetype)initWithWebState:(web::WebState*)webState 248 - (instancetype)initWithWebState:(web::WebState*)webState
246 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate { 249 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate {
247 self = [self initWithWebState:webState 250 self = [self initWithWebState:webState
248 passwordsUiDelegate:UIDelegate 251 passwordsUiDelegate:UIDelegate
249 client:nullptr]; 252 client:nullptr];
250 return self; 253 return self;
251 } 254 }
252 255
253 - (instancetype)initWithWebState:(web::WebState*)webState 256 - (instancetype)initWithWebState:(web::WebState*)webState
254 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate 257 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate
255 client:(std::unique_ptr<PasswordManagerClient>) 258 client:(std::unique_ptr<PasswordManagerClient>)
256 passwordManagerClient { 259 passwordManagerClient {
257 DCHECK(webState); 260 DCHECK(webState);
258 self = [super init]; 261 self = [super init];
259 if (self) { 262 if (self) {
260 webStateObserverBridge_.reset( 263 isBeingDestroyed_ = NO;
Eugene But (OOO till 7-30) 2016/05/03 17:49:49 From Objective-C Style Guide: Don't initialize in
vabr (Chromium) 2016/05/04 15:03:46 Done.
261 new web::WebStateObserverBridge(webState, self)); 264 webState_ = webState;
Eugene But (OOO till 7-30) 2016/05/03 17:49:49 This change is not part of the bugfix and because
vabr (Chromium) 2016/05/04 15:03:46 Done.
262 if (passwordManagerClient) 265 if (passwordManagerClient)
263 passwordManagerClient_ = std::move(passwordManagerClient); 266 passwordManagerClient_ = std::move(passwordManagerClient);
264 else 267 else
265 passwordManagerClient_.reset(new IOSChromePasswordManagerClient(self)); 268 passwordManagerClient_.reset(new IOSChromePasswordManagerClient(self));
266 passwordManager_.reset(new PasswordManager(passwordManagerClient_.get())); 269 passwordManager_.reset(new PasswordManager(passwordManagerClient_.get()));
267 passwordManagerDriver_.reset(new IOSChromePasswordManagerDriver(self)); 270 passwordManagerDriver_.reset(new IOSChromePasswordManagerDriver(self));
268 if (experimental_flags::IsPasswordGenerationEnabled() && 271 if (experimental_flags::IsPasswordGenerationEnabled() &&
269 !passwordManagerClient_->IsOffTheRecord()) { 272 !passwordManagerClient_->IsOffTheRecord()) {
270 passwordGenerationManager_.reset(new PasswordGenerationManager( 273 passwordGenerationManager_.reset(new PasswordGenerationManager(
271 passwordManagerClient_.get(), passwordManagerDriver_.get())); 274 passwordManagerClient_.get(), passwordManagerDriver_.get()));
272 passwordGenerationAgent_.reset([[PasswordGenerationAgent alloc] 275 passwordGenerationAgent_.reset([[PasswordGenerationAgent alloc]
273 initWithWebState:webState 276 initWithWebState:webState
274 passwordManager:passwordManager_.get() 277 passwordManager:passwordManager_.get()
275 passwordManagerDriver:passwordManagerDriver_.get() 278 passwordManagerDriver:passwordManagerDriver_.get()
276 passwordsUiDelegate:UIDelegate]); 279 passwordsUiDelegate:UIDelegate]);
277 } 280 }
278 281
279 passwordJsManager_ = base::mac::ObjCCastStrict<JsPasswordManager>( 282 passwordJsManager_ = base::mac::ObjCCastStrict<JsPasswordManager>(
280 [webState->GetJSInjectionReceiver() 283 [webState->GetJSInjectionReceiver()
281 instanceOfClass:[JsPasswordManager class]]); 284 instanceOfClass:[JsPasswordManager class]]);
285 webStateObserverBridge_.reset(
Eugene But (OOO till 7-30) 2016/05/03 17:49:49 This also not a part of the fix, so please exclude
vabr (Chromium) 2016/05/04 15:03:46 Done.
286 new web::WebStateObserverBridge(webState, self));
282 } 287 }
283 return self; 288 return self;
284 } 289 }
285 290
286 - (instancetype)init { 291 - (instancetype)init {
287 NOTREACHED(); 292 NOTREACHED();
288 return nil; 293 return nil;
289 } 294 }
290 295
291 - (void)dealloc { 296 - (void)dealloc {
292 [self detach]; 297 [self detach];
293 [super dealloc]; 298 [super dealloc];
294 } 299 }
295 300
296 - (ios::ChromeBrowserState*)browserState { 301 - (ios::ChromeBrowserState*)browserState {
297 return webStateObserverBridge_ && webStateObserverBridge_->web_state() 302 return webState_ ? ios::ChromeBrowserState::FromBrowserState(
298 ? ios::ChromeBrowserState::FromBrowserState( 303 webState_->GetBrowserState())
299 webStateObserverBridge_->web_state()->GetBrowserState()) 304 : nullptr;
300 : nullptr;
301 } 305 }
302 306
303 - (const GURL&)lastCommittedURL { 307 - (const GURL&)lastCommittedURL {
304 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) 308 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state())
305 return GURL::EmptyGURL(); 309 return GURL::EmptyGURL();
306 return webStateObserverBridge_->web_state()->GetLastCommittedURL(); 310 return webStateObserverBridge_->web_state()->GetLastCommittedURL();
307 } 311 }
308 312
309 - (void)detach { 313 - (void)detach {
314 webState_ = nullptr;
310 webStateObserverBridge_.reset(); 315 webStateObserverBridge_.reset();
311 passwordGenerationAgent_.reset(); 316 passwordGenerationAgent_.reset();
312 passwordGenerationManager_.reset(); 317 passwordGenerationManager_.reset();
313 passwordManagerDriver_.reset(); 318 passwordManagerDriver_.reset();
314 passwordManager_.reset(); 319 passwordManager_.reset();
315 passwordManagerClient_.reset(); 320 passwordManagerClient_.reset();
316 } 321 }
317 322
318 - (void)findAndFillPasswordForms:(NSString*)username 323 - (void)findAndFillPasswordForms:(NSString*)username
319 password:(NSString*)password 324 password:(NSString*)password
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 381
377 - (void)webState:(web::WebState*)webState 382 - (void)webState:(web::WebState*)webState
378 didSubmitDocumentWithFormNamed:(const std::string&)formName 383 didSubmitDocumentWithFormNamed:(const std::string&)formName
379 userInitiated:(BOOL)userInitiated { 384 userInitiated:(BOOL)userInitiated {
380 base::WeakNSObject<PasswordController> weakSelf(self); 385 base::WeakNSObject<PasswordController> weakSelf(self);
381 // This code is racing against the new page loading and will not get the 386 // This code is racing against the new page loading and will not get the
382 // password form data if the page has changed. In most cases this code wins 387 // password form data if the page has changed. In most cases this code wins
383 // the race. 388 // the race.
384 // TODO(crbug.com/418827): Fix this by passing in more data from the JS side. 389 // TODO(crbug.com/418827): Fix this by passing in more data from the JS side.
385 id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) { 390 id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) {
386 if (weakSelf) { 391 if (weakSelf && [weakSelf isBeingDestroyed] == NO) {
Eugene But (OOO till 7-30) 2016/05/03 17:49:49 NIT: ![weakSelf isBeingDestroyed]
vabr (Chromium) 2016/05/04 15:03:46 Done.
387 weakSelf.get()->passwordManager_->OnPasswordFormSubmitted( 392 weakSelf.get()->passwordManager_->OnPasswordFormSubmitted(
388 weakSelf.get()->passwordManagerDriver_.get(), form); 393 weakSelf.get()->passwordManagerDriver_.get(), form);
389 } 394 }
390 }; 395 };
391 [self extractSubmittedPasswordForm:formName 396 [self extractSubmittedPasswordForm:formName
392 completionHandler:completionHandler]; 397 completionHandler:completionHandler];
393 } 398 }
394 399
395 - (void)webStateDestroyed:(web::WebState*)webState { 400 - (void)webStateDestroyed:(web::WebState*)webState {
401 isBeingDestroyed_ = YES;
396 [self detach]; 402 [self detach];
397 } 403 }
398 404
399 - (void)findPasswordFormsWithCompletionHandler: 405 - (void)findPasswordFormsWithCompletionHandler:
400 (void (^)(const std::vector<autofill::PasswordForm>&))completionHandler { 406 (void (^)(const std::vector<autofill::PasswordForm>&))completionHandler {
401 DCHECK(completionHandler); 407 DCHECK(completionHandler);
402 408
403 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) 409 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state())
404 return; 410 return;
405 411
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 817
812 - (PasswordManager*)passwordManager { 818 - (PasswordManager*)passwordManager {
813 return passwordManager_.get(); 819 return passwordManager_.get();
814 } 820 }
815 821
816 - (JsPasswordManager*)passwordJsManager { 822 - (JsPasswordManager*)passwordJsManager {
817 return passwordJsManager_; 823 return passwordJsManager_;
818 } 824 }
819 825
820 @end 826 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698