Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / pending_enables.cc
blobf7af99dafc9e6b89bbcf5d06299fe6863b07bc7e
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 "chrome/browser/sync/sync_prefs.h"
11 namespace extensions {
13 PendingEnables::PendingEnables(scoped_ptr<browser_sync::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) {
22 PendingEnables::~PendingEnables() {
25 void PendingEnables::OnExtensionEnabled(const std::string& extension_id) {
26 if (IsWaitingForSync())
27 ids_.insert(extension_id);
30 void PendingEnables::OnExtensionDisabled(const std::string& extension_id) {
31 if (IsWaitingForSync())
32 ids_.erase(extension_id);
35 void PendingEnables::OnSyncStarted(ExtensionService* service) {
36 for (std::set<std::string>::const_iterator it = ids_.begin();
37 it != ids_.end(); ++it) {
38 const Extension* extension = service->GetExtensionById(*it, true);
39 if (extension)
40 sync_bundle_->SyncChangeIfNeeded(*extension);
42 ids_.clear();
45 bool PendingEnables::Contains(const std::string& extension_id) const {
46 return ids_.find(extension_id) != ids_.end();
49 bool PendingEnables::IsSyncEnabled() {
50 if (is_sync_enabled_for_test_)
51 return true;
52 return sync_prefs_ &&
53 sync_prefs_->HasSyncSetupCompleted() &&
54 sync_prefs_->GetPreferredDataTypes(syncer::ModelTypeSet(enable_type_))
55 .Has(enable_type_);
58 bool PendingEnables::IsWaitingForSync() {
59 return IsSyncEnabled() && !sync_bundle_->IsSyncing();
62 } // namespace extensions