blob: 2d3fb1ddeb51a90c8f830953713815b3db2206d4 [file] [log] [blame]
Marc Treibc18387c52018-11-12 12:28:061// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/browser_sync/sync_user_settings_impl.h"
6
7#include "components/browser_sync/profile_sync_service.h"
8#include "components/sync/base/model_type.h"
9#include "components/sync/base/sync_prefs.h"
10
11namespace browser_sync {
12
13SyncUserSettingsImpl::SyncUserSettingsImpl(ProfileSyncService* service,
14 syncer::SyncPrefs* prefs)
15 : service_(service), prefs_(prefs) {}
16
17SyncUserSettingsImpl::~SyncUserSettingsImpl() = default;
18
19bool SyncUserSettingsImpl::IsSyncRequested() const {
20 // TODO(crbug.com/884159): Query prefs directly.
21 return !service_->HasDisableReason(
22 syncer::SyncService::DISABLE_REASON_USER_CHOICE);
23}
24
25void SyncUserSettingsImpl::SetSyncRequested(bool requested) {
26 // TODO(crbug.com/884159): Write to prefs directly.
27 if (requested) {
28 service_->RequestStart();
29 } else {
Marc Treib896c4172018-12-05 08:19:2730 service_->RequestStop(ProfileSyncService::KEEP_DATA);
Marc Treibc18387c52018-11-12 12:28:0631 }
32}
33
34bool SyncUserSettingsImpl::IsSyncAllowedByPlatform() const {
35 return sync_allowed_by_platform_;
36}
37
38void SyncUserSettingsImpl::SetSyncAllowedByPlatform(bool allowed) {
39 if (sync_allowed_by_platform_ == allowed) {
40 return;
41 }
42
43 sync_allowed_by_platform_ = allowed;
44
45 service_->SyncAllowedByPlatformChanged(sync_allowed_by_platform_);
46}
47
48bool SyncUserSettingsImpl::IsFirstSetupComplete() const {
49 // TODO(crbug.com/884159): Query prefs directly.
50 return service_->IsFirstSetupComplete();
51}
52
53void SyncUserSettingsImpl::SetFirstSetupComplete() {
54 // TODO(crbug.com/884159): Write to prefs directly.
55 service_->SetFirstSetupComplete();
56}
57
58bool SyncUserSettingsImpl::IsSyncEverythingEnabled() const {
59 return prefs_->HasKeepEverythingSynced();
60}
61
62syncer::ModelTypeSet SyncUserSettingsImpl::GetChosenDataTypes() const {
63 syncer::ModelTypeSet types = service_->GetPreferredDataTypes();
64 types.RetainAll(syncer::UserSelectableTypes());
65 return types;
66}
67
68void SyncUserSettingsImpl::SetChosenDataTypes(bool sync_everything,
69 syncer::ModelTypeSet types) {
70 // TODO(crbug.com/884159): Write to prefs directly (might be tricky because it
Thomas Tanglb0dc23d2018-11-19 13:30:4571 // needs the registered types).
Marc Treibc18387c52018-11-12 12:28:0672 service_->OnUserChoseDatatypes(sync_everything, types);
73}
74
75bool SyncUserSettingsImpl::IsEncryptEverythingAllowed() const {
76 // TODO(crbug.com/884159): Use SyncServiceCrypto.
77 // Note: This requires *Profile*SyncService.
78 return service_->IsEncryptEverythingAllowed();
79}
80
81void SyncUserSettingsImpl::SetEncryptEverythingAllowed(bool allowed) {
82 // TODO(crbug.com/884159): Use SyncServiceCrypto.
83 // Note: This requires *Profile*SyncService.
84 service_->SetEncryptEverythingAllowed(allowed);
85}
86
87bool SyncUserSettingsImpl::IsEncryptEverythingEnabled() const {
88 // TODO(crbug.com/884159): Use SyncServiceCrypto.
89 return service_->IsEncryptEverythingEnabled();
90}
91
92void SyncUserSettingsImpl::EnableEncryptEverything() {
93 // TODO(crbug.com/884159): Use SyncServiceCrypto.
94 service_->EnableEncryptEverything();
95}
96
97bool SyncUserSettingsImpl::IsPassphraseRequired() const {
98 // TODO(crbug.com/884159): Use SyncServiceCrypto.
99 return service_->IsPassphraseRequired();
100}
101
102bool SyncUserSettingsImpl::IsPassphraseRequiredForDecryption() const {
103 // TODO(crbug.com/884159): Use SyncServiceCrypto.
104 return service_->IsPassphraseRequiredForDecryption();
105}
106
107bool SyncUserSettingsImpl::IsUsingSecondaryPassphrase() const {
108 // TODO(crbug.com/884159): Use SyncServiceCrypto.
109 return service_->IsUsingSecondaryPassphrase();
110}
111
112base::Time SyncUserSettingsImpl::GetExplicitPassphraseTime() const {
113 // TODO(crbug.com/884159): Use SyncServiceCrypto.
114 return service_->GetExplicitPassphraseTime();
115}
116
117syncer::PassphraseType SyncUserSettingsImpl::GetPassphraseType() const {
118 // TODO(crbug.com/884159): Use SyncServiceCrypto.
119 // Note: This requires *Profile*SyncService.
120 return service_->GetPassphraseType();
121}
122
123void SyncUserSettingsImpl::SetEncryptionPassphrase(
124 const std::string& passphrase) {
125 // TODO(crbug.com/884159): Use SyncServiceCrypto.
126 service_->SetEncryptionPassphrase(passphrase);
127}
128
129bool SyncUserSettingsImpl::SetDecryptionPassphrase(
130 const std::string& passphrase) {
131 // TODO(crbug.com/884159): Use SyncServiceCrypto.
132 return service_->SetDecryptionPassphrase(passphrase);
133}
134
135} // namespace browser_sync