-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync: Consistently handle kSavingBrowserHistoryDisabled in controllers
The pref/policy kSavingBrowserHistoryDisabled should cause all history-related sync data types to get disabled. The relevant data types are: Sessions, TypedUrls, HistoryDeleteDirectives, and ProxyTabs. This CL is mostly a cleanup/simplification, but there are behavior changes in some (edge) cases: The policy being changed will now consistently apply at runtime, whereas before, in some cases it only applied after a browser restart. Before this CL, the policy implementations for those 4 data types were inconsistent: Sessions and TypedUrls watched for changes to the pref, and turned themselves off - but Sessions with kMustStopAndKeepData and TypedUrls with kMustStopAndClearData. The other two controllers didn't watch the pref at all. Additionally, SyncApiComponentFactoryImpl didn't even instantiate the controllers if the pref was already set during startup - which means that history sync could never get re-enabled during runtime. This CL makes the behavior consistent across all 4 data types: Watch the pref, and use kMustStopAndClearData. The logic in SyncApiComponentFactoryImpl is not needed anymore and is removed. Bug: 1303833 Change-Id: I65fe584745d15db12702afc46fba8f08b6de7c23 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3620600 Commit-Queue: Marc Treib <treib@chromium.org> Reviewed-by: Tommy Li <tommycli@chromium.org> Reviewed-by: Mikel Astiz <mastiz@chromium.org> Cr-Commit-Position: refs/heads/main@{#1001368}
- Loading branch information
Marc Treib
authored and
Chromium LUCI CQ
committed
May 10, 2022
1 parent
07d2270
commit 4221c27
Showing
14 changed files
with
192 additions
and
127 deletions.
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
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
44 changes: 44 additions & 0 deletions
44
components/history/core/browser/sync/history_model_type_controller_helper.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,44 @@ | ||
// Copyright 2022 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 "components/history/core/browser/sync/history_model_type_controller_helper.h" | ||
|
||
#include "base/bind.h" | ||
#include "components/history/core/common/pref_names.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "components/sync/driver/sync_service.h" | ||
|
||
namespace history { | ||
|
||
HistoryModelTypeControllerHelper::HistoryModelTypeControllerHelper( | ||
syncer::ModelType model_type, | ||
syncer::SyncService* sync_service, | ||
PrefService* pref_service) | ||
: model_type_(model_type), | ||
sync_service_(sync_service), | ||
pref_service_(pref_service) { | ||
pref_registrar_.Init(pref_service_); | ||
// base::Unretained() is safe because `pref_registar_` is owned by `this`. | ||
pref_registrar_.Add( | ||
prefs::kSavingBrowserHistoryDisabled, | ||
base::BindRepeating(&HistoryModelTypeControllerHelper:: | ||
OnSavingBrowserHistoryDisabledChanged, | ||
base::Unretained(this))); | ||
} | ||
|
||
HistoryModelTypeControllerHelper::~HistoryModelTypeControllerHelper() = default; | ||
|
||
syncer::DataTypeController::PreconditionState | ||
HistoryModelTypeControllerHelper::GetPreconditionState() const { | ||
return pref_service_->GetBoolean(prefs::kSavingBrowserHistoryDisabled) | ||
? syncer::DataTypeController::PreconditionState:: | ||
kMustStopAndClearData | ||
: syncer::DataTypeController::PreconditionState::kPreconditionsMet; | ||
} | ||
|
||
void HistoryModelTypeControllerHelper::OnSavingBrowserHistoryDisabledChanged() { | ||
sync_service_->DataTypePreconditionChanged(model_type_); | ||
} | ||
|
||
} // namespace history |
53 changes: 53 additions & 0 deletions
53
components/history/core/browser/sync/history_model_type_controller_helper.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,53 @@ | ||
// Copyright 2022 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 COMPONENTS_HISTORY_CORE_BROWSER_SYNC_HISTORY_MODEL_TYPE_CONTROLLER_HELPER_H_ | ||
#define COMPONENTS_HISTORY_CORE_BROWSER_SYNC_HISTORY_MODEL_TYPE_CONTROLLER_HELPER_H_ | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "components/prefs/pref_change_registrar.h" | ||
#include "components/sync/base/model_type.h" | ||
#include "components/sync/driver/data_type_controller.h" | ||
|
||
class PrefService; | ||
|
||
namespace syncer { | ||
class SyncService; | ||
} // namespace syncer | ||
|
||
namespace history { | ||
|
||
// Helper class for implementing history-related ModelTypeControllers. It | ||
// implements the pref/policy kSavingBrowserHistoryDisabled: It calls | ||
// SyncService::DataTypePreconditionChanged() when the pref changes. | ||
// DataTypeControllers using this helper must call its GetPreconditionState(). | ||
class HistoryModelTypeControllerHelper { | ||
public: | ||
HistoryModelTypeControllerHelper(syncer::ModelType model_type, | ||
syncer::SyncService* sync_service, | ||
PrefService* pref_service); | ||
|
||
HistoryModelTypeControllerHelper(const HistoryModelTypeControllerHelper&) = | ||
delete; | ||
HistoryModelTypeControllerHelper& operator=( | ||
const HistoryModelTypeControllerHelper&) = delete; | ||
|
||
~HistoryModelTypeControllerHelper(); | ||
|
||
// Must be called from DataTypeController::GetPreconditionState(). | ||
syncer::DataTypeController::PreconditionState GetPreconditionState() const; | ||
|
||
private: | ||
void OnSavingBrowserHistoryDisabledChanged(); | ||
|
||
const syncer::ModelType model_type_; | ||
const raw_ptr<syncer::SyncService> sync_service_; | ||
const raw_ptr<PrefService> pref_service_; | ||
|
||
PrefChangeRegistrar pref_registrar_; | ||
}; | ||
|
||
} // namespace history | ||
|
||
#endif // COMPONENTS_HISTORY_CORE_BROWSER_SYNC_HISTORY_MODEL_TYPE_CONTROLLER_HELPER_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
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
Oops, something went wrong.