Chromium Code Reviews| Index: components/password_manager/core/browser/password_manager.cc |
| diff --git a/components/password_manager/core/browser/password_manager.cc b/components/password_manager/core/browser/password_manager.cc |
| index 99be5089ba36df629ff00fafd278fd6fd660248c..e94d49cf7b023b2f00a9e2f8162d23eb95902c4c 100644 |
| --- a/components/password_manager/core/browser/password_manager.cc |
| +++ b/components/password_manager/core/browser/password_manager.cc |
| @@ -20,6 +20,7 @@ |
| #include "components/password_manager/core/browser/affiliation_utils.h" |
| #include "components/password_manager/core/browser/browser_save_password_progress_logger.h" |
| #include "components/password_manager/core/browser/keychain_migration_status_mac.h" |
| +#include "components/password_manager/core/browser/log_router.h" |
| #include "components/password_manager/core/browser/password_autofill_manager.h" |
| #include "components/password_manager/core/browser/password_form_manager.h" |
| #include "components/password_manager/core/browser/password_manager_client.h" |
| @@ -172,14 +173,38 @@ void PasswordManager::RegisterLocalPrefs(PrefRegistrySimple* registry) { |
| #endif |
| PasswordManager::PasswordManager(PasswordManagerClient* client) |
| - : client_(client) { |
| + : client_(client), |
| + log_router_(client_->GetLogRouter()), |
| + can_use_log_router_(log_router_ ? log_router_->RegisterManager(this) |
|
vasilii
2015/11/12 16:27:34
Can't you just add a method to LogRouter to reques
vabr (Chromium)
2015/11/12 21:55:43
I could, but what would be the advantage?
|
| + : false) { |
| DCHECK(client_); |
| } |
| PasswordManager::~PasswordManager() { |
| + if (log_router_) |
| + log_router_->UnregisterManager(this); |
| FOR_EACH_OBSERVER(LoginModelObserver, observers_, OnLoginModelDestroying()); |
| } |
| +void PasswordManager::OnLogRouterAvailabilityChanged(bool router_can_be_used) { |
| + DCHECK(log_router_); // |log_router_| should be calling this method. |
| + if (can_use_log_router_ == router_can_be_used) |
| + return; |
| + can_use_log_router_ = router_can_be_used; |
| + |
| + client_->NotifyDriversAboutLoggingAvailability(can_use_log_router_); |
| +} |
| + |
| +void PasswordManager::LogSavePasswordProgress(const std::string& text) const { |
| + if (!IsLoggingActive()) |
| + return; |
| + log_router_->ProcessLog(text); |
| +} |
| + |
| +bool PasswordManager::IsLoggingActive() const { |
| + return can_use_log_router_ && log_router_; |
| +} |
| + |
| void PasswordManager::GenerationAvailableForForm(const PasswordForm& form) { |
| DCHECK(client_->IsSavingAndFillingEnabledForCurrentPage()); |
| @@ -223,8 +248,8 @@ void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { |
| client_->IsSavingAndFillingEnabledForCurrentPage(); |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_PROVISIONALLY_SAVE_PASSWORD_METHOD); |
| logger->LogPasswordForm(Logger::STRING_PROVISIONALLY_SAVE_PASSWORD_FORM, |
| form); |
| @@ -452,8 +477,8 @@ void PasswordManager::CreatePendingLoginManagers( |
| password_manager::PasswordManagerDriver* driver, |
| const std::vector<PasswordForm>& forms) { |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_CREATE_LOGIN_MANAGERS_METHOD); |
| } |
| @@ -525,8 +550,8 @@ void PasswordManager::CreatePendingLoginManagers( |
| bool PasswordManager::CanProvisionalManagerSave() { |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_CAN_PROVISIONAL_MANAGER_SAVE_METHOD); |
| } |
| @@ -566,8 +591,8 @@ void PasswordManager::OnPasswordFormsRendered( |
| bool did_stop_loading) { |
| CreatePendingLoginManagers(driver, visible_forms); |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_ON_PASSWORD_FORMS_RENDERED_METHOD); |
| } |
| @@ -643,8 +668,8 @@ void PasswordManager::OnInPageNavigation( |
| password_manager::PasswordManagerDriver* driver, |
| const PasswordForm& password_form) { |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_ON_IN_PAGE_NAVIGATION); |
| } |
| @@ -658,8 +683,8 @@ void PasswordManager::OnInPageNavigation( |
| void PasswordManager::OnLoginSuccessful() { |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_ON_ASK_USER_OR_SAVE_PASSWORD); |
| } |
| @@ -722,8 +747,8 @@ void PasswordManager::Autofill(password_manager::PasswordManagerDriver* driver, |
| DCHECK_EQ(PasswordForm::SCHEME_HTML, preferred_match.scheme); |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_PASSWORDMANAGER_AUTOFILL); |
| } |
| @@ -749,8 +774,8 @@ void PasswordManager::AutofillHttpAuth( |
| DCHECK_NE(PasswordForm::SCHEME_HTML, preferred_match.scheme); |
| scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| - if (client_->IsLoggingActive()) { |
| - logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| + if (IsLoggingActive()) { |
| + logger.reset(new BrowserSavePasswordProgressLogger(this)); |
| logger->LogMessage(Logger::STRING_PASSWORDMANAGER_AUTOFILLHTTPAUTH); |
| logger->LogBoolean(Logger::STRING_LOGINMODELOBSERVER_PRESENT, |
| observers_.might_have_observers()); |