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

Side by Side Diff: chrome/browser/password_manager/password_manager_delegate_impl.cc

Issue 151413008: Move ownership of Password(Generation)Manager to ContentPasswordDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle WebContents having no PasswordManagerDelegateImpl attached Created 6 years, 10 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 | Annotate | Revision Log
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 #include "chrome/browser/password_manager/password_manager_delegate_impl.h" 5 #include "chrome/browser/password_manager/password_manager_delegate_impl.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/timer/elapsed_timer.h" 10 #include "base/timer/elapsed_timer.h"
11 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 11 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
12 #include "chrome/browser/infobars/infobar.h" 12 #include "chrome/browser/infobars/infobar.h"
13 #include "chrome/browser/infobars/infobar_service.h" 13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/password_manager/password_form_manager.h" 14 #include "chrome/browser/password_manager/password_form_manager.h"
15 #include "chrome/browser/password_manager/password_manager.h" 15 #include "chrome/browser/password_manager/password_manager.h"
16 #include "chrome/browser/password_manager/password_manager_metrics_util.h" 16 #include "chrome/browser/password_manager/password_manager_metrics_util.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 18 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
19 #include "content/public/browser/navigation_details.h" 19 #include "content/public/browser/navigation_details.h"
20 #include "content/public/browser/navigation_entry.h" 20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "google_apis/gaia/gaia_urls.h" 22 #include "google_apis/gaia/gaia_urls.h"
23 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 27
28
29 // SavePasswordInfoBarDelegate ------------------------------------------------ 28 // SavePasswordInfoBarDelegate ------------------------------------------------
30 29
31 // After a successful *new* login attempt, we take the PasswordFormManager in 30 // After a successful *new* login attempt, we take the PasswordFormManager in
32 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while 31 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
33 // the user makes up their mind with the "save password" infobar. Note if the 32 // the user makes up their mind with the "save password" infobar. Note if the
34 // login is one we already know about, the end of the line is 33 // login is one we already know about, the end of the line is
35 // provisional_save_manager_ because we just update it on success and so such 34 // provisional_save_manager_ because we just update it on success and so such
36 // forms never end up in an infobar. 35 // forms never end up in an infobar.
37 class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { 36 class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
38 public: 37 public:
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return PASSWORD_INFOBAR; 200 return PASSWORD_INFOBAR;
202 } 201 }
203 202
204 203
205 // PasswordManagerDelegateImpl ------------------------------------------------ 204 // PasswordManagerDelegateImpl ------------------------------------------------
206 205
207 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordManagerDelegateImpl); 206 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordManagerDelegateImpl);
208 207
209 PasswordManagerDelegateImpl::PasswordManagerDelegateImpl( 208 PasswordManagerDelegateImpl::PasswordManagerDelegateImpl(
210 content::WebContents* web_contents) 209 content::WebContents* web_contents)
211 : web_contents_(web_contents), 210 : web_contents_(web_contents), driver_(web_contents, this) {}
212 driver_(web_contents) {
213 }
214 211
215 PasswordManagerDelegateImpl::~PasswordManagerDelegateImpl() { 212 PasswordManagerDelegateImpl::~PasswordManagerDelegateImpl() {
216 } 213 }
217 214
218 void PasswordManagerDelegateImpl::AddSavePasswordInfoBarIfPermitted( 215 void PasswordManagerDelegateImpl::AddSavePasswordInfoBarIfPermitted(
219 PasswordFormManager* form_to_save) { 216 PasswordFormManager* form_to_save) {
220 std::string uma_histogram_suffix( 217 std::string uma_histogram_suffix(
221 password_manager_metrics_util::GroupIdToString( 218 password_manager_metrics_util::GroupIdToString(
222 password_manager_metrics_util::MonitoredDomainGroupId( 219 password_manager_metrics_util::MonitoredDomainGroupId(
223 form_to_save->realm(), GetProfile()->GetPrefs()))); 220 form_to_save->realm(), GetProfile()->GetPrefs())));
224 SavePasswordInfoBarDelegate::Create( 221 SavePasswordInfoBarDelegate::Create(
225 web_contents_, form_to_save, uma_histogram_suffix); 222 web_contents_, form_to_save, uma_histogram_suffix);
226 } 223 }
227 224
228 Profile* PasswordManagerDelegateImpl::GetProfile() { 225 Profile* PasswordManagerDelegateImpl::GetProfile() {
229 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 226 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
230 } 227 }
231 228
232 PasswordManagerDriver* PasswordManagerDelegateImpl::GetDriver() { 229 PasswordManagerDriver* PasswordManagerDelegateImpl::GetDriver() {
233 return &driver_; 230 return &driver_;
234 } 231 }
232
233 // static
234 PasswordGenerationManager*
235 PasswordManagerDelegateImpl::GetGenerationManagerFromWebContents(
236 content::WebContents* contents) {
237 PasswordManagerDelegateImpl* delegate =
238 PasswordManagerDelegateImpl::FromWebContents(contents);
239 if (!delegate)
240 return NULL;
241 return delegate->GetDriver()->GetPasswordGenerationManager();
242 }
243
244 // static
245 PasswordManager* PasswordManagerDelegateImpl::GetManagerFromWebContents(
246 content::WebContents* contents) {
247 PasswordManagerDelegateImpl* delegate =
248 PasswordManagerDelegateImpl::FromWebContents(contents);
249 if (!delegate)
250 return NULL;
251 return delegate->GetDriver()->GetPasswordManager();
252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698