forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search] Add a policy to allow disabling a search feature
Specifically, Contextual Search can now be controlled by policy. BUG=432631 Review URL: https://codereview.chromium.org/720933002 Cr-Commit-Position: refs/heads/master@{#304662}
- Loading branch information
mathp
authored and
Commit bot
committed
Nov 18, 2014
1 parent
b4c4604
commit cc5d84f
Showing
11 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
chrome/browser/search/contextual_search_policy_handler_android.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/search/contextual_search_policy_handler_android.h" | ||
|
||
#include "base/prefs/pref_value_map.h" | ||
#include "base/values.h" | ||
#include "chrome/common/pref_names.h" | ||
#include "components/policy/core/common/policy_map.h" | ||
#include "policy/policy_constants.h" | ||
|
||
namespace policy { | ||
|
||
ContextualSearchPolicyHandlerAndroid::ContextualSearchPolicyHandlerAndroid() | ||
: TypeCheckingPolicyHandler(key::kContextualSearchEnabled, | ||
base::Value::TYPE_BOOLEAN) {} | ||
|
||
ContextualSearchPolicyHandlerAndroid::~ContextualSearchPolicyHandlerAndroid() { | ||
} | ||
|
||
void ContextualSearchPolicyHandlerAndroid::ApplyPolicySettings( | ||
const PolicyMap& policies, | ||
PrefValueMap* prefs) { | ||
const base::Value* value = policies.GetValue(policy_name()); | ||
bool contextual_search_enabled = true; | ||
// From a Contextual Search preference point of view, "false" means the | ||
// feature is turned off completely. "" means the feature is uninitialized and | ||
// an opt-in screen is presented to the user, after which the preference is | ||
// either "true" or "false", depending on their choice. Here a false policy | ||
// explicitly disables Contextual Search. | ||
if (value && | ||
value->GetAsBoolean(&contextual_search_enabled) && | ||
!contextual_search_enabled) { | ||
prefs->SetString(prefs::kContextualSearchEnabled, "false"); | ||
} | ||
} | ||
|
||
} // namespace policy |
31 changes: 31 additions & 0 deletions
31
chrome/browser/search/contextual_search_policy_handler_android.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_SEARCH_CONTEXTUAL_SEARCH_POLICY_HANDLER_ANDROID_H_ | ||
#define CHROME_BROWSER_SEARCH_CONTEXTUAL_SEARCH_POLICY_HANDLER_ANDROID_H_ | ||
|
||
#include "components/policy/core/browser/configuration_policy_handler.h" | ||
|
||
namespace policy { | ||
|
||
class PolicyMap; | ||
|
||
// ConfigurationPolicyHandler for the ContextualSearchEnabled policy. | ||
class ContextualSearchPolicyHandlerAndroid | ||
: public TypeCheckingPolicyHandler { | ||
public: | ||
ContextualSearchPolicyHandlerAndroid(); | ||
~ContextualSearchPolicyHandlerAndroid() override; | ||
|
||
// ConfigurationPolicyHandler methods: | ||
void ApplyPolicySettings(const PolicyMap& policies, | ||
PrefValueMap* prefs) override; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(ContextualSearchPolicyHandlerAndroid); | ||
}; | ||
|
||
} // namespace policy | ||
|
||
#endif // CHROME_BROWSER_SEARCH_CONTEXTUAL_SEARCH_POLICY_HANDLER_ANDROID_H_ |
59 changes: 59 additions & 0 deletions
59
chrome/browser/search/contextual_search_policy_handler_android_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/prefs/pref_value_map.h" | ||
#include "base/values.h" | ||
#include "chrome/browser/search/contextual_search_policy_handler_android.h" | ||
#include "chrome/common/pref_names.h" | ||
#include "components/policy/core/common/policy_map.h" | ||
#include "policy/policy_constants.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace policy { | ||
|
||
TEST(ContextualSearchPolicyHandlerAndroidTest, Default) { | ||
PolicyMap policy; | ||
PrefValueMap prefs; | ||
ContextualSearchPolicyHandlerAndroid handler; | ||
handler.ApplyPolicySettings(policy, &prefs); | ||
std::string pref_value; | ||
EXPECT_FALSE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); | ||
EXPECT_EQ("", pref_value); | ||
} | ||
|
||
TEST(ContextualSearchPolicyHandlerAndroidTest, Enabled) { | ||
PolicyMap policy; | ||
policy.Set(key::kContextualSearchEnabled, | ||
POLICY_LEVEL_MANDATORY, | ||
POLICY_SCOPE_USER, | ||
new base::FundamentalValue(true), | ||
NULL); | ||
PrefValueMap prefs; | ||
ContextualSearchPolicyHandlerAndroid handler; | ||
handler.ApplyPolicySettings(policy, &prefs); | ||
|
||
// Enabling Contextual Search policy should not set the pref. | ||
std::string pref_value; | ||
EXPECT_FALSE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); | ||
EXPECT_EQ("", pref_value); | ||
} | ||
|
||
TEST(ContextualSearchPolicyHandlerAndroidTest, Disabled) { | ||
PolicyMap policy; | ||
policy.Set(key::kContextualSearchEnabled, | ||
POLICY_LEVEL_MANDATORY, | ||
POLICY_SCOPE_USER, | ||
new base::FundamentalValue(false), | ||
NULL); | ||
PrefValueMap prefs; | ||
ContextualSearchPolicyHandlerAndroid handler; | ||
handler.ApplyPolicySettings(policy, &prefs); | ||
|
||
// Disabling Contextual Search should switch the pref to managed. | ||
std::string pref_value; | ||
EXPECT_TRUE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); | ||
EXPECT_EQ("false", pref_value); | ||
} | ||
|
||
} // namespace policy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters