blob: de43a4cf0e2ab21df91bd290087b4d35546a74a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright 2014 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::OnStateChanged() {
ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(GetProfile());
if (sync_service->sync_initialized()) {
sync_service->RemoveObserver(this);
RunImpl();
Release(); // Balanced in RunImpl().
}
}
bool PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::RunImpl() {
ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(GetProfile());
if (!sync_service)
return false;
if (!sync_service->sync_initialized()) {
AddRef(); // Balanced in OnStateChanged().
sync_service->AddObserver(this);
return true;
}
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());
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);
SendResponse(true);
return true;
}
} // namespace extensions
|