diff options
author | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 07:43:01 +0000 |
---|---|---|
committer | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 07:43:01 +0000 |
commit | 7f4308d5da55597a0c2c74a5749ae6439082b18a (patch) | |
tree | 0b7ea28f453d56e3e1e6fa4eb16b550b0b1d3af6 /chrome | |
parent | 257b2c5198a848075c7f62f2619c027e76873b2d (diff) | |
download | chromium_src-7f4308d5da55597a0c2c74a5749ae6439082b18a.zip chromium_src-7f4308d5da55597a0c2c74a5749ae6439082b18a.tar.gz chromium_src-7f4308d5da55597a0c2c74a5749ae6439082b18a.tar.bz2 |
[NTP4] Add ExtensionSet::AddAll and ExtensionService::GetAllInstalledExtensions.
R=aa@chromium.org
TBR=estade@chromium.org
TEST=ExtensionsSetTest.ExtensionSet passes and nothing breaks.
BUG=97762
Review URL: http://codereview.chromium.org/9134003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.h | 4 | ||||
-rw-r--r-- | chrome/common/extensions/extension_set.cc | 11 | ||||
-rw-r--r-- | chrome/common/extensions/extension_set.h | 6 | ||||
-rw-r--r-- | chrome/common/extensions/extension_set_unittest.cc | 19 |
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()); } |