Commit d5b9a79d authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Adding metrics and plugging the user consent in the consent bump dialog

UnifiedConsent.ConsentBump.Action is added for iOS.
It has already been added into Chromium with:
crrev.com/c/1143185

Bug: 827072
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ieda1e49c547182c6f044effdcf66e294f946c875
Reviewed-on: https://chromium-review.googlesource.com/1174832Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584471}
parent c9953911
...@@ -8,6 +8,8 @@ static_library("unified_consent") { ...@@ -8,6 +8,8 @@ static_library("unified_consent") {
"feature.h", "feature.h",
"pref_names.cc", "pref_names.cc",
"pref_names.h", "pref_names.h",
"unified_consent_metrics.cc",
"unified_consent_metrics.h",
"unified_consent_service.cc", "unified_consent_service.cc",
"unified_consent_service.h", "unified_consent_service.h",
"unified_consent_service_client.cc", "unified_consent_service_client.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/unified_consent/unified_consent_metrics.h"
#include "base/metrics/histogram_macros.h"
namespace {
// Histogram name.
const char kConsentBumpActionMetricName[] = "UnifiedConsent.ConsentBump.Action";
} // namespace
namespace unified_consent {
namespace metrics {
void RecordConsentBumpMetric(UnifiedConsentBumpAction action) {
UMA_HISTOGRAM_ENUMERATION(
kConsentBumpActionMetricName, action,
UnifiedConsentBumpAction::kUnifiedConsentBumpActionMoreOptionsMax);
}
} // namespace metrics
} // namespace unified_consent
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_METRICS_H_
#define COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_METRICS_H_
namespace unified_consent {
namespace metrics {
// Histogram enum: UnifiedConsentBumpAction.
enum class UnifiedConsentBumpAction : int {
kUnifiedConsentBumpActionDefaultOptIn = 0,
kUnifiedConsentBumpActionMoreOptionsOptIn,
kUnifiedConsentBumpActionMoreOptionsReviewSettings,
kUnifiedConsentBumpActionMoreOptionsNoChanges,
kUnifiedConsentBumpActionMoreOptionsMax,
};
// Records histogram action for the unified consent bump.
void RecordConsentBumpMetric(UnifiedConsentBumpAction action);
} // namespace metrics
} // namespace unified_consent
#endif // COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_METRICS_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h" #import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h"
#include "base/logging.h" #include "base/logging.h"
#include "components/unified_consent/unified_consent_metrics.h"
#include "components/unified_consent/unified_consent_service.h" #include "components/unified_consent/unified_consent_service.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator_delegate.h" #import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator_delegate.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_mediator.h" #import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_mediator.h"
...@@ -18,6 +19,39 @@ ...@@ -18,6 +19,39 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using unified_consent::metrics::UnifiedConsentBumpAction;
using unified_consent::metrics::RecordConsentBumpMetric;
namespace {
void RecordMetricWithConsentBumpOptionType(ConsentBumpOptionType type) {
UnifiedConsentBumpAction action;
switch (type) {
case ConsentBumpOptionTypeNotSet:
NOTREACHED();
action = UnifiedConsentBumpAction::kUnifiedConsentBumpActionDefaultOptIn;
break;
case ConsentBumpOptionTypeDefaultYesImIn:
action = UnifiedConsentBumpAction::kUnifiedConsentBumpActionDefaultOptIn;
break;
case ConsentBumpOptionTypeMoreOptionsNoChange:
action = UnifiedConsentBumpAction::
kUnifiedConsentBumpActionMoreOptionsNoChanges;
break;
case ConsentBumpOptionTypeMoreOptionsReview:
action = UnifiedConsentBumpAction::
kUnifiedConsentBumpActionMoreOptionsReviewSettings;
break;
case ConsentBumpOptionTypeMoreOptionsTurnOn:
action =
UnifiedConsentBumpAction::kUnifiedConsentBumpActionMoreOptionsOptIn;
break;
}
RecordConsentBumpMetric(action);
}
} // namespace
@interface ConsentBumpCoordinator ()<ConsentBumpViewControllerDelegate, @interface ConsentBumpCoordinator ()<ConsentBumpViewControllerDelegate,
UnifiedConsentCoordinatorDelegate> UnifiedConsentCoordinatorDelegate>
...@@ -70,6 +104,7 @@ ...@@ -70,6 +104,7 @@
#pragma mark - ChromeCoordinator #pragma mark - ChromeCoordinator
- (void)start { - (void)start {
DCHECK(self.browserState);
self.consentBumpViewController = [[ConsentBumpViewController alloc] init]; self.consentBumpViewController = [[ConsentBumpViewController alloc] init];
self.consentBumpViewController.delegate = self; self.consentBumpViewController.delegate = self;
...@@ -100,28 +135,32 @@ ...@@ -100,28 +135,32 @@
ConsentBumpOptionType type = ConsentBumpOptionTypeNotSet; ConsentBumpOptionType type = ConsentBumpOptionTypeNotSet;
switch (self.presentedCoordinatorType) { switch (self.presentedCoordinatorType) {
case ConsentBumpScreenUnifiedConsent: case ConsentBumpScreenUnifiedConsent:
type = ConsentBumpOptionTypeTurnOn; type = ConsentBumpOptionTypeDefaultYesImIn;
break; break;
case ConsentBumpScreenPersonalization: case ConsentBumpScreenPersonalization:
type = self.personalizationCoordinator.selectedOption; type = self.personalizationCoordinator.selectedOption;
DCHECK_NE(ConsentBumpOptionTypeDefaultYesImIn, type);
break; break;
} }
unified_consent::UnifiedConsentService* unifiedConsentService =
UnifiedConsentServiceFactory::GetForBrowserState(self.browserState);
DCHECK(unifiedConsentService);
switch (type) { switch (type) {
case ConsentBumpOptionTypeNoChange: case ConsentBumpOptionTypeDefaultYesImIn:
// TODO(crbug.com/866506): Implement metrics. case ConsentBumpOptionTypeMoreOptionsTurnOn:
break; case ConsentBumpOptionTypeMoreOptionsReview:
case ConsentBumpOptionTypeReview: unifiedConsentService->SetUnifiedConsentGiven(true);
// TODO(crbug.com/866506): Implement metrics.
break; break;
case ConsentBumpOptionTypeTurnOn: case ConsentBumpOptionTypeMoreOptionsNoChange:
// TODO(crbug.com/866506): Implement metrics + sync updates.
break; break;
case ConsentBumpOptionTypeNotSet: case ConsentBumpOptionTypeNotSet:
NOTREACHED(); NOTREACHED();
break; break;
} }
RecordMetricWithConsentBumpOptionType(type);
BOOL showSettings = type == ConsentBumpOptionTypeMoreOptionsReview;
[self.delegate consentBumpCoordinator:self [self.delegate consentBumpCoordinator:self
didFinishNeedingToShowSettings:(type == ConsentBumpOptionTypeReview)]; didFinishNeedingToShowSettings:showSettings];
} }
- (void)consentBumpViewControllerDidTapSecondaryButton: - (void)consentBumpViewControllerDidTapSecondaryButton:
......
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
// Different option types. // Different option types.
typedef NS_ENUM(NSInteger, ConsentBumpOptionType) { typedef NS_ENUM(NSInteger, ConsentBumpOptionType) {
ConsentBumpOptionTypeNotSet = 0, ConsentBumpOptionTypeNotSet = 0,
ConsentBumpOptionTypeNoChange, ConsentBumpOptionTypeDefaultYesImIn,
ConsentBumpOptionTypeReview, ConsentBumpOptionTypeMoreOptionsNoChange,
ConsentBumpOptionTypeTurnOn ConsentBumpOptionTypeMoreOptionsReview,
ConsentBumpOptionTypeMoreOptionsTurnOn,
}; };
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_OPTION_TYPE_H_ #endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_OPTION_TYPE_H_
...@@ -108,15 +108,15 @@ const CGFloat kOptionsVerticalMargin = 16; ...@@ -108,15 +108,15 @@ const CGFloat kOptionsVerticalMargin = 16;
text: text:
l10n_util::GetNSString( l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_NO_CHANGE_TEXT)]; IDS_IOS_CONSENT_BUMP_NO_CHANGE_TEXT)];
noChangeOption.type = ConsentBumpOptionTypeNoChange; noChangeOption.type = ConsentBumpOptionTypeMoreOptionsNoChange;
noChangeOption.checked = YES; noChangeOption.checked = YES;
self.selectedOption = ConsentBumpOptionTypeNoChange; self.selectedOption = ConsentBumpOptionTypeMoreOptionsNoChange;
ConsentBumpOptionButton* reviewOption = [ConsentBumpOptionButton ConsentBumpOptionButton* reviewOption = [ConsentBumpOptionButton
consentBumpOptionButtonWithTitle:l10n_util::GetNSString( consentBumpOptionButtonWithTitle:l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_REVIEW_TITLE) IDS_IOS_CONSENT_BUMP_REVIEW_TITLE)
text:nil]; text:nil];
reviewOption.type = ConsentBumpOptionTypeReview; reviewOption.type = ConsentBumpOptionTypeMoreOptionsReview;
reviewOption.checked = NO; reviewOption.checked = NO;
ConsentBumpOptionButton* turnOnOption = [ConsentBumpOptionButton ConsentBumpOptionButton* turnOnOption = [ConsentBumpOptionButton
...@@ -124,7 +124,7 @@ const CGFloat kOptionsVerticalMargin = 16; ...@@ -124,7 +124,7 @@ const CGFloat kOptionsVerticalMargin = 16;
IDS_IOS_CONSENT_BUMP_TURN_ON_TITLE) IDS_IOS_CONSENT_BUMP_TURN_ON_TITLE)
text:l10n_util::GetNSString( text:l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_TURN_ON_TEXT)]; IDS_IOS_CONSENT_BUMP_TURN_ON_TEXT)];
turnOnOption.type = ConsentBumpOptionTypeTurnOn; turnOnOption.type = ConsentBumpOptionTypeMoreOptionsTurnOn;
turnOnOption.checked = NO; turnOnOption.checked = NO;
self.options = @[ noChangeOption, reviewOption, turnOnOption ]; self.options = @[ noChangeOption, reviewOption, turnOnOption ];
......
...@@ -5054,7 +5054,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -5054,7 +5054,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
return; return;
} }
self.consentBumpCoordinator = self.consentBumpCoordinator =
[[ConsentBumpCoordinator alloc] initWithBaseViewController:self]; [[ConsentBumpCoordinator alloc] initWithBaseViewController:self
browserState:_browserState];
self.consentBumpCoordinator.delegate = self; self.consentBumpCoordinator.delegate = self;
[self.consentBumpCoordinator start]; [self.consentBumpCoordinator start];
self.consentBumpCoordinator.viewController.modalPresentationStyle = self.consentBumpCoordinator.viewController.modalPresentationStyle =
......
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