Skip to content

Commit

Permalink
[WebLayer] Persist preferences for non-incognito profiles
Browse files Browse the repository at this point in the history
WebLayer profiles which have a path should persist preferences,
otherwise a user will be prompted for permissions after every restart.

Bug: 1025609
Change-Id: Id4d141f814c61b5e839fb3c859dfa37669b03925
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2111358
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#752161}
  • Loading branch information
clarkduvall authored and Commit Bot committed Mar 20, 2020
1 parent 9ba092b commit fbaae44
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
11 changes: 5 additions & 6 deletions base/threading/thread_restrictions.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class DrmThreadProxy;
class GpuState;
}
namespace weblayer {
class BrowserContextImpl;
class ProfileImpl;
class WebLayerPathProvider;
}
namespace net {
Expand Down Expand Up @@ -276,10 +278,6 @@ class WebMainLoop;
class WebSubThread;
}

namespace weblayer {
class ProfileImpl;
}

namespace webrtc {
class DesktopConfigurationMonitor;
}
Expand Down Expand Up @@ -361,9 +359,11 @@ class BASE_EXPORT ScopedAllowBlocking {
// This can only be instantiated by friends. Use ScopedAllowBlockingForTesting
// in unit tests to avoid the friend requirement.
friend class AdjustOOMScoreHelper;
friend class StackSamplingProfiler;
friend class android_webview::ScopedAllowInitGLBindings;
friend class chromeos::MojoUtils; // http://crbug.com/1055467
friend class content::BrowserProcessSubThread;
friend class content::RenderProcessHostImpl;
friend class content::RenderWidgetHostViewMac; // http://crbug.com/121917
friend class content::WebContentsViewMac;
friend class cronet::CronetPrefsManager;
Expand All @@ -374,9 +374,8 @@ class BASE_EXPORT ScopedAllowBlocking {
friend class printing::PrintJobWorker;
friend class resource_coordinator::TabManagerDelegate; // crbug.com/778703
friend class web::WebSubThread;
friend class StackSamplingProfiler;
friend class weblayer::BrowserContextImpl;
friend class weblayer::ProfileImpl;
friend class content::RenderProcessHostImpl;
friend class weblayer::WebLayerPathProvider;

friend bool PathProviderWin(int, FilePath*);
Expand Down
17 changes: 14 additions & 3 deletions weblayer/browser/browser_context_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

#include "weblayer/browser/browser_context_impl.h"

#include "base/threading/thread_restrictions.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/download/public/common/in_progress_download_manager.h"
#include "components/embedder_support/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/permissions/permission_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/in_memory_pref_store.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_service_factory.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
Expand Down Expand Up @@ -206,9 +208,18 @@ void BrowserContextImpl::CreateUserPrefService() {
RegisterPrefs(pref_registry.get());

PrefServiceFactory pref_service_factory;
pref_service_factory.set_user_prefs(
base::MakeRefCounted<InMemoryPrefStore>());
user_pref_service_ = pref_service_factory.Create(pref_registry);
if (IsOffTheRecord()) {
pref_service_factory.set_user_prefs(
base::MakeRefCounted<InMemoryPrefStore>());
} else {
pref_service_factory.set_user_prefs(base::MakeRefCounted<JsonPrefStore>(
path_.Append(FILE_PATH_LITERAL("Preferences"))));
}
{
// Creating the prefs service may require reading the preferences from disk.
base::ScopedAllowBlocking allow_io;
user_pref_service_ = pref_service_factory.Create(pref_registry);
}
// Note: UserPrefs::Set also ensures that the user_pref_service_ has not
// been set previously.
user_prefs::UserPrefs::Set(this, user_pref_service_.get());
Expand Down
15 changes: 11 additions & 4 deletions weblayer/browser/ssl_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ IN_PROC_BROWSER_TEST_F(SSLBrowserTest, Reload) {
// Tests clicking proceed link on the interstitial page. This is a PRE_ test
// because it also acts as setup for the test below which verifies the behavior
// across restarts.
// TODO(crbug.com/654704): Android does not support PRE_ tests. For Android just
// run only the PRE_ version of this test.
#if defined(OS_ANDROID)
#define PRE_Proceed Proceed
#endif
IN_PROC_BROWSER_TEST_F(SSLBrowserTest, PRE_Proceed) {
NavigateToOkPage();
NavigateToPageWithMismatchedCertExpectSSLInterstitial();
Expand All @@ -257,12 +262,14 @@ IN_PROC_BROWSER_TEST_F(SSLBrowserTest, PRE_Proceed) {
NavigateToPageWithMismatchedCertExpectNotBlocked();
}

// The proceed decision is not perpetuated across WebLayer sessions, i.e.
// WebLayer will block again when navigating to the same bad page that was
// previously proceeded through.
#if !defined(OS_ANDROID)
// The proceed decision is perpetuated across WebLayer sessions, i.e. WebLayer
// will not block again when navigating to the same bad page that was previously
// proceeded through.
IN_PROC_BROWSER_TEST_F(SSLBrowserTest, Proceed) {
NavigateToPageWithMismatchedCertExpectSSLInterstitial();
NavigateToPageWithMismatchedCertExpectNotBlocked();
}
#endif

// Tests navigating away from the interstitial page.
IN_PROC_BROWSER_TEST_F(SSLBrowserTest, NavigateAway) {
Expand Down

0 comments on commit fbaae44

Please sign in to comment.