Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: chrome/browser/extensions/api/preferences_private/preferences_private_api.cc

Issue 118413003: Add hook for extension to check sync status. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::Run() {
25 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.
26 ProfileSyncServiceFactory::GetForProfile(GetProfile());
27 if (sync_service->sync_initialized()) {
28 SendResponse(RunImpl());
29 } else {
30 AddRef(); // Balanced in OnStateChanged().
31 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.
32 }
33 }
34
35 void
36 PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::OnStateChanged() {
37 ProfileSyncService* sync_service =
38 ProfileSyncServiceFactory::GetForProfile(GetProfile());
39 if (sync_service->sync_initialized()) {
40 sync_service->RemoveObserver(this);
41 SendResponse(RunImpl());
42 Release(); // Balanced in Run().
43 }
44 }
45
46 bool PreferencesPrivateGetSyncCategoriesWithoutPassphraseFunction::RunImpl() {
47 ProfileSyncService* sync_service =
48 ProfileSyncServiceFactory::GetForProfile(GetProfile());
49
50 syncer::ModelTypeSet result_set = syncer::UserSelectableTypes();
51
52 // Only include categories that are synced.
53 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs());
54 if (!sync_prefs.HasKeepEverythingSynced()) {
55 result_set = syncer::Intersection(result_set,
56 sync_service->GetPreferredDataTypes());
57 }
58 // Don't include encrypted categories.
59 result_set = syncer::Difference(result_set,
60 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
61
62 std::vector<std::string> categories;
63 for (syncer::ModelTypeSet::Iterator it = result_set.First(); it.Good();
64 it.Inc()) {
65 categories.push_back(syncer::ModelTypeToString(it.Get()));
66 }
67
68 results_ = GetSyncCategoriesWithoutPassphrase::Results::Create(categories);
69 return true;
70 }
71
72 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698