Chromium Code Reviews| Index: chrome/browser/chromeos/login/users/affiliation.cc |
| diff --git a/chrome/browser/chromeos/login/users/affiliation.cc b/chrome/browser/chromeos/login/users/affiliation.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a37f254d2cc743f648c643e5b07045f99c9ed391 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/users/affiliation.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2015 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 "chrome/browser/chromeos/login/users/affiliation.h" |
| + |
| +#include "chrome/browser/chromeos/policy/device_local_account.h" |
| +#include "google_apis/gaia/gaia_auth_util.h" |
| + |
| +namespace chromeos { |
| + |
| +bool HaveCommonElement(const std::set<std::string>& set1, |
| + const std::set<std::string>& set2) { |
| + std::set<std::string>::const_iterator it1 = set1.begin(); |
| + std::set<std::string>::const_iterator it2 = set2.begin(); |
| + |
| + while (it1 != set1.end() && it2 != set2.end()) { |
| + if (*it1 == *it2) |
| + return true; |
| + if (*it1 < *it2) { |
| + ++it1; |
| + } else { |
| + ++it2; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +bool IsUserAffiliated(const std::set<std::string>& user_affiliation_ids, |
| + const std::set<std::string>& device_affiliation_ids, |
| + const std::string& email, |
| + const std::string& enterprise_domain) { |
| + // An empty username means incognito user in case of ChromiumOS and |
| + // no logged-in user in case of Chromium (SigninService). Many tests use |
| + // nonsense email addresses (e.g. 'test') so treat those as non-enterprise |
| + // users. |
| + if (email.empty() || email.find('@') == std::string::npos) { |
| + return false; |
| + } |
| + |
| + if (policy::IsDeviceLocalAccountUser(email, NULL)) { |
| + return true; |
| + } |
| + |
| + // If either device or user affiliation IDs are provided, the feature is |
| + // implemented on server side and we should rely on them to determine the |
| + // affiliation. If no affiliation IDs provided, then maybe the feature is not |
| + // done on server side. In that case use the old logic. |
| + if (!device_affiliation_ids.empty() || !user_affiliation_ids.empty()) { |
|
Mattias Nissler (ping if slow)
2015/07/30 15:34:08
Do we need to worry about the case where the serve
peletskyi
2015/07/30 16:39:49
Done.
|
| + return HaveCommonElement(user_affiliation_ids, device_affiliation_ids); |
| + } |
| + |
| + // TODO(peletskyi): Remove the following backwards compatibility part. |
| + if (gaia::ExtractDomainName(gaia::CanonicalizeEmail(email)) == |
| + enterprise_domain) { |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| +} // namespace chromeos |