1 // Copyright 2015 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.
5 #include "chrome/browser/chromeos/login/users/affiliation.h"
7 #include "chrome/browser/chromeos/policy/device_local_account.h"
8 #include "google_apis/gaia/gaia_auth_util.h"
12 bool HaveCommonElement(const std::set
<std::string
>& set1
,
13 const std::set
<std::string
>& set2
) {
14 std::set
<std::string
>::const_iterator it1
= set1
.begin();
15 std::set
<std::string
>::const_iterator it2
= set2
.begin();
17 while (it1
!= set1
.end() && it2
!= set2
.end()) {
29 bool IsUserAffiliated(const AffiliationIDSet
& user_affiliation_ids
,
30 const AffiliationIDSet
& device_affiliation_ids
,
31 const std::string
& email
,
32 const std::string
& enterprise_domain
) {
33 // An empty username means incognito user in case of ChromiumOS and
34 // no logged-in user in case of Chromium (SigninService). Many tests use
35 // nonsense email addresses (e.g. 'test') so treat those as non-enterprise
37 if (email
.empty() || email
.find('@') == std::string::npos
) {
41 if (policy::IsDeviceLocalAccountUser(email
, NULL
)) {
45 if (!device_affiliation_ids
.empty() && !user_affiliation_ids
.empty()) {
46 return HaveCommonElement(user_affiliation_ids
, device_affiliation_ids
);
49 // TODO(peletskyi): Remove the following backwards compatibility part.
50 if (gaia::ExtractDomainName(gaia::CanonicalizeEmail(email
)) ==
58 } // namespace chromeos