OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 "chrome/browser/extensions/api/preferences_private/preferences_private_ api.h" | |
6 | |
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/browser/sync/sync_prefs.h" | |
11 #include "chrome/common/extensions/api/preferences_private.h" | |
12 | |
13 namespace extensions { | |
14 | |
15 namespace GetSyncCategoriesWithoutPassphrase = | |
16 api::preferences_private::GetSyncCategoriesWithoutPassphrase; | |
17 | |
18 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction:: | |
19 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction() {} | |
20 | |
21 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction:: | |
22 ~PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction() {} | |
23 | |
24 void | |
25 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::OnStateChanged() { | |
26 ProfileSyncService* sync_service = | |
27 ProfileSyncServiceFactory::GetForProfile(GetProfile()); | |
28 if (sync_service->sync_initialized()) { | |
29 sync_service->RemoveObserver(this); | |
30 RunImpl(); | |
31 Release(); // Balanced in RunImpl(). | |
32 } | |
33 } | |
34 | |
35 bool PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::RunImpl() { | |
36 ProfileSyncService* sync_service = | |
37 ProfileSyncServiceFactory::GetForProfile(GetProfile()); | |
38 if (!sync_service->sync_initialized()) { | |
39 AddRef(); // Balanced in OnStateChanged(). | |
40 sync_service->AddObserver(this); | |
41 return true; | |
42 } | |
43 | |
44 syncer::ModelTypeSet result_set = syncer::UserSelectableTypes(); | |
45 | |
46 // Only include categories that are synced. | |
47 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); | |
48 if (!sync_prefs.HasKeepEverythingSynced()) { | |
49 result_set = syncer::Intersection(result_set, | |
50 sync_service->GetPreferredDataTypes()); | |
Nicolas Zea
2013/12/19 00:23:59
Do you want GetPreferred, or GetActive? Active is
Rune Fevang
2013/12/19 00:35:49
The use case is "which types do the user want to s
| |
51 } | |
52 // Don't include encrypted categories. | |
53 result_set = syncer::Difference(result_set, | |
54 sync_service->GetEncryptedDataTypes()); | |
55 | |
56 std::vector<std::string> categories; | |
57 for (syncer::ModelTypeSet::Iterator it = result_set.First(); it.Good(); | |
58 it.Inc()) { | |
59 categories.push_back(syncer::ModelTypeToString(it.Get())); | |
60 } | |
61 | |
62 results_ = GetSyncCategoriesWithoutPassphrase::Results::Create(categories); | |
63 SendResponse(true); | |
64 return true; | |
65 } | |
66 | |
67 } // namespace extensions | |
OLD | NEW |