Commit 465933b5 authored by vabr's avatar vabr Committed by Commit bot

Prepare password_bubble_experiment and password_manager_util for componentisation

This CL removes some unneeded //chrome dependencies in password manager utilities. The goal is to make those files movable to the password manager component. The move will happen in a separate CL.

BUG=486739

Review URL: https://codereview.chromium.org/1141413002

Cr-Commit-Position: refs/heads/master@{#330805}
parent b9d760ae
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/passwords/password_bubble_experiment.h" #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -117,8 +119,10 @@ static jboolean ShouldDisplayManageAccountLink( ...@@ -117,8 +119,10 @@ static jboolean ShouldDisplayManageAccountLink(
static jboolean ShouldUseSmartLockBranding( static jboolean ShouldUseSmartLockBranding(
JNIEnv* env, jclass) { JNIEnv* env, jclass) {
return password_bubble_experiment::IsSmartLockBrandingEnabled( const ProfileSyncService* sync_service =
ProfileManager::GetLastUsedProfile()); ProfileSyncServiceFactory::GetForProfile(
ProfileManager::GetLastUsedProfile());
return password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service);
} }
// static // static
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
#include "chrome/browser/password_manager/password_manager_util.h" #include "chrome/browser/password_manager/password_manager_util.h"
#include "chrome/browser/sync/profile_sync_service.h" #include "components/sync_driver/sync_service.h"
namespace password_manager_util { namespace password_manager_util {
password_manager::PasswordSyncState GetPasswordSyncState( password_manager::PasswordSyncState GetPasswordSyncState(
const ProfileSyncService* sync_service) { const sync_driver::SyncService* sync_service) {
if (sync_service && sync_service->HasSyncSetupCompleted() && if (sync_service && sync_service->HasSyncSetupCompleted() &&
sync_service->SyncActive() && sync_service->SyncActive() &&
sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS)) { sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS)) {
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_client.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
class ProfileSyncService; namespace sync_driver {
class SyncService;
}
namespace password_manager_util { namespace password_manager_util {
...@@ -40,7 +42,7 @@ void GetOsPasswordStatus(const base::Callback<void(OsPasswordStatus)>& reply); ...@@ -40,7 +42,7 @@ void GetOsPasswordStatus(const base::Callback<void(OsPasswordStatus)>& reply);
// Reports whether and how passwords are currently synced. In particular, for a // Reports whether and how passwords are currently synced. In particular, for a
// null |sync_service| returns NOT_SYNCING_PASSWORDS. // null |sync_service| returns NOT_SYNCING_PASSWORDS.
password_manager::PasswordSyncState GetPasswordSyncState( password_manager::PasswordSyncState GetPasswordSyncState(
const ProfileSyncService* sync_service); const sync_driver::SyncService* sync_service);
} // namespace password_manager_util } // namespace password_manager_util
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/passwords/password_bubble_experiment.h" #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -41,10 +43,12 @@ void SavePasswordInfoBarDelegate::Create( ...@@ -41,10 +43,12 @@ void SavePasswordInfoBarDelegate::Create(
InfoBarService::FromWebContents(web_contents); InfoBarService::FromWebContents(web_contents);
Profile* profile = Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext()); Profile::FromBrowserContext(web_contents->GetBrowserContext());
const ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(profile);
SavePasswordInfoBarDelegate* infobar_delegate = SavePasswordInfoBarDelegate* infobar_delegate =
new SavePasswordInfoBarDelegate( new SavePasswordInfoBarDelegate(
form_to_save.Pass(), uma_histogram_suffix, source_type, form_to_save.Pass(), uma_histogram_suffix, source_type,
password_bubble_experiment::IsSmartLockBrandingEnabled(profile)); password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service));
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// For Android in case of smart lock we need different appearance of infobar. // For Android in case of smart lock we need different appearance of infobar.
scoped_ptr<infobars::InfoBar> infobar = scoped_ptr<infobars::InfoBar> infobar =
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "base/strings/utf_string_conversion_utils.h" #include "base/strings/utf_string_conversion_utils.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/autofill/password_generation_popup_observer.h" #include "chrome/browser/ui/autofill/password_generation_popup_observer.h"
#include "chrome/browser/ui/autofill/password_generation_popup_view.h" #include "chrome/browser/ui/autofill/password_generation_popup_view.h"
#include "chrome/browser/ui/autofill/popup_constants.h" #include "chrome/browser/ui/autofill/popup_constants.h"
...@@ -91,8 +93,10 @@ PasswordGenerationPopupControllerImpl::PasswordGenerationPopupControllerImpl( ...@@ -91,8 +93,10 @@ PasswordGenerationPopupControllerImpl::PasswordGenerationPopupControllerImpl(
int link_id = IDS_MANAGE_PASSWORDS_LINK; int link_id = IDS_MANAGE_PASSWORDS_LINK;
int help_text_id = IDS_PASSWORD_GENERATION_PROMPT; int help_text_id = IDS_PASSWORD_GENERATION_PROMPT;
if (password_bubble_experiment::IsSmartLockBrandingEnabled( const ProfileSyncService* sync_service =
Profile::FromBrowserContext(web_contents->GetBrowserContext()))) { ProfileSyncServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext()));
if (password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service)) {
help_text_id = IDS_PASSWORD_GENERATION_SMART_LOCK_PROMPT; help_text_id = IDS_PASSWORD_GENERATION_SMART_LOCK_PROMPT;
link_id = IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS; link_id = IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS;
} }
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
...@@ -72,6 +74,14 @@ ScopedVector<const autofill::PasswordForm> DeepCopyForms( ...@@ -72,6 +74,14 @@ ScopedVector<const autofill::PasswordForm> DeepCopyForms(
return result.Pass(); return result.Pass();
} }
// A wrapper around password_bubble_experiment::IsSmartLockBrandingEnabled
// extracting the sync_service from the profile.
bool IsSmartLockBrandingEnabled(Profile* profile) {
const ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(profile);
return password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service);
}
} // namespace } // namespace
ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
...@@ -121,7 +131,7 @@ ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( ...@@ -121,7 +131,7 @@ ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
base::string16 save_confirmation_link = base::string16 save_confirmation_link =
l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_LINK); l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_LINK);
int confirmation_text_id = IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT; int confirmation_text_id = IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT;
if (password_bubble_experiment::IsSmartLockBrandingEnabled(GetProfile())) { if (IsSmartLockBrandingEnabled(GetProfile())) {
std::string management_hostname = std::string management_hostname =
GURL(chrome::kPasswordManagerAccountDashboardURL).host(); GURL(chrome::kPasswordManagerAccountDashboardURL).host();
save_confirmation_link = base::UTF8ToUTF16(management_hostname); save_confirmation_link = base::UTF8ToUTF16(management_hostname);
...@@ -249,7 +259,7 @@ void ManagePasswordsBubbleModel::OnOKClicked() { ...@@ -249,7 +259,7 @@ void ManagePasswordsBubbleModel::OnOKClicked() {
void ManagePasswordsBubbleModel::OnManageLinkClicked() { void ManagePasswordsBubbleModel::OnManageLinkClicked() {
dismissal_reason_ = metrics_util::CLICKED_MANAGE; dismissal_reason_ = metrics_util::CLICKED_MANAGE;
if (password_bubble_experiment::IsSmartLockBrandingEnabled(GetProfile())) { if (IsSmartLockBrandingEnabled(GetProfile())) {
ManagePasswordsUIController::FromWebContents(web_contents()) ManagePasswordsUIController::FromWebContents(web_contents())
->NavigateToExternalPasswordManager(); ->NavigateToExternalPasswordManager();
} else { } else {
...@@ -328,8 +338,7 @@ void ManagePasswordsBubbleModel::UpdatePendingStateTitle() { ...@@ -328,8 +338,7 @@ void ManagePasswordsBubbleModel::UpdatePendingStateTitle() {
if (never_save_passwords_) { if (never_save_passwords_) {
title_ = l10n_util::GetStringUTF16( title_ = l10n_util::GetStringUTF16(
IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE); IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE);
} else if (password_bubble_experiment::IsSmartLockBrandingEnabled( } else if (IsSmartLockBrandingEnabled(GetProfile())) {
GetProfile())) {
// "Google Smart Lock" should be a hyperlink. // "Google Smart Lock" should be a hyperlink.
base::string16 brand_link = base::string16 brand_link =
l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK);
......
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
#include "chrome/browser/ui/passwords/password_bubble_experiment.h" #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/password_manager/password_manager_util.h" #include "chrome/browser/password_manager/password_manager_util.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
namespace password_bubble_experiment { namespace password_bubble_experiment {
namespace { namespace {
...@@ -23,9 +22,7 @@ void RecordBubbleClosed( ...@@ -23,9 +22,7 @@ void RecordBubbleClosed(
// TODO(vasilii): store the statistics. // TODO(vasilii): store the statistics.
} }
bool IsSmartLockBrandingEnabled(Profile* profile) { bool IsSmartLockBrandingEnabled(const sync_driver::SyncService* sync_service) {
const ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(profile);
return password_manager_util::GetPasswordSyncState(sync_service) == return password_manager_util::GetPasswordSyncState(sync_service) ==
password_manager::SYNCING_NORMAL_ENCRYPTION && password_manager::SYNCING_NORMAL_ENCRYPTION &&
base::FieldTrialList::FindFullName(kBrandingExperimentName) == base::FieldTrialList::FindFullName(kBrandingExperimentName) ==
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h" #include "components/password_manager/core/browser/password_manager_metrics_util.h"
class Profile; class PrefService;
namespace sync_driver {
class SyncService;
}
namespace password_bubble_experiment { namespace password_bubble_experiment {
...@@ -20,7 +24,7 @@ void RecordBubbleClosed( ...@@ -20,7 +24,7 @@ void RecordBubbleClosed(
// Returns true if the password manager should be referred to as Smart Lock. // Returns true if the password manager should be referred to as Smart Lock.
// This is only true for signed-in users. // This is only true for signed-in users.
bool IsSmartLockBrandingEnabled(Profile* profile); bool IsSmartLockBrandingEnabled(const sync_driver::SyncService* sync_service);
} // namespace password_bubble_experiment } // namespace password_bubble_experiment
......
...@@ -310,7 +310,8 @@ void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) { ...@@ -310,7 +310,8 @@ void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) {
IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION }, IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION },
{ "passwordManagerEnabled", { "passwordManagerEnabled",
password_bubble_experiment::IsSmartLockBrandingEnabled( password_bubble_experiment::IsSmartLockBrandingEnabled(
Profile::FromWebUI(web_ui())) ? ProfileSyncServiceFactory::GetForProfile(
Profile::FromWebUI(web_ui()))) ?
IDS_OPTIONS_PASSWORD_MANAGER_SMART_LOCK_ENABLE : IDS_OPTIONS_PASSWORD_MANAGER_SMART_LOCK_ENABLE :
IDS_OPTIONS_PASSWORD_MANAGER_ENABLE }, IDS_OPTIONS_PASSWORD_MANAGER_ENABLE },
{ "passwordsAndAutofillGroupName", { "passwordsAndAutofillGroupName",
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#if defined(OS_WIN) && defined(USE_ASH) #if defined(OS_WIN) && defined(USE_ASH)
#include "chrome/browser/ui/ash/ash_util.h" #include "chrome/browser/ui/ash/ash_util.h"
#endif #endif
...@@ -76,8 +78,10 @@ void PasswordManagerHandler::GetLocalizedValues( ...@@ -76,8 +78,10 @@ void PasswordManagerHandler::GetLocalizedValues(
RegisterStrings(localized_strings, resources, arraysize(resources)); RegisterStrings(localized_strings, resources, arraysize(resources));
const ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(GetProfile());
int title_id = int title_id =
password_bubble_experiment::IsSmartLockBrandingEnabled(GetProfile()) ? password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service) ?
IDS_PASSWORDS_EXCEPTIONS_SMART_LOCK_WINDOW_TITLE : IDS_PASSWORDS_EXCEPTIONS_SMART_LOCK_WINDOW_TITLE :
IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE; IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE;
RegisterTitle(localized_strings, "passwordsPage", title_id); RegisterTitle(localized_strings, "passwordsPage", title_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment