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") {
"feature.h",
"pref_names.cc",
"pref_names.h",
"unified_consent_metrics.cc",
"unified_consent_metrics.h",
"unified_consent_service.cc",
"unified_consent_service.h",
"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 @@
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h"
#include "base/logging.h"
#include "components/unified_consent/unified_consent_metrics.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_mediator.h"
......@@ -18,6 +19,39 @@
#error "This file requires ARC support."
#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,
UnifiedConsentCoordinatorDelegate>
......@@ -70,6 +104,7 @@
#pragma mark - ChromeCoordinator
- (void)start {
DCHECK(self.browserState);
self.consentBumpViewController = [[ConsentBumpViewController alloc] init];
self.consentBumpViewController.delegate = self;
......@@ -100,28 +135,32 @@
ConsentBumpOptionType type = ConsentBumpOptionTypeNotSet;
switch (self.presentedCoordinatorType) {
case ConsentBumpScreenUnifiedConsent:
type = ConsentBumpOptionTypeTurnOn;
type = ConsentBumpOptionTypeDefaultYesImIn;
break;
case ConsentBumpScreenPersonalization:
type = self.personalizationCoordinator.selectedOption;
DCHECK_NE(ConsentBumpOptionTypeDefaultYesImIn, type);
break;
}
unified_consent::UnifiedConsentService* unifiedConsentService =
UnifiedConsentServiceFactory::GetForBrowserState(self.browserState);
DCHECK(unifiedConsentService);
switch (type) {
case ConsentBumpOptionTypeNoChange:
// TODO(crbug.com/866506): Implement metrics.
break;
case ConsentBumpOptionTypeReview:
// TODO(crbug.com/866506): Implement metrics.
case ConsentBumpOptionTypeDefaultYesImIn:
case ConsentBumpOptionTypeMoreOptionsTurnOn:
case ConsentBumpOptionTypeMoreOptionsReview:
unifiedConsentService->SetUnifiedConsentGiven(true);
break;
case ConsentBumpOptionTypeTurnOn:
// TODO(crbug.com/866506): Implement metrics + sync updates.
case ConsentBumpOptionTypeMoreOptionsNoChange:
break;
case ConsentBumpOptionTypeNotSet:
NOTREACHED();
break;
}
RecordMetricWithConsentBumpOptionType(type);
BOOL showSettings = type == ConsentBumpOptionTypeMoreOptionsReview;
[self.delegate consentBumpCoordinator:self
didFinishNeedingToShowSettings:(type == ConsentBumpOptionTypeReview)];
didFinishNeedingToShowSettings:showSettings];
}
- (void)consentBumpViewControllerDidTapSecondaryButton:
......
......@@ -10,9 +10,10 @@
// Different option types.
typedef NS_ENUM(NSInteger, ConsentBumpOptionType) {
ConsentBumpOptionTypeNotSet = 0,
ConsentBumpOptionTypeNoChange,
ConsentBumpOptionTypeReview,
ConsentBumpOptionTypeTurnOn
ConsentBumpOptionTypeDefaultYesImIn,
ConsentBumpOptionTypeMoreOptionsNoChange,
ConsentBumpOptionTypeMoreOptionsReview,
ConsentBumpOptionTypeMoreOptionsTurnOn,
};
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_OPTION_TYPE_H_
......@@ -108,15 +108,15 @@ const CGFloat kOptionsVerticalMargin = 16;
text:
l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_NO_CHANGE_TEXT)];
noChangeOption.type = ConsentBumpOptionTypeNoChange;
noChangeOption.type = ConsentBumpOptionTypeMoreOptionsNoChange;
noChangeOption.checked = YES;
self.selectedOption = ConsentBumpOptionTypeNoChange;
self.selectedOption = ConsentBumpOptionTypeMoreOptionsNoChange;
ConsentBumpOptionButton* reviewOption = [ConsentBumpOptionButton
consentBumpOptionButtonWithTitle:l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_REVIEW_TITLE)
text:nil];
reviewOption.type = ConsentBumpOptionTypeReview;
reviewOption.type = ConsentBumpOptionTypeMoreOptionsReview;
reviewOption.checked = NO;
ConsentBumpOptionButton* turnOnOption = [ConsentBumpOptionButton
......@@ -124,7 +124,7 @@ const CGFloat kOptionsVerticalMargin = 16;
IDS_IOS_CONSENT_BUMP_TURN_ON_TITLE)
text:l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_TURN_ON_TEXT)];
turnOnOption.type = ConsentBumpOptionTypeTurnOn;
turnOnOption.type = ConsentBumpOptionTypeMoreOptionsTurnOn;
turnOnOption.checked = NO;
self.options = @[ noChangeOption, reviewOption, turnOnOption ];
......
......@@ -5054,7 +5054,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
return;
}
self.consentBumpCoordinator =
[[ConsentBumpCoordinator alloc] initWithBaseViewController:self];
[[ConsentBumpCoordinator alloc] initWithBaseViewController:self
browserState:_browserState];
self.consentBumpCoordinator.delegate = self;
[self.consentBumpCoordinator start];
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