Commit 2298d0da authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Reset OTR prefs when creating a new OTR Browser state

Before, the OTR prefs were stored in chrome_browser_state_impl, so even
after destroying the OTR state (when closing the last tab), a new OTR
state would use the same prefs. Thus, the prefs would only reset after a
cold start of the app.

After, each new OTR browser state creates a new prefs (based off of the
existing CBS prefs). The net affect of this is that incognito prefs are
reset every time the OTR state is destroyed instead of only every cold
start.

Bug: 1067412
Change-Id: I0a11f2d83bf7cf1d939bacbafa15b96cb63ee5cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135754Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#757003}
parent a738266c
......@@ -200,11 +200,10 @@ void ChromeBrowserStateImpl::SetOffTheRecordChromeBrowserState(
}
PrefService* ChromeBrowserStateImpl::GetOffTheRecordPrefs() {
DCHECK(prefs_);
if (!otr_prefs_) {
otr_prefs_ = CreateIncognitoBrowserStatePrefs(prefs_.get());
if (otr_state_) {
return otr_state_->GetPrefs();
}
return otr_prefs_.get();
return nullptr;
}
ChromeBrowserStateIOData* ChromeBrowserStateImpl::GetIOData() {
......
......@@ -85,7 +85,6 @@ class ChromeBrowserStateImpl : public ChromeBrowserState {
// others store pointers to |prefs_| and shall be destructed first.
scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_;
std::unique_ptr<sync_preferences::PrefServiceSyncable> otr_prefs_;
std::unique_ptr<ChromeBrowserStateImplIOData::Handle> io_data_;
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
......
......@@ -14,6 +14,7 @@
#include "components/user_prefs/user_prefs.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h"
#include "ios/chrome/browser/prefs/ios_chrome_pref_service_factory.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
......@@ -24,8 +25,9 @@ OffTheRecordChromeBrowserStateImpl::OffTheRecordChromeBrowserStateImpl(
: ChromeBrowserState(std::move(io_task_runner)),
otr_state_path_(otr_path),
original_chrome_browser_state_(original_chrome_browser_state),
prefs_(static_cast<sync_preferences::PrefServiceSyncable*>(
original_chrome_browser_state->GetOffTheRecordPrefs())) {
prefs_(CreateIncognitoBrowserStatePrefs(
static_cast<sync_preferences::PrefServiceSyncable*>(
original_chrome_browser_state->GetPrefs()))) {
user_prefs::UserPrefs::Set(this, GetPrefs());
io_data_.reset(new OffTheRecordChromeBrowserStateIOData::Handle(this));
BrowserStateDependencyManager::GetInstance()->CreateBrowserStateServices(
......@@ -70,7 +72,7 @@ OffTheRecordChromeBrowserStateImpl::GetPolicyConnector() {
}
PrefService* OffTheRecordChromeBrowserStateImpl::GetPrefs() {
return prefs_;
return prefs_.get();
}
PrefService* OffTheRecordChromeBrowserStateImpl::GetOffTheRecordPrefs() {
......
......@@ -52,8 +52,7 @@ class OffTheRecordChromeBrowserStateImpl : public ChromeBrowserState {
base::FilePath otr_state_path_;
ChromeBrowserState* original_chrome_browser_state_; // weak
// Weak pointer owned by |original_chrome_browser_state_|.
sync_preferences::PrefServiceSyncable* prefs_;
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_;
std::unique_ptr<OffTheRecordChromeBrowserStateIOData::Handle> io_data_;
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
......
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