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

Side by Side Diff: chrome/browser/ui/login/login_prompt.h

Issue 1395473003: Follow-up clean-up in LoginHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove accessors Created 5 years, 2 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
« no previous file with comments | « chrome/browser/ui/cocoa/login_prompt_cocoa.mm ('k') | chrome/browser/ui/login/login_prompt.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #ifndef CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ 5 #ifndef CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_
6 #define CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ 6 #define CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "components/password_manager/core/browser/password_manager.h" 12 #include "components/password_manager/core/browser/password_manager.h"
13 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" 14 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
15 15
16 class GURL; 16 class GURL;
17 17
18 namespace content { 18 namespace content {
19 class RenderViewHostDelegate; 19 class RenderViewHostDelegate;
20 class NotificationRegistrar; 20 class NotificationRegistrar;
21 class WebContents; 21 class WebContents;
22 } // namespace content 22 } // namespace content
23 23
24 namespace net { 24 namespace net {
25 class AuthChallengeInfo; 25 class AuthChallengeInfo;
26 class HttpNetworkSession; 26 class HttpNetworkSession;
27 class URLRequest; 27 class URLRequest;
28 } // namespace net 28 } // namespace net
29 29
30 namespace password_manager {
31 class ContentPasswordManagerDriver;
32 } // namespace password_manager
33
34 // This is the base implementation for the OS-specific classes that route 30 // This is the base implementation for the OS-specific classes that route
35 // authentication info to the net::URLRequest that needs it. These functions 31 // authentication info to the net::URLRequest that needs it. These functions
36 // must be implemented in a thread safe manner. 32 // must be implemented in a thread safe manner.
37 class LoginHandler : public content::ResourceDispatcherHostLoginDelegate, 33 class LoginHandler : public content::ResourceDispatcherHostLoginDelegate,
38 public password_manager::LoginModelObserver, 34 public password_manager::LoginModelObserver,
39 public content::NotificationObserver { 35 public content::NotificationObserver {
40 public: 36 public:
41 // The purpose of this struct is to enforce that BuildView receives either 37 // The purpose of this struct is to enforce that BuildViewImpl receives either
42 // both the login model and the observed form, or none. That is a bit spoiled 38 // both the login model and the observed form, or none. That is a bit spoiled
43 // by the fact that the model is a pointer to LoginModel, as opposed to a 39 // by the fact that the model is a pointer to LoginModel, as opposed to a
44 // reference. Having it as a reference would go against the style guide, which 40 // reference. Having it as a reference would go against the style guide, which
45 // forbids non-const references in arguments, presumably also inside passed 41 // forbids non-const references in arguments, presumably also inside passed
46 // structs, because the guide's rationale still applies. Therefore at least 42 // structs, because the guide's rationale still applies. Therefore at least
47 // the constructor DCHECKs that |login_model| is not null. 43 // the constructor DCHECKs that |login_model| is not null.
48 struct LoginModelData { 44 struct LoginModelData {
49 LoginModelData(password_manager::LoginModel* login_model, 45 LoginModelData(password_manager::LoginModel* login_model,
50 const autofill::PasswordForm& observed_form); 46 const autofill::PasswordForm& observed_form);
51 47
52 password_manager::LoginModel* const model; 48 password_manager::LoginModel* const model;
53 const autofill::PasswordForm& form; 49 const autofill::PasswordForm& form;
54 }; 50 };
55 51
56 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); 52 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request);
57 53
58 // Builds the platform specific LoginHandler. Used from within 54 // Builds the platform specific LoginHandler. Used from within
59 // CreateLoginPrompt() which creates tasks. 55 // CreateLoginPrompt() which creates tasks.
60 static LoginHandler* Create(net::AuthChallengeInfo* auth_info, 56 static LoginHandler* Create(net::AuthChallengeInfo* auth_info,
61 net::URLRequest* request); 57 net::URLRequest* request);
62 58
63 // ResourceDispatcherHostLoginDelegate implementation: 59 // ResourceDispatcherHostLoginDelegate implementation:
64 void OnRequestCancelled() override; 60 void OnRequestCancelled() override;
65 61
66 // Implement this to initialize the underlying platform specific view. If 62 // Use this to build a view with password manager support. |password_manager|
67 // |login_model_data| is not null, the contained LoginModel and PasswordForm 63 // must not be null.
68 // can be used to register the view. 64 void BuildViewWithPasswordManager(
69 virtual void BuildView(const base::string16& explanation, 65 const base::string16& explanation,
70 LoginModelData* login_model_data) = 0; 66 password_manager::PasswordManager* password_manager,
67 const autofill::PasswordForm& observed_form);
71 68
72 // Sets information about the authentication type (|form|) and the 69 // Use this to build a view without password manager support.
73 // |password_manager| for this profile. 70 void BuildViewWithoutPasswordManager(const base::string16& explanation);
74 void SetPasswordForm(const autofill::PasswordForm& form);
75 void SetPasswordManager(password_manager::PasswordManager* password_manager);
76 71
77 // Returns the WebContents that needs authentication. 72 // Returns the WebContents that needs authentication.
78 content::WebContents* GetWebContentsForLogin() const; 73 content::WebContents* GetWebContentsForLogin() const;
79 74
80 // Returns the PasswordManager for the web contents that needs login. 75 // Returns the PasswordManager for the web contents that needs login.
81 password_manager::PasswordManager* GetPasswordManagerForLogin(); 76 password_manager::PasswordManager* GetPasswordManagerForLogin();
82 77
83 // Resend the request with authentication credentials. 78 // Resend the request with authentication credentials.
84 // This function can be called from either thread. 79 // This function can be called from either thread.
85 void SetAuth(const base::string16& username, const base::string16& password); 80 void SetAuth(const base::string16& username, const base::string16& password);
(...skipping 12 matching lines...) Expand all
98 93
99 // Who/where/what asked for the authentication. 94 // Who/where/what asked for the authentication.
100 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); } 95 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); }
101 96
102 // Returns whether authentication had been handled (SetAuth or CancelAuth). 97 // Returns whether authentication had been handled (SetAuth or CancelAuth).
103 bool WasAuthHandled() const; 98 bool WasAuthHandled() const;
104 99
105 protected: 100 protected:
106 ~LoginHandler() override; 101 ~LoginHandler() override;
107 102
103 // Implement this to initialize the underlying platform specific view. If
104 // |login_model_data| is not null, the contained LoginModel and PasswordForm
105 // can be used to register the view.
106 virtual void BuildViewImpl(const base::string16& explanation,
107 LoginModelData* login_model_data) = 0;
108
108 // Sets |model_data.model| as |login_model_| and registers |this| as an 109 // Sets |model_data.model| as |login_model_| and registers |this| as an
109 // observer for |model_data.form|-related events. 110 // observer for |model_data.form|-related events.
110 void SetModel(LoginModelData model_data); 111 void SetModel(LoginModelData model_data);
111 112
112 // Clear |login_model_| and remove |this| as an observer. 113 // Clears |login_model_| and removes |this| as an observer.
113 void ResetModel(); 114 void ResetModel();
114 115
115 // Notify observers that authentication is needed. 116 // Notify observers that authentication is needed.
116 void NotifyAuthNeeded(); 117 void NotifyAuthNeeded();
117 118
118 // Performs necessary cleanup before deletion. 119 // Performs necessary cleanup before deletion.
119 void ReleaseSoon(); 120 void ReleaseSoon();
120 121
121 // Closes the native dialog. 122 // Closes the native dialog.
122 virtual void CloseDialog() = 0; 123 virtual void CloseDialog() = 0;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // net::URLRequest::Delegate::OnAuthRequired. The prompt will be created 232 // net::URLRequest::Delegate::OnAuthRequired. The prompt will be created
232 // on the main UI thread via a call to UI loop's InvokeLater, and will send the 233 // on the main UI thread via a call to UI loop's InvokeLater, and will send the
233 // credentials back to the net::URLRequest on the calling thread. 234 // credentials back to the net::URLRequest on the calling thread.
234 // A LoginHandler object (which lives on the calling thread) is returned, 235 // A LoginHandler object (which lives on the calling thread) is returned,
235 // which can be used to set or cancel authentication programmatically. The 236 // which can be used to set or cancel authentication programmatically. The
236 // caller must invoke OnRequestCancelled() on this LoginHandler before 237 // caller must invoke OnRequestCancelled() on this LoginHandler before
237 // destroying the net::URLRequest. 238 // destroying the net::URLRequest.
238 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, 239 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info,
239 net::URLRequest* request); 240 net::URLRequest* request);
240 241
241 // Helper to remove the ref from an net::URLRequest to the LoginHandler.
242 // Should only be called from the IO thread, since it accesses an
243 // net::URLRequest.
244 void ResetLoginHandlerForRequest(net::URLRequest* request);
245
246 // Get the signon_realm under which the identity should be saved. 242 // Get the signon_realm under which the identity should be saved.
247 std::string GetSignonRealm(const GURL& url, 243 std::string GetSignonRealm(const GURL& url,
248 const net::AuthChallengeInfo& auth_info); 244 const net::AuthChallengeInfo& auth_info);
249 245
250 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ 246 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/login_prompt_cocoa.mm ('k') | chrome/browser/ui/login/login_prompt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698