Skip to content

Commit 640eb24

Browse files
author
Jérôme Lebel
committed
Recording user consent on iOS in the sync confirmation dialog
https://drive.google.com/open?id=1lm9YtGCZFxd7HyLdG4omPWoJy6R7Dg5i When the user accepts the sync confirmation, all the string ids need to be recorded using ConsentAuditor::RecordGaiaConsent(). See detailed explanation in this (internal) doc: https://docs.google.com/document/d/1Psl9VJ4Dbc1Dh5bXCTa85OF1_DE3viTTHYwybu3V6Uk/edit#bookmark=id.6zygb41dn9vl Related patch: crrev.com/c/897948 crrev.com/c/880861 Bug: 819204 Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs Change-Id: I6b4cba87e495af6a7d96e1428b6737e547ecf49f Reviewed-on: https://chromium-review.googlesource.com/924033 Commit-Queue: Jérôme Lebel <jlebel@chromium.org> Reviewed-by: Martin Šrámek <msramek@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Reviewed-by: Mihai Sardarescu <msarda@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#541089}(cherry picked from commit f25747e) Reviewed-on: https://chromium-review.googlesource.com/953462 Reviewed-by: Jérôme Lebel <jlebel@chromium.org> Cr-Commit-Position: refs/branch-heads/3359@{#71} Cr-Branched-From: 66afc5e-refs/heads/master@{#540276}
1 parent 44352a5 commit 640eb24

File tree

14 files changed

+214
-14
lines changed

14 files changed

+214
-14
lines changed

components/consent_auditor/consent_auditor.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "base/metrics/histogram_macros.h"
1010
#include "base/values.h"
11+
#include "build/build_config.h"
1112
#include "components/consent_auditor/pref_names.h"
1213
#include "components/prefs/pref_registry_simple.h"
1314
#include "components/prefs/pref_service.h"
@@ -110,10 +111,14 @@ void ConsentAuditor::RecordGaiaConsent(
110111
// FakeUserEventService doesn't have a sync bridge.
111112
// TODO(crbug.com/709094, crbug.com/761485): Remove this check when the store
112113
// initializes synchronously and is instantly ready to receive data.
114+
#if !defined(OS_IOS)
115+
// TODO(crbug.com/819176): On iOS the sync is may not be ready if the user
116+
// taps on "OK GOT IT" button too fast.
113117
DCHECK(!user_event_service_->GetSyncBridge() ||
114118
user_event_service_->GetSyncBridge()
115119
->change_processor()
116120
->IsTrackingMetadata());
121+
#endif
117122
user_event_service_->RecordUserEvent(std::move(specifics));
118123
}
119124

ios/chrome/browser/browser_state/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ source_set("browser_state_impl") {
8181
"//ios/chrome/browser/bookmarks",
8282
"//ios/chrome/browser/browser_state_metrics",
8383
"//ios/chrome/browser/browsing_data",
84+
"//ios/chrome/browser/consent_auditor",
8485
"//ios/chrome/browser/content_settings",
8586
"//ios/chrome/browser/desktop_promotion",
8687
"//ios/chrome/browser/dom_distiller",

ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
1313
#include "ios/chrome/browser/bookmarks/startup_task_runner_service_factory.h"
1414
#include "ios/chrome/browser/browsing_data/browsing_data_remover_factory.h"
15+
#include "ios/chrome/browser/consent_auditor/consent_auditor_factory.h"
1516
#include "ios/chrome/browser/content_settings/cookie_settings_factory.h"
1617
#include "ios/chrome/browser/desktop_promotion/desktop_promotion_sync_service_factory.h"
1718
#include "ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h"
@@ -103,6 +104,7 @@ void EnsureBrowserStateKeyedServiceFactoriesBuilt() {
103104
BrowserListFactory::GetInstance();
104105
BrowserListSessionServiceFactory::GetInstance();
105106
BrowsingDataRemoverFactory::GetInstance();
107+
ConsentAuditorFactory::GetInstance();
106108
DesktopPromotionSyncServiceFactory::GetInstance();
107109
feature_engagement::TrackerFactory::GetInstance();
108110
IOSChromeGCMProfileServiceFactory::GetInstance();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2018 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
source_set("consent_auditor") {
6+
configs += [ "//build/config/compiler:enable_arc" ]
7+
sources = [
8+
"consent_auditor_factory.cc",
9+
"consent_auditor_factory.h",
10+
]
11+
deps = [
12+
"//base",
13+
"//components/consent_auditor",
14+
"//components/keyed_service/ios",
15+
"//components/pref_registry",
16+
"//components/version_info",
17+
"//ios/chrome/browser",
18+
"//ios/chrome/browser/browser_state",
19+
"//ios/chrome/browser/sync",
20+
"//ios/web/public",
21+
]
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include_rules = [
2+
"+components/consent_auditor",
3+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jlebel@chromium.org
2+
msarda@chromium.org
3+
msramek@google.com
4+
5+
# COMPONENT: Privacy
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "ios/chrome/browser/consent_auditor/consent_auditor_factory.h"
6+
7+
#include "base/memory/ptr_util.h"
8+
#include "base/memory/singleton.h"
9+
#include "components/consent_auditor/consent_auditor.h"
10+
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
11+
#include "components/pref_registry/pref_registry_syncable.h"
12+
#include "components/version_info/version_info.h"
13+
#include "ios/chrome/browser/application_context.h"
14+
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
15+
#include "ios/chrome/browser/sync/ios_user_event_service_factory.h"
16+
#include "ios/web/public/browser_state.h"
17+
18+
// static
19+
consent_auditor::ConsentAuditor* ConsentAuditorFactory::GetForBrowserState(
20+
ios::ChromeBrowserState* browser_state) {
21+
return static_cast<consent_auditor::ConsentAuditor*>(
22+
GetInstance()->GetServiceForBrowserState(browser_state, true));
23+
}
24+
25+
// static
26+
consent_auditor::ConsentAuditor*
27+
ConsentAuditorFactory::GetForBrowserStateIfExists(
28+
ios::ChromeBrowserState* browser_state) {
29+
return static_cast<consent_auditor::ConsentAuditor*>(
30+
GetInstance()->GetServiceForBrowserState(browser_state, false));
31+
}
32+
33+
// static
34+
ConsentAuditorFactory* ConsentAuditorFactory::GetInstance() {
35+
return base::Singleton<ConsentAuditorFactory>::get();
36+
}
37+
38+
ConsentAuditorFactory::ConsentAuditorFactory()
39+
: BrowserStateKeyedServiceFactory(
40+
"ConsentAuditor",
41+
BrowserStateDependencyManager::GetInstance()) {
42+
DependsOn(IOSUserEventServiceFactory::GetInstance());
43+
}
44+
45+
ConsentAuditorFactory::~ConsentAuditorFactory() {}
46+
47+
std::unique_ptr<KeyedService> ConsentAuditorFactory::BuildServiceInstanceFor(
48+
web::BrowserState* browser_state) const {
49+
ios::ChromeBrowserState* ios_browser_state =
50+
ios::ChromeBrowserState::FromBrowserState(browser_state);
51+
syncer::UserEventService* const user_event_service =
52+
IOSUserEventServiceFactory::GetForBrowserState(ios_browser_state);
53+
return std::make_unique<consent_auditor::ConsentAuditor>(
54+
ios_browser_state->GetPrefs(), user_event_service,
55+
// The browser version and locale do not change runtime, so we can pass
56+
// them directly.
57+
version_info::GetVersionNumber(),
58+
GetApplicationContext()->GetApplicationLocale());
59+
}
60+
61+
bool ConsentAuditorFactory::ServiceIsNULLWhileTesting() const {
62+
return true;
63+
}
64+
65+
void ConsentAuditorFactory::RegisterBrowserStatePrefs(
66+
user_prefs::PrefRegistrySyncable* registry) {
67+
consent_auditor::ConsentAuditor::RegisterProfilePrefs(registry);
68+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef IOS_CHROME_BROWSER_CONSENT_AUDITOR_CONSENT_AUDITOR_FACTORY_H_
6+
#define IOS_CHROME_BROWSER_CONSENT_AUDITOR_CONSENT_AUDITOR_FACTORY_H_
7+
8+
#include "base/memory/singleton.h"
9+
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
10+
11+
namespace consent_auditor {
12+
class ConsentAuditor;
13+
} // namespace consent_auditor
14+
15+
namespace ios {
16+
class ChromeBrowserState;
17+
} // namespace ios
18+
19+
// Singleton that owns all ConsentAuditors and associates them with
20+
// ios::ChromeBrowserState.
21+
class ConsentAuditorFactory : public BrowserStateKeyedServiceFactory {
22+
public:
23+
static consent_auditor::ConsentAuditor* GetForBrowserState(
24+
ios::ChromeBrowserState* browser_state);
25+
static consent_auditor::ConsentAuditor* GetForBrowserStateIfExists(
26+
ios::ChromeBrowserState* browser_state);
27+
static ConsentAuditorFactory* GetInstance();
28+
29+
private:
30+
friend struct base::DefaultSingletonTraits<ConsentAuditorFactory>;
31+
32+
ConsentAuditorFactory();
33+
~ConsentAuditorFactory() override;
34+
35+
// BrowserStateKeyedServiceFactory implementation.
36+
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
37+
web::BrowserState* context) const override;
38+
bool ServiceIsNULLWhileTesting() const override;
39+
void RegisterBrowserStatePrefs(
40+
user_prefs::PrefRegistrySyncable* registry) override;
41+
42+
DISALLOW_COPY_AND_ASSIGN(ConsentAuditorFactory);
43+
};
44+
45+
#endif // IOS_CHROME_BROWSER_CONSENT_AUDITOR_CONSENT_AUDITOR_FACTORY_H_

ios/chrome/browser/prefs/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ source_set("browser_prefs") {
6060
"//components/web_resource",
6161
"//ios/chrome/browser",
6262
"//ios/chrome/browser/browser_state",
63+
"//ios/chrome/browser/consent_auditor",
6364
"//ios/chrome/browser/desktop_promotion",
6465
"//ios/chrome/browser/first_run",
6566
"//ios/chrome/browser/geolocation",

ios/chrome/browser/ui/authentication/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ source_set("authentication") {
3434
"resources:signin_confirmation_more",
3535
"resources:signin_promo_close_gray",
3636
"//base",
37+
"//components/consent_auditor",
3738
"//components/google/core/browser",
3839
"//components/infobars/core",
3940
"//components/prefs",
@@ -46,6 +47,7 @@ source_set("authentication") {
4647
"//ios/chrome/browser",
4748
"//ios/chrome/browser/browser_state",
4849
"//ios/chrome/browser/browsing_data",
50+
"//ios/chrome/browser/consent_auditor",
4951
"//ios/chrome/browser/infobars",
5052
"//ios/chrome/browser/signin",
5153
"//ios/chrome/browser/sync",

0 commit comments

Comments
 (0)