Chromium Code Reviews| Index: chrome/browser/extensions/api/preferences_private/preferences_private_api.cc |
| diff --git a/chrome/browser/extensions/api/preferences_private/preferences_private_api.cc b/chrome/browser/extensions/api/preferences_private/preferences_private_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8b880580bb6384bbdfa2eafbdb971f62a97153af |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/preferences_private/preferences_private_api.cc |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2013 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 "chrome/browser/extensions/api/preferences_private/preferences_private_api.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/sync/profile_sync_service.h" |
| +#include "chrome/browser/sync/profile_sync_service_factory.h" |
| +#include "chrome/browser/sync/sync_prefs.h" |
| +#include "chrome/common/extensions/api/preferences_private.h" |
| + |
| +namespace extensions { |
| + |
| +namespace GetSyncCategoriesWithoutPassphrase = |
| + api::preferences_private::GetSyncCategoriesWithoutPassphrase; |
| + |
| +PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction:: |
| +PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction() {} |
| + |
| +PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction:: |
| +~PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction() {} |
| + |
| +void PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::Run() { |
| + ProfileSyncService* sync_service = |
|
not at google - send to devlin
2013/12/18 22:30:37
@zea - can this ever be null (e.g. if the sync ser
Nicolas Zea
2013/12/19 00:23:59
If sync is disabled by command line flag this can
Rune Fevang
2013/12/19 00:35:49
Done.
|
| + ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
| + if (sync_service->sync_initialized()) { |
| + SendResponse(RunImpl()); |
| + } else { |
| + AddRef(); // Balanced in OnStateChanged(). |
| + sync_service->AddObserver(this); |
|
not at google - send to devlin
2013/12/18 22:30:37
idiomatically all work is done in RunImpl and Run
Rune Fevang
2013/12/19 00:13:43
Done.
|
| + } |
| +} |
| + |
| +void |
| +PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::OnStateChanged() { |
| + ProfileSyncService* sync_service = |
| + ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
| + if (sync_service->sync_initialized()) { |
| + sync_service->RemoveObserver(this); |
| + SendResponse(RunImpl()); |
| + Release(); // Balanced in Run(). |
| + } |
| +} |
| + |
| +bool PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::RunImpl() { |
| + ProfileSyncService* sync_service = |
| + ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
| + |
| + syncer::ModelTypeSet result_set = syncer::UserSelectableTypes(); |
| + |
| + // Only include categories that are synced. |
| + browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); |
| + if (!sync_prefs.HasKeepEverythingSynced()) { |
| + result_set = syncer::Intersection(result_set, |
| + sync_service->GetPreferredDataTypes()); |
| + } |
| + // Don't include encrypted categories. |
| + result_set = syncer::Difference(result_set, |
| + sync_service->GetEncryptedDataTypes()); |
|
not at google - send to devlin
2013/12/18 22:30:37
is it possible for there to be things in Encrypted
Rune Fevang
2013/12/19 00:13:43
I'm not sure, but I don't really see how it matter
Nicolas Zea
2013/12/19 00:23:59
It is possible, but Difference does an A & ~B oper
|
| + |
| + std::vector<std::string> categories; |
| + for (syncer::ModelTypeSet::Iterator it = result_set.First(); it.Good(); |
| + it.Inc()) { |
| + categories.push_back(syncer::ModelTypeToString(it.Get())); |
| + } |
| + |
| + results_ = GetSyncCategoriesWithoutPassphrase::Results::Create(categories); |
| + return true; |
| +} |
| + |
| +} // namespace extensions |