OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/autofill_wallet_data_type_controller.
h" | 5 #include "components/autofill/core/browser/autofill_wallet_data_type_controller.
h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/autofill/core/browser/personal_data_manager.h" | 8 #include "components/autofill/core/browser/personal_data_manager.h" |
9 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 9 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
10 #include "components/autofill/core/common/autofill_pref_names.h" | 10 #include "components/autofill/core/common/autofill_pref_names.h" |
11 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
12 #include "components/sync/api/sync_error.h" | 12 #include "components/sync/api/sync_error.h" |
13 #include "components/sync/api/syncable_service.h" | 13 #include "components/sync/api/syncable_service.h" |
14 #include "components/sync/driver/sync_client.h" | 14 #include "components/sync/driver/sync_client.h" |
15 #include "components/sync/driver/sync_service.h" | 15 #include "components/sync/driver/sync_service.h" |
16 | 16 |
17 namespace browser_sync { | 17 namespace browser_sync { |
18 | 18 |
19 AutofillWalletDataTypeController::AutofillWalletDataTypeController( | 19 AutofillWalletDataTypeController::AutofillWalletDataTypeController( |
20 syncer::ModelType type, | 20 syncer::ModelType type, |
21 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 21 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
22 const base::Closure& dump_stack, | 22 const base::Closure& dump_stack, |
23 sync_driver::SyncClient* sync_client, | 23 syncer::SyncClient* sync_client, |
24 const scoped_refptr<autofill::AutofillWebDataService>& web_data_service) | 24 const scoped_refptr<autofill::AutofillWebDataService>& web_data_service) |
25 : NonUIDataTypeController(type, dump_stack, sync_client), | 25 : NonUIDataTypeController(type, dump_stack, sync_client), |
26 db_thread_(db_thread), | 26 db_thread_(db_thread), |
27 sync_client_(sync_client), | 27 sync_client_(sync_client), |
28 callback_registered_(false), | 28 callback_registered_(false), |
29 web_data_service_(web_data_service), | 29 web_data_service_(web_data_service), |
30 currently_enabled_(IsEnabled()) { | 30 currently_enabled_(IsEnabled()) { |
31 DCHECK(type == syncer::AUTOFILL_WALLET_DATA || | 31 DCHECK(type == syncer::AUTOFILL_WALLET_DATA || |
32 type == syncer::AUTOFILL_WALLET_METADATA); | 32 type == syncer::AUTOFILL_WALLET_METADATA); |
33 pref_registrar_.Init(sync_client_->GetPrefService()); | 33 pref_registrar_.Init(sync_client_->GetPrefService()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 void AutofillWalletDataTypeController::StopModels() { | 74 void AutofillWalletDataTypeController::StopModels() { |
75 DCHECK(CalledOnValidThread()); | 75 DCHECK(CalledOnValidThread()); |
76 | 76 |
77 // This function is called when shutting down (nothing is changing), when | 77 // This function is called when shutting down (nothing is changing), when |
78 // sync is disabled completely, or when wallet sync is disabled. In the | 78 // sync is disabled completely, or when wallet sync is disabled. In the |
79 // cases where wallet sync or sync in general is disabled, clear wallet cards | 79 // cases where wallet sync or sync in general is disabled, clear wallet cards |
80 // and addresses copied from the server. This is different than other sync | 80 // and addresses copied from the server. This is different than other sync |
81 // cases since this type of data reflects what's on the server rather than | 81 // cases since this type of data reflects what's on the server rather than |
82 // syncing local data between clients, so this extra step is required. | 82 // syncing local data between clients, so this extra step is required. |
83 sync_driver::SyncService* service = sync_client_->GetSyncService(); | 83 syncer::SyncService* service = sync_client_->GetSyncService(); |
84 | 84 |
85 // CanSyncStart indicates if sync is currently enabled at all. The preferred | 85 // CanSyncStart indicates if sync is currently enabled at all. The preferred |
86 // data type indicates if wallet sync data/metadata is enabled, and | 86 // data type indicates if wallet sync data/metadata is enabled, and |
87 // currently_enabled_ indicates if the other prefs are enabled. All of these | 87 // currently_enabled_ indicates if the other prefs are enabled. All of these |
88 // have to be enabled to sync wallet data/metadata. | 88 // have to be enabled to sync wallet data/metadata. |
89 if (!service->CanSyncStart() || | 89 if (!service->CanSyncStart() || |
90 !service->GetPreferredDataTypes().Has(type()) || !currently_enabled_) { | 90 !service->GetPreferredDataTypes().Has(type()) || !currently_enabled_) { |
91 autofill::PersonalDataManager* pdm = sync_client_->GetPersonalDataManager(); | 91 autofill::PersonalDataManager* pdm = sync_client_->GetPersonalDataManager(); |
92 if (pdm) | 92 if (pdm) |
93 pdm->ClearAllServerData(); | 93 pdm->ClearAllServerData(); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 bool AutofillWalletDataTypeController::ReadyForStart() const { | 97 bool AutofillWalletDataTypeController::ReadyForStart() const { |
98 DCHECK(CalledOnValidThread()); | 98 DCHECK(CalledOnValidThread()); |
99 return currently_enabled_; | 99 return currently_enabled_; |
100 } | 100 } |
101 | 101 |
102 void AutofillWalletDataTypeController::OnUserPrefChanged() { | 102 void AutofillWalletDataTypeController::OnUserPrefChanged() { |
103 DCHECK(CalledOnValidThread()); | 103 DCHECK(CalledOnValidThread()); |
104 | 104 |
105 bool new_enabled = IsEnabled(); | 105 bool new_enabled = IsEnabled(); |
106 if (currently_enabled_ == new_enabled) | 106 if (currently_enabled_ == new_enabled) |
107 return; // No change to sync state. | 107 return; // No change to sync state. |
108 currently_enabled_ = new_enabled; | 108 currently_enabled_ = new_enabled; |
109 | 109 |
110 if (currently_enabled_) { | 110 if (currently_enabled_) { |
111 // The preference was just enabled. Trigger a reconfiguration. This will do | 111 // The preference was just enabled. Trigger a reconfiguration. This will do |
112 // nothing if the type isn't preferred. | 112 // nothing if the type isn't preferred. |
113 sync_driver::SyncService* sync_service = sync_client_->GetSyncService(); | 113 syncer::SyncService* sync_service = sync_client_->GetSyncService(); |
114 sync_service->ReenableDatatype(type()); | 114 sync_service->ReenableDatatype(type()); |
115 } else { | 115 } else { |
116 // Report the error (which will stop the datatype asynchronously). | 116 // Report the error (which will stop the datatype asynchronously). |
117 if (state() != NOT_RUNNING && state() != STOPPING) { | 117 if (state() != NOT_RUNNING && state() != STOPPING) { |
118 CreateErrorHandler()->OnUnrecoverableError( | 118 CreateErrorHandler()->OnUnrecoverableError( |
119 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_POLICY_ERROR, | 119 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_POLICY_ERROR, |
120 "Wallet syncing is disabled by policy.", type())); | 120 "Wallet syncing is disabled by policy.", type())); |
121 } | 121 } |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 bool AutofillWalletDataTypeController::IsEnabled() { | 125 bool AutofillWalletDataTypeController::IsEnabled() { |
126 DCHECK(CalledOnValidThread()); | 126 DCHECK(CalledOnValidThread()); |
127 | 127 |
128 // Require the user-visible pref to be enabled to sync Wallet data/metadata. | 128 // Require the user-visible pref to be enabled to sync Wallet data/metadata. |
129 PrefService* ps = sync_client_->GetPrefService(); | 129 PrefService* ps = sync_client_->GetPrefService(); |
130 return ps->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled); | 130 return ps->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled); |
131 } | 131 } |
132 | 132 |
133 } // namespace browser_sync | 133 } // namespace browser_sync |
OLD | NEW |