Chromium Code Reviews| Index: components/policy/core/browser/android/app_restrictions_importer.cc |
| diff --git a/chrome/browser/android/policy/policy_manager.cc b/components/policy/core/browser/android/app_restrictions_importer.cc |
| similarity index 53% |
| copy from chrome/browser/android/policy/policy_manager.cc |
| copy to components/policy/core/browser/android/app_restrictions_importer.cc |
| index 62dbf405c12826e7b216fbbe241eff0a9566d2a1..d808aa2bbcc412116487aeb50b00b07f229c1034 100644 |
| --- a/chrome/browser/android/policy/policy_manager.cc |
| +++ b/components/policy/core/browser/android/app_restrictions_importer.cc |
| @@ -2,73 +2,59 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/android/policy/policy_manager.h" |
| +#include "components/policy/core/browser/android/app_restrictions_importer.h" |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_array.h" |
| #include "base/android/jni_string.h" |
| -#include "base/bind.h" |
| #include "base/json/json_reader.h" |
| #include "base/prefs/pref_service.h" |
|
bartfab (slow)
2015/07/03 16:55:48
Nit: Not used.
dgn
2015/07/06 17:34:03
Done.
|
| #include "base/strings/string_number_conversions.h" |
| -#include "chrome/browser/browser_process.h" |
| -#include "chrome/browser/profiles/profile_manager.h" |
| -#include "chrome/common/pref_names.h" |
| -#include "components/policy/core/browser/browser_policy_connector.h" |
| +#include "components/policy/core/common/policy_bundle.h" |
| #include "components/policy/core/common/policy_provider_android.h" |
| -#include "jni/PolicyManager_jni.h" |
| -using base::android::AttachCurrentThread; |
| using base::android::ConvertJavaStringToUTF8; |
| -PolicyManager::PolicyManager(JNIEnv* env, jobject obj) |
| - : weak_java_policy_manager_(env, obj), |
| - policy_bundle_(new policy::PolicyBundle) { |
| - policy_provider_ = static_cast<policy::PolicyProviderAndroid*>( |
| - g_browser_process->browser_policy_connector()->GetPlatformProvider()); |
| - policy_provider_->SetDelegate(this); |
| -} |
| - |
| -PolicyManager::~PolicyManager() {} |
| +namespace policy { |
| -void PolicyManager::RefreshPolicies() { |
| - JNIEnv* env = AttachCurrentThread(); |
| - Java_PolicyManager_refreshPolicies( |
| - env, weak_java_policy_manager_.get(env).obj()); |
| +AppRestrictionsImporter::AppRestrictionsImporter() |
| + : policy_bundle_(new PolicyBundle) { |
| } |
| -void PolicyManager::PolicyProviderShutdown() { |
| - policy_provider_ = NULL; |
| +AppRestrictionsImporter::~AppRestrictionsImporter() {} |
|
bartfab (slow)
2015/07/03 16:55:47
Please move this and the following method so that
dgn
2015/07/06 17:34:03
Done.
|
| + |
| +PolicyNamespace AppRestrictionsImporter::GetPolicyNamespace() { |
| + return PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()); |
|
bartfab (slow)
2015/07/03 16:55:48
Nit: #include "components/policy/core/common/polic
dgn
2015/07/06 17:34:03
Done.
|
| } |
| -void PolicyManager::SetPolicyBoolean(JNIEnv* env, |
| - jobject obj, |
| - jstring policyKey, |
| - jboolean value) { |
| +void AppRestrictionsImporter::SetPolicyBoolean(JNIEnv* env, |
| + jobject obj, |
| + jstring policyKey, |
| + jboolean value) { |
| SetPolicyValue(ConvertJavaStringToUTF8(env, policyKey), |
| new base::FundamentalValue(static_cast<bool>(value))); |
|
bartfab (slow)
2015/07/03 16:55:47
Nit: #include "base/values.h"
dgn
2015/07/06 17:34:03
Done.
|
| } |
| -void PolicyManager::SetPolicyInteger(JNIEnv* env, |
| - jobject obj, |
| - jstring policyKey, |
| - jint value) { |
| +void AppRestrictionsImporter::SetPolicyInteger(JNIEnv* env, |
| + jobject obj, |
| + jstring policyKey, |
| + jint value) { |
| SetPolicyValue(ConvertJavaStringToUTF8(env, policyKey), |
| new base::FundamentalValue(static_cast<int>(value))); |
| } |
| -void PolicyManager::SetPolicyString(JNIEnv* env, |
| - jobject obj, |
| - jstring policyKey, |
| - jstring value) { |
| +void AppRestrictionsImporter::SetPolicyString(JNIEnv* env, |
| + jobject obj, |
| + jstring policyKey, |
| + jstring value) { |
| SetPolicyValue(ConvertJavaStringToUTF8(env, policyKey), |
| new base::StringValue(ConvertJavaStringToUTF8(env, value))); |
| } |
| -void PolicyManager::SetPolicyStringArray(JNIEnv* env, |
| - jobject obj, |
| - jstring policyKey, |
| - jobjectArray array) { |
| +void AppRestrictionsImporter::SetPolicyStringArray(JNIEnv* env, |
| + jobject obj, |
| + jstring policyKey, |
| + jobjectArray array) { |
| std::vector<base::string16> string_vector; |
|
bartfab (slow)
2015/07/03 16:55:47
Nit 1: #include <vector>
Nit 2: #include "base/str
dgn
2015/07/06 17:34:03
Done.
|
| base::android::AppendJavaStringArrayToStringVector(env, array, |
| &string_vector); |
| @@ -77,24 +63,19 @@ void PolicyManager::SetPolicyStringArray(JNIEnv* env, |
| SetPolicyValue(ConvertJavaStringToUTF8(env, policyKey), list_values); |
| } |
| -void PolicyManager::FlushPolicies(JNIEnv* env, jobject obj) { |
| - if (!policy_provider_) |
| +void AppRestrictionsImporter::FlushPolicies(JNIEnv* env, jobject obj) { |
| + PolicyProviderAndroid* policy_provider = GetPolicyProvider(); |
|
bartfab (slow)
2015/07/03 16:55:47
Nit: const pointer.
dgn
2015/07/07 11:31:17
Do you mean PolicyProviderAndroid* const policy_pr
|
| + if (!policy_provider) |
| return; |
| - policy_provider_->SetPolicies(policy_bundle_.Pass()); |
| - policy_bundle_.reset(new policy::PolicyBundle); |
| -} |
| - |
| -void PolicyManager::Destroy(JNIEnv* env, jobject obj) { |
| - if (policy_provider_) |
| - policy_provider_->SetDelegate(NULL); |
| - |
| - delete this; |
| + policy_provider->SetPolicies(policy_bundle_.Pass()); |
| + policy_bundle_.reset(new PolicyBundle); |
| } |
| // static |
| -base::Value* PolicyManager::ConvertValueToSchema(base::Value* raw_value, |
| - const policy::Schema& schema) { |
| +base::Value* AppRestrictionsImporter::ConvertValueToSchema( |
| + base::Value* raw_value, |
|
bartfab (slow)
2015/07/03 16:55:47
Nit: Indentation.
dgn
2015/07/06 17:34:03
Done.
|
| + const Schema& schema) { |
|
bartfab (slow)
2015/07/03 16:55:48
Nit: #include "components/policy/core/common/schem
dgn
2015/07/06 17:34:02
Done.
|
| scoped_ptr<base::Value> value(raw_value); |
| if (!schema.valid()) |
| @@ -150,7 +131,7 @@ base::Value* PolicyManager::ConvertValueToSchema(base::Value* raw_value, |
| // Binary is not a valid schema type. |
| case base::Value::TYPE_BINARY: { |
| NOTREACHED(); |
|
bartfab (slow)
2015/07/03 16:55:47
Nit: #include "base/logging.h"
dgn
2015/07/06 17:34:03
Done.
|
| - return NULL; |
| + return nullptr; |
| } |
| // Complex types have to be deserialized from JSON. |
| @@ -168,28 +149,22 @@ base::Value* PolicyManager::ConvertValueToSchema(base::Value* raw_value, |
| } |
| NOTREACHED(); |
| - return NULL; |
| + return nullptr; |
| } |
| -void PolicyManager::SetPolicyValue(const std::string& key, base::Value* value) { |
| - if (!policy_provider_) |
| +void AppRestrictionsImporter::SetPolicyValue(const std::string& key, |
| + base::Value* value) { |
| + if (!GetPolicyProvider()) |
|
bartfab (slow)
2015/07/03 16:55:48
Why does it matter here whether we have a policy p
dgn
2015/07/06 17:34:03
We want to avoid crashing on a null pointer. Well,
|
| return; |
| - policy::Schema schema = |
| - policy_provider_->GetChromeSchema()->GetKnownProperty(key); |
| + Schema schema = GetPolicySchema(key); |
|
bartfab (slow)
2015/07/03 16:55:48
Nit: const.
dgn
2015/07/06 17:34:03
Done.
|
| - policy::PolicyNamespace ns(policy::POLICY_DOMAIN_CHROME, std::string()); |
| + PolicyNamespace ns = GetPolicyNamespace(); |
|
bartfab (slow)
2015/07/03 16:55:48
Nit: const.
dgn
2015/07/06 17:34:02
Done.
|
| policy_bundle_->Get(ns).Set(key, |
|
bartfab (slow)
2015/07/03 16:55:47
Nit: #include "components/policy/core/common/polic
dgn
2015/07/06 17:34:03
Done.
|
| - policy::POLICY_LEVEL_MANDATORY, |
| - policy::POLICY_SCOPE_MACHINE, |
| + POLICY_LEVEL_MANDATORY, |
|
bartfab (slow)
2015/07/03 16:55:48
Nit: #include "components/policy/core/common/polic
dgn
2015/07/06 17:34:03
Done.
|
| + POLICY_SCOPE_MACHINE, |
| ConvertValueToSchema(value, schema), |
| - NULL); |
| -} |
| - |
| -static jlong Init(JNIEnv* env, jobject obj) { |
| - return reinterpret_cast<intptr_t>(new PolicyManager(env, obj)); |
| + nullptr); |
| } |
| -bool RegisterPolicyManager(JNIEnv* env) { |
| - return RegisterNativesImpl(env); |
| } |