1 // Copyright 2014 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.
5 #include "chrome/browser/extensions/api/preferences_private/preferences_private_api.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/sync/profile_sync_service.h"
9 #include "chrome/browser/sync/profile_sync_service_factory.h"
10 #include "chrome/common/extensions/api/preferences_private.h"
11 #include "components/sync_driver/sync_prefs.h"
13 namespace extensions
{
15 namespace GetSyncCategoriesWithoutPassphrase
=
16 api::preferences_private::GetSyncCategoriesWithoutPassphrase
;
18 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::
19 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction() {}
21 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::
22 ~PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction() {}
25 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::OnStateChanged() {
26 ProfileSyncService
* sync_service
=
27 ProfileSyncServiceFactory::GetForProfile(GetProfile());
28 if (sync_service
->IsSyncActive()) {
29 sync_service
->RemoveObserver(this);
31 Release(); // Balanced in RunAsync().
35 bool PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::RunAsync() {
36 ProfileSyncService
* sync_service
=
37 ProfileSyncServiceFactory::GetForProfile(GetProfile());
40 if (!sync_service
->IsSyncActive()) {
41 AddRef(); // Balanced in OnStateChanged().
42 sync_service
->AddObserver(this);
46 syncer::ModelTypeSet result_set
= syncer::UserSelectableTypes();
48 // Only include categories that are synced.
49 sync_driver::SyncPrefs
sync_prefs(GetProfile()->GetPrefs());
50 if (!sync_prefs
.HasKeepEverythingSynced()) {
51 result_set
= syncer::Intersection(result_set
,
52 sync_service
->GetPreferredDataTypes());
54 // Don't include encrypted categories.
55 result_set
= syncer::Difference(result_set
,
56 sync_service
->GetEncryptedDataTypes());
58 std::vector
<std::string
> categories
;
59 for (syncer::ModelTypeSet::Iterator it
= result_set
.First(); it
.Good();
61 categories
.push_back(syncer::ModelTypeToString(it
.Get()));
64 results_
= GetSyncCategoriesWithoutPassphrase::Results::Create(categories
);
69 } // namespace extensions