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.
5 #include "chrome/browser/extensions/pending_enables.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/sync_bundle.h"
9 #include "components/sync_driver/sync_prefs.h"
11 namespace extensions
{
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) {}
21 PendingEnables::~PendingEnables() {
24 void PendingEnables::Add(const std::string
& extension_id
) {
25 if (IsWaitingForSync())
26 ids_
.insert(extension_id
);
29 void PendingEnables::Remove(const std::string
& extension_id
) {
30 if (IsWaitingForSync())
31 ids_
.erase(extension_id
);
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);
39 sync_bundle_
->PushSyncChangeIfNeeded(*extension
);
44 bool PendingEnables::Contains(const std::string
& extension_id
) const {
45 return ids_
.find(extension_id
) != ids_
.end();
48 bool PendingEnables::IsSyncEnabled() {
49 if (is_sync_enabled_for_test_
)
52 sync_prefs_
->HasSyncSetupCompleted() &&
53 sync_prefs_
->GetPreferredDataTypes(syncer::ModelTypeSet(enable_type_
))
57 bool PendingEnables::IsWaitingForSync() {
58 return IsSyncEnabled() && !sync_bundle_
->IsSyncing();
61 } // namespace extensions