Skip to content

Commit

Permalink
Clear incognito preferences on destroying incognito profile.
Browse files Browse the repository at this point in the history
Tests are not added, since it's not final version yet.

BUG=444283

Review URL: https://codereview.chromium.org/1643203002

Cr-Commit-Position: refs/heads/master@{#373804}
  • Loading branch information
dvadym authored and Commit bot committed Feb 5, 2016
1 parent 91a967c commit 53fc0d4
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions android_webview/browser/aw_pref_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AwPrefStore : public PersistentPrefStore {
void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override;
void CommitPendingWrite() override {}
void SchedulePendingLossyWrites() override {}
void ClearMutableValues() override {}

protected:
~AwPrefStore() override;
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/profiles/profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ Profile* ProfileImpl::GetOffTheRecordProfile() {

void ProfileImpl::DestroyOffTheRecordProfile() {
off_the_record_profile_.reset();
otr_prefs_->ClearMutableValues();
#if defined(ENABLE_EXTENSIONS)
ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
ClearAllIncognitoSessionOnlyPreferences();
Expand Down
17 changes: 17 additions & 0 deletions chrome/browser/profiles/profile_manager_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,27 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) {
ASSERT_TRUE(profile_manager->IsValidProfile(incognito_profile));
EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());

// Check that a default save path is not empty, since it's taken from the
// main profile preferences, set it to empty and verify that it becomes
// empty.
EXPECT_FALSE(profile->GetOffTheRecordPrefs()
->GetFilePath(prefs::kSaveFileDefaultDirectory)
.empty());
profile->GetOffTheRecordPrefs()->SetFilePath(prefs::kSaveFileDefaultDirectory,
base::FilePath());
EXPECT_TRUE(profile->GetOffTheRecordPrefs()
->GetFilePath(prefs::kSaveFileDefaultDirectory)
.empty());

// Delete the incognito profile.
incognito_profile->GetOriginalProfile()->DestroyOffTheRecordProfile();

EXPECT_FALSE(profile->HasOffTheRecordProfile());
EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile));
EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());
// After destroying the incognito profile incognito preferences should be
// cleared so the default save path should be taken from the main profile.
EXPECT_FALSE(profile->GetOffTheRecordPrefs()
->GetFilePath(prefs::kSaveFileDefaultDirectory)
.empty());
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ void FilesystemJsonPrefStore::RemoveValueSilently(const std::string& key,
ScheduleWrite(flags);
}

void FilesystemJsonPrefStore::ClearMutableValues() {
NOTIMPLEMENTED();
}

bool FilesystemJsonPrefStore::ReadOnly() const {
DCHECK(CalledOnValidThread());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class FilesystemJsonPrefStore
// cleanup that shouldn't otherwise alert observers.
void RemoveValueSilently(const std::string& key, uint32_t flags);

void ClearMutableValues() override;

private:
friend class base::JsonPrefStoreLossyWriteTest;

Expand Down
4 changes: 4 additions & 0 deletions components/prefs/json_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ void JsonPrefStore::RegisterOnNextSuccessfulWriteCallback(
writer_.RegisterOnNextSuccessfulWriteCallback(on_next_successful_write);
}

void JsonPrefStore::ClearMutableValues() {
NOTIMPLEMENTED();
}

void JsonPrefStore::OnFileRead(scoped_ptr<ReadResult> read_result) {
DCHECK(CalledOnValidThread());

Expand Down
2 changes: 2 additions & 0 deletions components/prefs/json_pref_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
void RegisterOnNextSuccessfulWriteCallback(
const base::Closure& on_next_successful_write);

void ClearMutableValues() override;

private:
// Represents a histogram for recording the number of writes to the pref file
// that occur every kHistogramWriteReportIntervalInMins minutes.
Expand Down
4 changes: 4 additions & 0 deletions components/prefs/overlay_user_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ void OverlayUserPrefStore::RegisterOverlayPref(
underlay_to_overlay_names_map_[underlay_key] = overlay_key;
}

void OverlayUserPrefStore::ClearMutableValues() {
overlay_.Clear();
}

OverlayUserPrefStore::~OverlayUserPrefStore() {
underlay_->RemoveObserver(this);
}
Expand Down
2 changes: 2 additions & 0 deletions components/prefs/overlay_user_pref_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class COMPONENTS_PREFS_EXPORT OverlayUserPrefStore : public PersistentPrefStore,
void RegisterOverlayPref(const std::string& overlay_key,
const std::string& underlay_key);

void ClearMutableValues() override;

protected:
~OverlayUserPrefStore() override;

Expand Down
19 changes: 19 additions & 0 deletions components/prefs/overlay_user_pref_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,23 @@ TEST_F(OverlayUserPrefStoreTest, NamesMapping) {
EXPECT_TRUE(obs.changed_keys.empty());
}

// Check that mutable values are removed correctly.
TEST_F(OverlayUserPrefStoreTest, ClearMutableValues) {
// Set in overlay and underlay the same preference.
underlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(42)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
overlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(43)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);

const Value* value = nullptr;
// Check that an overlay preference is returned.
EXPECT_TRUE(overlay_->GetValue(overlay_key, &value));
EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
overlay_->ClearMutableValues();

// Check that an underlay preference is returned.
EXPECT_TRUE(overlay_->GetValue(overlay_key, &value));
EXPECT_TRUE(base::FundamentalValue(42).Equals(value));
}

} // namespace base
3 changes: 3 additions & 0 deletions components/prefs/persistent_pref_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class COMPONENTS_PREFS_EXPORT PersistentPrefStore : public WriteablePrefStore {
// isn't one scheduled already.
virtual void SchedulePendingLossyWrites() = 0;

// It should be called only for Incognito pref store.
virtual void ClearMutableValues() = 0;

protected:
~PersistentPrefStore() override {}
};
Expand Down
4 changes: 4 additions & 0 deletions components/prefs/pref_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ void PrefService::ClearPref(const std::string& path) {
user_pref_store_->RemoveValue(path, GetWriteFlags(pref));
}

void PrefService::ClearMutableValues() {
user_pref_store_->ClearMutableValues();
}

void PrefService::Set(const std::string& path, const base::Value& value) {
SetUserPrefValue(path, value.DeepCopy());
}
Expand Down
3 changes: 3 additions & 0 deletions components/prefs/pref_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ class COMPONENTS_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// implemented in chrome/browser/prefs/browser_prefs.cc.
PrefRegistry* DeprecatedGetPrefRegistry();

// Clears mutable values.
void ClearMutableValues();

protected:
// The PrefNotifier handles registering and notifying preference observers.
// It is created and owned by this PrefService. Subclasses may access it for
Expand Down
4 changes: 4 additions & 0 deletions components/prefs/testing_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ void TestingPrefStore::SetBlockAsyncRead(bool block_async_read) {
NotifyInitializationCompleted();
}

void TestingPrefStore::ClearMutableValues() {
NOTIMPLEMENTED();
}

void TestingPrefStore::set_read_only(bool read_only) {
read_only_ = read_only;
}
Expand Down
2 changes: 2 additions & 0 deletions components/prefs/testing_pref_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class TestingPrefStore : public PersistentPrefStore {
// the call to ReadPrefsAsync.
void SetBlockAsyncRead(bool block_async_read);

void ClearMutableValues() override;

// Getter and Setter methods for setting and getting the state of the
// |TestingPrefStore|.
virtual void set_read_only(bool read_only);
Expand Down
4 changes: 4 additions & 0 deletions components/user_prefs/tracked/segregated_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ void SegregatedPrefStore::SchedulePendingLossyWrites() {
selected_pref_store_->SchedulePendingLossyWrites();
}

void SegregatedPrefStore::ClearMutableValues() {
NOTIMPLEMENTED();
}

SegregatedPrefStore::~SegregatedPrefStore() {
default_pref_store_->RemoveObserver(&aggregating_observer_);
selected_pref_store_->RemoveObserver(&aggregating_observer_);
Expand Down
2 changes: 2 additions & 0 deletions components/user_prefs/tracked/segregated_pref_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class SegregatedPrefStore : public PersistentPrefStore {
void CommitPendingWrite() override;
void SchedulePendingLossyWrites() override;

void ClearMutableValues() override;

private:
// Aggregates events from the underlying stores and synthesizes external
// events via |on_initialization|, |read_error_delegate_|, and |observers_|.
Expand Down

0 comments on commit 53fc0d4

Please sign in to comment.