summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-01 12:31:34 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-01 12:31:34 +0000
commite19cf1e973a77089f45935fc3f960aba91890373 (patch)
tree8b1e8ecb09278b5ae708d246685a852dc62dfb6f /chrome/browser
parente87d0813680968941a8be73cc0a22881237fdbce (diff)
downloadchromium_src-e19cf1e973a77089f45935fc3f960aba91890373.zip
chromium_src-e19cf1e973a77089f45935fc3f960aba91890373.tar.gz
chromium_src-e19cf1e973a77089f45935fc3f960aba91890373.tar.bz2
Implement policy for enabling/disabling browsing history.
BUG=none TEST=none Review URL: http://codereview.chromium.org/3432033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61169 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/autocomplete_browsertest.cc9
-rw-r--r--chrome/browser/history/history_browsertest.cc210
-rw-r--r--chrome/browser/options_util.cc1
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc4
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store_unittest.cc5
-rw-r--r--chrome/browser/policy/configuration_policy_store.h1
-rw-r--r--chrome/browser/prefs/browser_prefs.cc2
-rw-r--r--chrome/browser/profile_impl.cc10
-rw-r--r--chrome/browser/profile_impl.h4
9 files changed, 237 insertions, 9 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc
index 5ef296b..744db3e 100644
--- a/chrome/browser/autocomplete/autocomplete_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc
@@ -64,13 +64,6 @@ class AutocompleteBrowserTest : public InProcessBrowserTest {
return GetLocationBar()->location_entry()->model()->popup_model()->
autocomplete_controller();
}
-
- void WaitForHistoryBackendToLoad() {
- HistoryService* history_service =
- browser()->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- if (!history_service->BackendLoaded())
- ui_test_utils::WaitForNotification(NotificationType::HISTORY_LOADED);
- }
};
IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Basic) {
@@ -114,7 +107,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Basic) {
IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) {
// The results depend on the history backend being loaded. Make sure it is
// loaded so that the autocomplete results are consistent.
- WaitForHistoryBackendToLoad();
+ ui_test_utils::WaitForHistoryToLoad(browser());
LocationBar* location_bar = GetLocationBar();
AutocompleteController* autocomplete_controller = GetAutocompleteController();
diff --git a/chrome/browser/history/history_browsertest.cc b/chrome/browser/history/history_browsertest.cc
new file mode 100644
index 0000000..72ddc9d
--- /dev/null
+++ b/chrome/browser/history/history_browsertest.cc
@@ -0,0 +1,210 @@
+// Copyright (c) 2010 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 <vector>
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/history/history.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "googleurl/src/gurl.h"
+
+namespace {
+
+// Note: WaitableEvent is not used for synchronization between the main thread
+// and history backend thread because the history subsystem posts tasks back
+// to the main thread. Had we tried to Signal an event in such a task
+// and Wait for it on the main thread, the task would not run at all because
+// the main thread would be blocked on the Wait call, resulting in a deadlock.
+
+// A task to be scheduled on the history backend thread.
+// Notifies the main thread after all history backend thread tasks have run.
+class WaitForHistoryTask : public HistoryDBTask {
+ public:
+ WaitForHistoryTask() {
+ }
+
+ virtual bool RunOnDBThread(history::HistoryBackend* backend,
+ history::HistoryDatabase* db) {
+ return true;
+ }
+
+ virtual void DoneRunOnMainThread() {
+ MessageLoop::current()->Quit();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask);
+};
+
+// Enumerates all history contents on the backend thread.
+class HistoryEnumerator : public HistoryService::URLEnumerator {
+ public:
+ explicit HistoryEnumerator(HistoryService* history) {
+ EXPECT_TRUE(history);
+ if (!history)
+ return;
+
+ ChromeThread::PostTask(
+ ChromeThread::UI,
+ FROM_HERE,
+ NewRunnableMethod(history, &HistoryService::IterateURLs, this));
+ ui_test_utils::RunMessageLoop();
+ }
+
+ virtual void OnURL(const GURL& url) {
+ urls_.push_back(url);
+ }
+
+ virtual void OnComplete(bool success) {
+ ChromeThread::PostTask(
+ ChromeThread::UI,
+ FROM_HERE,
+ new MessageLoop::QuitTask());
+ }
+
+ std::vector<GURL>& urls() { return urls_; }
+
+ private:
+ std::vector<GURL> urls_;
+
+ DISALLOW_COPY_AND_ASSIGN(HistoryEnumerator);
+};
+
+class HistoryBrowserTest : public InProcessBrowserTest {
+ protected:
+ PrefService* GetPrefs() {
+ return GetProfile()->GetPrefs();
+ }
+
+ Profile* GetProfile() {
+ return browser()->GetProfile();
+ }
+
+ HistoryService* GetHistoryService() {
+ return GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ }
+
+ std::vector<GURL> GetHistoryContents() {
+ HistoryEnumerator enumerator(GetHistoryService());
+ return enumerator.urls();
+ }
+
+ GURL GetTestUrl() {
+ return ui_test_utils::GetTestUrl(
+ FilePath(FilePath::kCurrentDirectory),
+ FilePath(FILE_PATH_LITERAL("title2.html")));
+ }
+
+ void WaitForHistoryBackendToRun() {
+ CancelableRequestConsumerTSimple<int> request_consumer;
+ scoped_refptr<HistoryDBTask> task(new WaitForHistoryTask());
+ HistoryService* history = GetHistoryService();
+ ChromeThread::PostTask(ChromeThread::UI,
+ FROM_HERE,
+ NewRunnableMethod(history,
+ &HistoryService::ScheduleDBTask,
+ task.get(),
+ &request_consumer));
+ ui_test_utils::RunMessageLoop();
+ }
+
+ void ExpectEmptyHistory() {
+ std::vector<GURL> urls(GetHistoryContents());
+ EXPECT_EQ(0U, urls.size());
+ }
+};
+
+// Test that the browser history is saved (default setting).
+IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabled) {
+ EXPECT_FALSE(GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled));
+
+ EXPECT_TRUE(GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS));
+ EXPECT_TRUE(GetProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS));
+
+ ui_test_utils::WaitForHistoryToLoad(browser());
+ ExpectEmptyHistory();
+
+ ui_test_utils::NavigateToURL(browser(), GetTestUrl());
+ WaitForHistoryBackendToRun();
+
+ {
+ std::vector<GURL> urls(GetHistoryContents());
+ ASSERT_EQ(1U, urls.size());
+ EXPECT_EQ(GetTestUrl().spec(), urls[0].spec());
+ }
+}
+
+// Test that disabling saving browser history really works.
+IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryDisabled) {
+ GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, true);
+
+ EXPECT_TRUE(GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS));
+ EXPECT_FALSE(GetProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS));
+
+ ui_test_utils::WaitForHistoryToLoad(browser());
+ ExpectEmptyHistory();
+
+ ui_test_utils::NavigateToURL(browser(), GetTestUrl());
+ WaitForHistoryBackendToRun();
+ ExpectEmptyHistory();
+}
+
+// Test that changing the pref takes effect immediately
+// when the browser is running.
+IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabledThenDisabled) {
+ EXPECT_FALSE(GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled));
+
+ ui_test_utils::WaitForHistoryToLoad(browser());
+
+ ui_test_utils::NavigateToURL(browser(), GetTestUrl());
+ WaitForHistoryBackendToRun();
+
+ {
+ std::vector<GURL> urls(GetHistoryContents());
+ ASSERT_EQ(1U, urls.size());
+ EXPECT_EQ(GetTestUrl().spec(), urls[0].spec());
+ }
+
+ GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, true);
+
+ ui_test_utils::NavigateToURL(browser(), GetTestUrl());
+ WaitForHistoryBackendToRun();
+
+ {
+ // No additional entries should be present in the history.
+ std::vector<GURL> urls(GetHistoryContents());
+ ASSERT_EQ(1U, urls.size());
+ EXPECT_EQ(GetTestUrl().spec(), urls[0].spec());
+ }
+}
+
+// Test that changing the pref takes effect immediately
+// when the browser is running.
+IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryDisabledThenEnabled) {
+ GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, true);
+
+ ui_test_utils::WaitForHistoryToLoad(browser());
+ ExpectEmptyHistory();
+
+ ui_test_utils::NavigateToURL(browser(), GetTestUrl());
+ WaitForHistoryBackendToRun();
+ ExpectEmptyHistory();
+
+ GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, false);
+
+ ui_test_utils::NavigateToURL(browser(), GetTestUrl());
+ WaitForHistoryBackendToRun();
+
+ {
+ std::vector<GURL> urls(GetHistoryContents());
+ ASSERT_EQ(1U, urls.size());
+ EXPECT_EQ(GetTestUrl().spec(), urls[0].spec());
+ }
+}
+
+} // namespace
diff --git a/chrome/browser/options_util.cc b/chrome/browser/options_util.cc
index 97f00120..659c8b9 100644
--- a/chrome/browser/options_util.cc
+++ b/chrome/browser/options_util.cc
@@ -43,6 +43,7 @@ void OptionsUtil::ResetToDefaults(Profile* profile) {
#endif
prefs::kDownloadDefaultDirectory,
prefs::kDownloadExtensionsToOpen,
+ prefs::kSavingBrowserHistoryDisabled,
prefs::kEnableSpellCheck,
prefs::kEnableTranslate,
prefs::kAutoFillEnabled,
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index dde144b..703731a 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -128,6 +128,8 @@ const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry
prefs::kShowHomeButton },
{ Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled,
prefs::kWebKitJavascriptEnabled },
+ { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled,
+ prefs::kSavingBrowserHistoryDisabled },
};
const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry
@@ -217,6 +219,8 @@ ConfigurationPolicyPrefStore::GetChromePolicyValueMap() {
Value::TYPE_BOOLEAN, key::kPrintingEnabled },
{ ConfigurationPolicyStore::kPolicyJavascriptEnabled,
Value::TYPE_BOOLEAN, key::kJavascriptEnabled },
+ { ConfigurationPolicyStore::kPolicySavingBrowserHistoryDisabled,
+ Value::TYPE_BOOLEAN, key::kSavingBrowserHistoryDisabled },
};
ConfigurationPolicyProvider::StaticPolicyValueMap map = {
diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
index 6b1bbe5..659e35d 100644
--- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
@@ -159,7 +159,10 @@ INSTANTIATE_TEST_CASE_P(
TypeAndName(ConfigurationPolicyStore::kPolicyPrintingEnabled,
prefs::kPrintingEnabled),
TypeAndName(ConfigurationPolicyStore::kPolicyJavascriptEnabled,
- prefs::kWebKitJavascriptEnabled)));
+ prefs::kWebKitJavascriptEnabled),
+ TypeAndName(ConfigurationPolicyStore::
+ kPolicySavingBrowserHistoryDisabled,
+ prefs::kSavingBrowserHistoryDisabled)));
// Test cases for integer-valued policy settings.
class ConfigurationPolicyPrefStoreIntegerTest
diff --git a/chrome/browser/policy/configuration_policy_store.h b/chrome/browser/policy/configuration_policy_store.h
index dacfa37..2b5cbb2 100644
--- a/chrome/browser/policy/configuration_policy_store.h
+++ b/chrome/browser/policy/configuration_policy_store.h
@@ -53,6 +53,7 @@ class ConfigurationPolicyStore {
kPolicyRenderInChromeFrameList,
kPolicyRenderInHostList,
kPolicyJavascriptEnabled,
+ kPolicySavingBrowserHistoryDisabled,
};
static const int kPolicyNoProxyServerMode = 0;
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index c737a63..03d18f4 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -35,6 +35,7 @@
#include "chrome/browser/page_info_model.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/prefs/session_startup_pref.h"
+#include "chrome/browser/profile_impl.h"
#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/renderer_host/web_cache_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
@@ -121,6 +122,7 @@ void RegisterUserPrefs(PrefService* user_prefs) {
LabsUI::RegisterUserPrefs(user_prefs);
NewTabUI::RegisterUserPrefs(user_prefs);
PluginsUI::RegisterUserPrefs(user_prefs);
+ ProfileImpl::RegisterUserPrefs(user_prefs);
HostContentSettingsMap::RegisterUserPrefs(user_prefs);
HostZoomMap::RegisterUserPrefs(user_prefs);
DevToolsManager::RegisterUserPrefs(user_prefs);
diff --git a/chrome/browser/profile_impl.cc b/chrome/browser/profile_impl.cc
index 8e541fb..e0087f8 100644
--- a/chrome/browser/profile_impl.cc
+++ b/chrome/browser/profile_impl.cc
@@ -235,6 +235,11 @@ Profile* Profile::CreateProfile(const FilePath& path) {
return new ProfileImpl(path);
}
+// static
+void ProfileImpl::RegisterUserPrefs(PrefService* prefs) {
+ prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, false);
+}
+
ProfileImpl::ProfileImpl(const FilePath& path)
: path_(path),
visited_link_event_listener_(new VisitedLinkEventListener()),
@@ -801,6 +806,11 @@ FindBarState* ProfileImpl::GetFindBarState() {
}
HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
+ // If saving history is disabled, only allow explicit access.
+ if (GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) &&
+ sat != EXPLICIT_ACCESS)
+ return NULL;
+
if (!history_service_created_) {
history_service_created_ = true;
scoped_refptr<HistoryService> history(new HistoryService(this));
diff --git a/chrome/browser/profile_impl.h b/chrome/browser/profile_impl.h
index 0bf1b56..c7b60d0 100644
--- a/chrome/browser/profile_impl.h
+++ b/chrome/browser/profile_impl.h
@@ -18,6 +18,8 @@
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
+class PrefService;
+
#if defined(OS_CHROMEOS)
namespace chromeos {
class Preferences;
@@ -31,6 +33,8 @@ class ProfileImpl : public Profile,
public:
virtual ~ProfileImpl();
+ static void RegisterUserPrefs(PrefService* prefs);
+
// Profile implementation.
virtual ProfileId GetRuntimeId();
virtual FilePath GetPath();