Commit 9c3880c0 authored by tby's avatar tby Committed by Commit Bot

[Suggested files] Gate suggested files based on enterprise policy.

Bug: 1034842
Change-Id: I95859612d1603a1fe87641d636c29a7de8dbc658
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426668Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Reviewed-by: default avatarTony Yeoman <tby@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811063}
parent 0ebe1eb8
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "components/drive/drive_pref_names.h"
#include "components/google/core/common/google_util.h" #include "components/google/core/common/google_util.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/access_token_info.h" #include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/consent_level.h" #include "components/signin/public/identity_manager/consent_level.h"
...@@ -51,7 +53,12 @@ constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = ...@@ -51,7 +53,12 @@ constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
policy { policy {
cookies_allowed: NO cookies_allowed: NO
setting: setting:
"This cannot be disabled." "This cannot be disabled except by policy."
chrome_policy {
DriveDisabled {
DriveDisabled: true
}
}
})"); })");
// The scope required for an access token in order to query ItemSuggest. // The scope required for an access token in order to query ItemSuggest.
...@@ -68,26 +75,29 @@ constexpr char kRequestBody[] = R"({ ...@@ -68,26 +75,29 @@ constexpr char kRequestBody[] = R"({
'scenario_type': 'QUICK_ACCESS' 'scenario_type': 'QUICK_ACCESS'
}})"; }})";
bool IsDisabledByPolicy(const Profile* profile) {
return profile->GetPrefs()->GetBoolean(drive::prefs::kDisableDrive);
}
//---------------- //----------------
// Error utilities // Error utilities
//---------------- //----------------
// Possible error states of the item suggest cache. These values persist to // Possible error states of the item suggest cache.
// logs. Entries should not be renumbered and numeric values should never be
// reused.
enum class Error { enum class Error {
kDisabled = 1, kDisabledByExperiment = 1,
kInvalidServerUrl = 2, kDisabledByPolicy = 2,
kNoIdentityManager = 3, kInvalidServerUrl = 3,
kGoogleAuthError = 4, kNoIdentityManager = 4,
kNetError = 5, kGoogleAuthError = 5,
k3xxError = 6, kNetError = 6,
k4xxError = 7, k3xxError = 7,
k5xxError = 8, k4xxError = 8,
kEmptyResponse = 9, k5xxError = 9,
kNoResultsInResponse = 10, kEmptyResponse = 10,
kJsonParseFailure = 11, kNoResultsInResponse = 11,
kJsonConversionFailure = 12, kJsonParseFailure = 12,
kJsonConversionFailure = 13,
kMaxValue = kJsonConversionFailure, kMaxValue = kJsonConversionFailure,
}; };
...@@ -204,15 +214,18 @@ void ItemSuggestCache::UpdateCache() { ...@@ -204,15 +214,18 @@ void ItemSuggestCache::UpdateCache() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(crbug.com/1034842): Add rate-limiting for cache updates. // TODO(crbug.com/1034842): Add rate-limiting for cache updates.
// Make no requests and exit in four cases: // Make no requests and exit in these cases:
// - item suggest has been disabled via experiment
// - the server url is not https
// - the server url is not trusted by Google
// - another request is in-flight (url_loader_ is non-null) // - another request is in-flight (url_loader_ is non-null)
// - item suggest has been disabled via experiment
// - item suggest has been disabled by policy
// - the server url is not https or not trusted by Google
if (url_loader_) { if (url_loader_) {
return; return;
} else if (!enabled_) { } else if (!enabled_) {
LogError(Error::kDisabled); LogError(Error::kDisabledByExperiment);
return;
} else if (IsDisabledByPolicy(profile_)) {
LogError(Error::kDisabledByPolicy);
return; return;
} else if (!server_url_.SchemeIs(url::kHttpsScheme) || } else if (!server_url_.SchemeIs(url::kHttpsScheme) ||
!google_util::IsGoogleAssociatedDomainUrl(server_url_)) { !google_util::IsGoogleAssociatedDomainUrl(server_url_)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment