Commit ecb995b4 authored by Filip Gorski's avatar Filip Gorski Committed by Commit Bot

[EoC] Provide check for whether the profile is enterprise policy controlled

* Updates the ContextualSuggestionsBridge to provide the policy check.

Bug: 829458
Change-Id: I941ce0b5bf0776ced410813d238bc9d6712be6fa
Reviewed-on: https://chromium-review.googlesource.com/1000142Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Filip Gorski <fgorski@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549313}
parent 80014088
...@@ -53,6 +53,13 @@ class ContextualSuggestionsBridge { ...@@ -53,6 +53,13 @@ class ContextualSuggestionsBridge {
mNativeContextualSuggestionsBridge = nativeInit(profile); mNativeContextualSuggestionsBridge = nativeInit(profile);
} }
/**
* @return Whether the current profile is enterprise policy managed.
*/
static boolean isEnterprisePolicyManaged() {
return nativeIsEnterprisePolicyManaged();
}
/** Destroys the bridge. */ /** Destroys the bridge. */
void destroy() { void destroy() {
assert mNativeContextualSuggestionsBridge != 0; assert mNativeContextualSuggestionsBridge != 0;
...@@ -125,6 +132,7 @@ class ContextualSuggestionsBridge { ...@@ -125,6 +132,7 @@ class ContextualSuggestionsBridge {
/*isVideoSuggestion=*/false, /*thumbnailDominantColor=*/0)); /*isVideoSuggestion=*/false, /*thumbnailDominantColor=*/0));
} }
static private native boolean nativeIsEnterprisePolicyManaged();
private native long nativeInit(Profile profile); private native long nativeInit(Profile profile);
private native void nativeDestroy(long nativeContextualSuggestionsBridge); private native void nativeDestroy(long nativeContextualSuggestionsBridge);
private native void nativeFetchSuggestions(long nativeContextualSuggestionsBridge, String url, private native void nativeFetchSuggestions(long nativeContextualSuggestionsBridge, String url,
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.contextual_suggestions; package org.chromium.chrome.browser.contextual_suggestions;
import org.chromium.chrome.browser.signin.SigninManager;
import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
import org.chromium.chrome.browser.sync.ProfileSyncService; import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListener; import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListener;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
...@@ -13,7 +15,7 @@ import org.chromium.components.sync.UploadState; ...@@ -13,7 +15,7 @@ import org.chromium.components.sync.UploadState;
* A monitor that is responsible for detecting changes to conditions required for contextual * A monitor that is responsible for detecting changes to conditions required for contextual
* suggestions to be enabled. Alerts its {@link Observer} when state changes. * suggestions to be enabled. Alerts its {@link Observer} when state changes.
*/ */
public class EnabledStateMonitor implements SyncStateChangedListener { public class EnabledStateMonitor implements SyncStateChangedListener, SignInStateObserver {
/** An observer to be notified of enabled state changes. **/ /** An observer to be notified of enabled state changes. **/
interface Observer { interface Observer {
void onEnabledStateChanged(boolean enabled); void onEnabledStateChanged(boolean enabled);
...@@ -29,11 +31,13 @@ public class EnabledStateMonitor implements SyncStateChangedListener { ...@@ -29,11 +31,13 @@ public class EnabledStateMonitor implements SyncStateChangedListener {
EnabledStateMonitor(Observer observer) { EnabledStateMonitor(Observer observer) {
mObserver = observer; mObserver = observer;
ProfileSyncService.get().addSyncStateChangedListener(this); ProfileSyncService.get().addSyncStateChangedListener(this);
SigninManager.get().addSignInStateObserver(this);
updateEnabledState(); updateEnabledState();
} }
void destroy() { void destroy() {
ProfileSyncService.get().removeSyncStateChangedListener(this); ProfileSyncService.get().removeSyncStateChangedListener(this);
SigninManager.get().removeSignInStateObserver(this);
} }
@Override @Override
...@@ -41,6 +45,16 @@ public class EnabledStateMonitor implements SyncStateChangedListener { ...@@ -41,6 +45,16 @@ public class EnabledStateMonitor implements SyncStateChangedListener {
updateEnabledState(); updateEnabledState();
} }
@Override
public void onSignedIn() {
updateEnabledState();
}
@Override
public void onSignedOut() {
updateEnabledState();
}
/** /**
* Updates whether contextual suggestions are enabled. Notifies the observer if the * Updates whether contextual suggestions are enabled. Notifies the observer if the
* enabled state has changed. * enabled state has changed.
...@@ -49,10 +63,11 @@ public class EnabledStateMonitor implements SyncStateChangedListener { ...@@ -49,10 +63,11 @@ public class EnabledStateMonitor implements SyncStateChangedListener {
boolean previousState = mEnabled; boolean previousState = mEnabled;
ProfileSyncService service = ProfileSyncService.get(); ProfileSyncService service = ProfileSyncService.get();
mEnabled = service.getUploadToGoogleState(ModelType.HISTORY_DELETE_DIRECTIVES) mEnabled = (service.getUploadToGoogleState(ModelType.HISTORY_DELETE_DIRECTIVES)
== UploadState.ACTIVE; == UploadState.ACTIVE)
&& !ContextualSuggestionsBridge.isEnterprisePolicyManaged();
// TODO(twellington): Add other run-time checks, e.g. enterprise policy, opt-out state. // TODO(twellington): Add other run-time checks, e.g. opt-out state.
if (mEnabled != previousState) mObserver.onEnabledStateChanged(mEnabled); if (mEnabled != previousState) mObserver.onEnabledStateChanged(mEnabled);
} }
......
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/callback.h" #include "base/callback.h"
#include "chrome/browser/ntp_snippets/contextual_content_suggestions_service_factory.h" #include "chrome/browser/ntp_snippets/contextual_content_suggestions_service_factory.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h" #include "chrome/browser/profiles/profile_android.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/ntp_snippets/category.h" #include "components/ntp_snippets/category.h"
#include "components/ntp_snippets/content_suggestions_service.h" #include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ntp_snippets/contextual/contextual_content_suggestions_service.h" #include "components/ntp_snippets/contextual/contextual_content_suggestions_service.h"
...@@ -48,6 +51,23 @@ static jlong JNI_ContextualSuggestionsBridge_Init( ...@@ -48,6 +51,23 @@ static jlong JNI_ContextualSuggestionsBridge_Init(
return reinterpret_cast<intptr_t>(contextual_suggestions_bridge); return reinterpret_cast<intptr_t>(contextual_suggestions_bridge);
} }
static jboolean JNI_ContextualSuggestionsBridge_IsEnterprisePolicyManaged(
JNIEnv* env,
const JavaParamRef<jclass>& clazz) {
// TODO(fgorski): This is simply checking whether the profile is managed by
// an enterprise policy.
// http://crbug.com/829460 covers implementation of policy controller for
// contextual content suggestions.
Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
if (!profile)
return false;
policy::ProfilePolicyConnector* policy_connector =
policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile);
return (policy_connector != nullptr) && policy_connector->IsManaged();
}
ContextualSuggestionsBridge::ContextualSuggestionsBridge( ContextualSuggestionsBridge::ContextualSuggestionsBridge(
JNIEnv* env, JNIEnv* env,
std::unique_ptr<ContextualContentSuggestionsServiceProxy> service_proxy) std::unique_ptr<ContextualContentSuggestionsServiceProxy> service_proxy)
......
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