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

Side by Side Diff: chrome/browser/chromeos/extensions/device_local_account_management_policy_provider.cc

Issue 2930653002: [Merge to M60] Added UMA for extension permissions used in public sessions (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/extensions/device_local_account_management_pol icy_provider.h" 5 #include "chrome/browser/chromeos/extensions/device_local_account_management_pol icy_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <string> 10 #include <string>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
18 #include "extensions/common/manifest.h" 19 #include "extensions/common/manifest.h"
19 #include "extensions/common/manifest_constants.h" 20 #include "extensions/common/manifest_constants.h"
20 #include "extensions/common/manifest_handlers/app_isolation_info.h" 21 #include "extensions/common/manifest_handlers/app_isolation_info.h"
22 #include "extensions/common/permissions/api_permission.h"
23 #include "extensions/common/permissions/permissions_info.h"
21 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
22 25
23 namespace chromeos { 26 namespace chromeos {
24 27
25 namespace { 28 namespace {
26 29
27 namespace emk = extensions::manifest_keys; 30 namespace emk = extensions::manifest_keys;
28 31
29 // Apps/extensions explicitly whitelisted for use in public sessions. 32 // Apps/extensions explicitly whitelisted for use in public sessions.
30 const char* const kPublicSessionWhitelist[] = { 33 const char* const kPublicSessionWhitelist[] = {
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 } 756 }
754 757
755 // See http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx for an 758 // See http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx for an
756 // explanation of array size determination. 759 // explanation of array size determination.
757 template <size_t N> 760 template <size_t N>
758 bool ArrayContains(const char* const (&char_array)[N], 761 bool ArrayContains(const char* const (&char_array)[N],
759 const std::string& entry) { 762 const std::string& entry) {
760 return ArrayContainsImpl(char_array, N, entry); 763 return ArrayContainsImpl(char_array, N, entry);
761 } 764 }
762 765
766 // Helper method used to log extension permissions UMA stats.
767 void LogPermissionUmaStats(const std::string& permission_string) {
768 const auto* permission_info =
769 extensions::PermissionsInfo::GetInstance()->GetByName(permission_string);
770 // Not a permission.
771 if (!permission_info) return;
772
773 UMA_HISTOGRAM_SPARSE_SLOWLY("Enterprise.PublicSession.ExtensionPermissions",
774 permission_info->id());
775 }
776
763 // Returns true for extensions that are considered safe for Public Sessions, 777 // Returns true for extensions that are considered safe for Public Sessions,
764 // which among other things requires the manifest top-level entries to be 778 // which among other things requires the manifest top-level entries to be
765 // contained in the |kSafeManifestEntries| whitelist and all permissions to be 779 // contained in the |kSafeManifestEntries| whitelist and all permissions to be
766 // contained in |kSafePermissionStrings| or |kSafePermissionDicts|. Otherwise 780 // contained in |kSafePermissionStrings| or |kSafePermissionDicts|. Otherwise
767 // returns false and logs all reasons for failure. 781 // returns false and logs all reasons for failure.
768 bool IsSafeForPublicSession(const extensions::Extension* extension) { 782 bool IsSafeForPublicSession(const extensions::Extension* extension) {
769 bool safe = true; 783 bool safe = true;
770 if (!extension->is_extension() && 784 if (!extension->is_extension() &&
771 !extension->is_hosted_app() && 785 !extension->is_hosted_app() &&
772 !extension->is_platform_app() && 786 !extension->is_platform_app() &&
(...skipping 27 matching lines...) Expand all
800 if (it2->GetAsDictionary(&dict_value)) { 814 if (it2->GetAsDictionary(&dict_value)) {
801 if (dict_value->size() != 1) { 815 if (dict_value->size() != 1) {
802 LOG(ERROR) << extension->id() 816 LOG(ERROR) << extension->id()
803 << " has dict in permission list with size " 817 << " has dict in permission list with size "
804 << dict_value->size() << "."; 818 << dict_value->size() << ".";
805 safe = false; 819 safe = false;
806 continue; 820 continue;
807 } 821 }
808 for (base::DictionaryValue::Iterator it3(*dict_value); 822 for (base::DictionaryValue::Iterator it3(*dict_value);
809 !it3.IsAtEnd(); it3.Advance()) { 823 !it3.IsAtEnd(); it3.Advance()) {
824 // Log permission (dictionary form).
825 LogPermissionUmaStats(it3.key());
810 if (!ArrayContains(kSafePermissionDicts, it3.key())) { 826 if (!ArrayContains(kSafePermissionDicts, it3.key())) {
811 LOG(ERROR) << extension->id() 827 LOG(ERROR) << extension->id()
812 << " has non-whitelisted dict in permission list: " 828 << " has non-whitelisted dict in permission list: "
813 << it3.key(); 829 << it3.key();
814 safe = false; 830 safe = false;
815 continue; 831 continue;
816 } 832 }
817 } 833 }
818 continue; 834 continue;
819 } 835 }
820 // Try to read as string. 836 // Try to read as string.
821 std::string permission_string; 837 std::string permission_string;
822 if (!it2->GetAsString(&permission_string)) { 838 if (!it2->GetAsString(&permission_string)) {
823 LOG(ERROR) << extension->id() << ": " << it.key() 839 LOG(ERROR) << extension->id() << ": " << it.key()
824 << " contains a token that's neither a string nor a dict."; 840 << " contains a token that's neither a string nor a dict.";
825 safe = false; 841 safe = false;
826 continue; 842 continue;
827 } 843 }
844 // Log permission (usual, string form).
845 LogPermissionUmaStats(permission_string);
828 // Accept whitelisted permissions. 846 // Accept whitelisted permissions.
829 if (ArrayContains(kSafePermissionStrings, permission_string)) { 847 if (ArrayContains(kSafePermissionStrings, permission_string)) {
830 continue; 848 continue;
831 } 849 }
832 // Web requests (origin permissions). Don't include <all_urls> because 850 // Web requests (origin permissions). Don't include <all_urls> because
833 // that also matches file:// schemes. 851 // that also matches file:// schemes.
834 if (base::StartsWith(permission_string, "https://", 852 if (base::StartsWith(permission_string, "https://",
835 base::CompareCase::SENSITIVE) || 853 base::CompareCase::SENSITIVE) ||
836 base::StartsWith(permission_string, "http://", 854 base::StartsWith(permission_string, "http://",
837 base::CompareCase::SENSITIVE) || 855 base::CompareCase::SENSITIVE) ||
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 if (error) { 998 if (error) {
981 *error = l10n_util::GetStringFUTF16( 999 *error = l10n_util::GetStringFUTF16(
982 IDS_EXTENSION_CANT_INSTALL_IN_DEVICE_LOCAL_ACCOUNT, 1000 IDS_EXTENSION_CANT_INSTALL_IN_DEVICE_LOCAL_ACCOUNT,
983 base::UTF8ToUTF16(extension->name()), 1001 base::UTF8ToUTF16(extension->name()),
984 base::UTF8ToUTF16(extension->id())); 1002 base::UTF8ToUTF16(extension->id()));
985 } 1003 }
986 return false; 1004 return false;
987 } 1005 }
988 1006
989 } // namespace chromeos 1007 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698