Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Side by Side Diff: chrome/browser/chromeos/login/users/affiliation.cc

Issue 1266563002: Added affiliation IDs for the new affiliation determination. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/chromeos/login/users/affiliation.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/chromeos/policy/device_local_account.h"
9 #include "google_apis/gaia/gaia_auth_util.h"
10
11 namespace chromeos {
12
13 bool HaveCommonElement(const std::set<std::string>& set1,
14 const std::set<std::string>& set2) {
15 std::set<std::string>::const_iterator it1 = set1.begin();
16 std::set<std::string>::const_iterator it2 = set2.begin();
17
18 while (it1 != set1.end() && it2 != set2.end()) {
19 if (*it1 == *it2)
20 return true;
21 if (*it1 < *it2) {
22 ++it1;
23 } else {
24 ++it2;
25 }
26 }
27 return false;
28 }
29
30 bool IsUserAffiliated(const std::set<std::string>& user_affiliation_ids,
31 const std::set<std::string>& device_affiliation_ids,
32 const std::string& email,
33 const std::string& enterprise_domain) {
34 // An empty username means incognito user in case of ChromiumOS and
35 // no logged-in user in case of Chromium (SigninService). Many tests use
36 // nonsense email addresses (e.g. 'test') so treat those as non-enterprise
37 // users.
38 if (email.empty() || email.find('@') == std::string::npos) {
39 return false;
40 }
41
42 if (policy::IsDeviceLocalAccountUser(email, NULL)) {
43 return true;
44 }
45
46 // If either device or user affiliation IDs are provided, the feature is
47 // implemented on server side and we should rely on them to determine the
48 // affiliation. If no affiliation IDs provided, then maybe the feature is not
49 // done on server side. In that case use the old logic.
50 if (!device_affiliation_ids.empty() || !user_affiliation_ids.empty()) {
51 return HaveCommonElement(user_affiliation_ids, device_affiliation_ids);
52 }
53
54 // TODO(peletskyi): Remove the following backwards compatibility part.
55 if (gaia::ExtractDomainName(gaia::CanonicalizeEmail(email)) ==
56 enterprise_domain) {
57 return true;
58 }
59
60 return false;
61 }
62
63 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698