summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/extension_service.cc8
-rw-r--r--chrome/browser/extensions/extension_service.h4
-rw-r--r--chrome/common/extensions/extension_set.cc11
-rw-r--r--chrome/common/extensions/extension_set.h6
-rw-r--r--chrome/common/extensions/extension_set_unittest.cc19
5 files changed, 45 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 834cc4b..7891b83 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -471,6 +471,14 @@ const ExtensionSet* ExtensionService::terminated_extensions() const {
return &terminated_extensions_;
}
+const ExtensionSet* ExtensionService::GenerateInstalledExtensionsSet() const {
+ ExtensionSet* installed_extensions = new ExtensionSet();
+ installed_extensions->InsertAll(extensions_);
+ installed_extensions->InsertAll(disabled_extensions_);
+ installed_extensions->InsertAll(terminated_extensions_);
+ return installed_extensions;
+}
+
PendingExtensionManager* ExtensionService::pending_extension_manager() {
return &pending_extension_manager_;
}
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index f5f3fd2..3467812b 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -199,6 +199,10 @@ class ExtensionService
const ExtensionSet* disabled_extensions() const;
const ExtensionSet* terminated_extensions() const;
+ // Retuns a set of all installed, disabled, and terminated extensions and
+ // transfers ownership to caller.
+ const ExtensionSet* GenerateInstalledExtensionsSet() const;
+
// Gets the object managing the set of pending extensions.
virtual PendingExtensionManager* pending_extension_manager() OVERRIDE;
diff --git a/chrome/common/extensions/extension_set.cc b/chrome/common/extensions/extension_set.cc
index d6d18f7..f5aee9f 100644
--- a/chrome/common/extensions/extension_set.cc
+++ b/chrome/common/extensions/extension_set.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -41,6 +41,15 @@ void ExtensionSet::Insert(const scoped_refptr<const Extension>& extension) {
extensions_[extension->id()] = extension;
}
+bool ExtensionSet::InsertAll(const ExtensionSet& extensions) {
+ size_t before = size();
+ for (ExtensionSet::const_iterator iter = extensions.begin();
+ iter != extensions.end(); ++iter) {
+ Insert(*iter);
+ }
+ return size() != before;
+}
+
void ExtensionSet::Remove(const std::string& id) {
extensions_.erase(id);
}
diff --git a/chrome/common/extensions/extension_set.h b/chrome/common/extensions/extension_set.h
index 87edae1..9d46373 100644
--- a/chrome/common/extensions/extension_set.h
+++ b/chrome/common/extensions/extension_set.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -85,6 +85,10 @@ class ExtensionSet {
// previous extension with the same ID is removed.
void Insert(const scoped_refptr<const Extension>& extension);
+ // Copies different items from |extensions| to the current set and returns
+ // whether anything changed.
+ bool InsertAll(const ExtensionSet& extensions);
+
// Removes the specified extension.
void Remove(const std::string& id);
diff --git a/chrome/common/extensions/extension_set_unittest.cc b/chrome/common/extensions/extension_set_unittest.cc
index 56f2b5f..37e5559 100644
--- a/chrome/common/extensions/extension_set_unittest.cc
+++ b/chrome/common/extensions/extension_set_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -114,4 +114,21 @@ TEST(ExtensionSetTest, ExtensionSet) {
extensions.Remove(ext2->id());
EXPECT_EQ(2u, extensions.size());
EXPECT_FALSE(extensions.GetByID(ext2->id()));
+
+ // Make a union of a set with 3 more extensions (only 2 are new).
+ scoped_refptr<Extension> ext5(CreateTestExtension("d", "", ""));
+ scoped_refptr<Extension> ext6(CreateTestExtension("e", "", ""));
+ ASSERT_TRUE(ext5 && ext6);
+
+ scoped_ptr<ExtensionSet> to_add(new ExtensionSet());
+ to_add->Insert(ext3); // Already in |extensions|, should not affect size.
+ to_add->Insert(ext5);
+ to_add->Insert(ext6);
+
+ ASSERT_TRUE(extensions.Contains(ext3->id()));
+ ASSERT_TRUE(extensions.InsertAll(*to_add));
+ EXPECT_EQ(4u, extensions.size());
+
+ ASSERT_FALSE(extensions.InsertAll(*to_add)); // Re-adding same set no-ops.
+ EXPECT_EQ(4u, extensions.size());
}