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

Side by Side Diff: chrome/browser/extensions/pending_enables.cc

Issue 1240573012: Extension syncing: Introduce a NeedsSync pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext_sync_uninstall
Patch Set: (b); hackfix sync_integration_tests Created 5 years, 5 months 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/pending_enables.h"
6
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/sync_bundle.h"
9 #include "components/sync_driver/sync_prefs.h"
10
11 namespace extensions {
12
13 PendingEnables::PendingEnables(scoped_ptr<sync_driver::SyncPrefs> sync_prefs,
14 SyncBundle* sync_bundle,
15 syncer::ModelType enable_type)
16 : sync_prefs_(sync_prefs.Pass()),
17 sync_bundle_(sync_bundle),
18 enable_type_(enable_type),
19 is_sync_enabled_for_test_(false) {}
20
21 PendingEnables::~PendingEnables() {
22 }
23
24 void PendingEnables::Add(const std::string& extension_id) {
25 if (IsWaitingForSync())
26 ids_.insert(extension_id);
27 }
28
29 void PendingEnables::Remove(const std::string& extension_id) {
30 if (IsWaitingForSync())
31 ids_.erase(extension_id);
32 }
33
34 void PendingEnables::OnSyncStarted(ExtensionService* service) {
35 for (std::set<std::string>::const_iterator it = ids_.begin();
36 it != ids_.end(); ++it) {
37 const Extension* extension = service->GetExtensionById(*it, true);
38 if (extension)
39 sync_bundle_->PushSyncAddOrUpdate(*extension);
40 }
41 ids_.clear();
42 }
43
44 bool PendingEnables::Contains(const std::string& extension_id) const {
45 return ids_.find(extension_id) != ids_.end();
46 }
47
48 bool PendingEnables::IsSyncEnabled() {
49 if (is_sync_enabled_for_test_)
50 return true;
51 return sync_prefs_ &&
52 sync_prefs_->HasSyncSetupCompleted() &&
53 sync_prefs_->GetPreferredDataTypes(syncer::ModelTypeSet(enable_type_))
54 .Has(enable_type_);
55 }
56
57 bool PendingEnables::IsWaitingForSync() {
58 return IsSyncEnabled() && !sync_bundle_->IsSyncing();
59 }
60
61 } // namespace extensions
62
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698