summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 08:45:15 +0000
committerlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 08:45:15 +0000
commit17f07823f46562542f60361beffe217b6bc94a77 (patch)
tree96121bbabec15b17a2b8b7890f30a53b72e4d6d3 /extensions
parentb1712ec30f0518ba9ed02a0eed88a89cc7ab00b3 (diff)
downloadchromium_src-17f07823f46562542f60361beffe217b6bc94a77.zip
chromium_src-17f07823f46562542f60361beffe217b6bc94a77.tar.gz
chromium_src-17f07823f46562542f60361beffe217b6bc94a77.tar.bz2
Add a function triggering extension installed to ExtensionRegistryObserver.
This can be replace chrome::NOTIFICATION_EXTENSION_INSTALLED with ExtensionRegistryObserver. And apply it to WebStoreInstaller and InstallTracker. R=kalman@chromium.org BUG=354459 TEST=unit_test, manual(install app from webstore) Review URL: https://codereview.chromium.org/279073003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/extension_registry.cc12
-rw-r--r--extensions/browser/extension_registry.h8
-rw-r--r--extensions/browser/extension_registry_observer.h15
-rw-r--r--extensions/browser/extension_registry_unittest.cc18
4 files changed, 53 insertions, 0 deletions
diff --git a/extensions/browser/extension_registry.cc b/extensions/browser/extension_registry.cc
index ac6c274..76783f0 100644
--- a/extensions/browser/extension_registry.cc
+++ b/extensions/browser/extension_registry.cc
@@ -53,6 +53,18 @@ void ExtensionRegistry::TriggerOnUnloaded(
OnExtensionUnloaded(browser_context_, extension, reason));
}
+void ExtensionRegistry::TriggerOnWillBeInstalled(const Extension* extension,
+ bool is_update,
+ const std::string& old_name) {
+ DCHECK(is_update ==
+ GenerateInstalledExtensionsSet()->Contains(extension->id()));
+ DCHECK(is_update == !old_name.empty());
+ FOR_EACH_OBSERVER(ExtensionRegistryObserver,
+ observers_,
+ OnExtensionWillBeInstalled(
+ browser_context_, extension, is_update, old_name));
+}
+
const Extension* ExtensionRegistry::GetExtensionById(const std::string& id,
int include_mask) const {
std::string lowercase_id = StringToLowerASCII(id);
diff --git a/extensions/browser/extension_registry.h b/extensions/browser/extension_registry.h
index d8df24b..65ee751 100644
--- a/extensions/browser/extension_registry.h
+++ b/extensions/browser/extension_registry.h
@@ -74,6 +74,14 @@ class ExtensionRegistry : public KeyedService {
void TriggerOnUnloaded(const Extension* extension,
UnloadedExtensionInfo::Reason reason);
+ // If this is a fresh install then |is_update| is false and there must not be
+ // any installed extension with |extension|'s ID. If this is an update then
+ // |is_update| is true and must be an installed extension with |extension|'s
+ // ID, and |old_name| must be non-empty.
+ void TriggerOnWillBeInstalled(const Extension* extension,
+ bool is_update,
+ const std::string& old_name);
+
// Find an extension by ID using |include_mask| to pick the sets to search:
// * enabled_extensions() --> ExtensionRegistry::ENABLED
// * disabled_extensions() --> ExtensionRegistry::DISABLED
diff --git a/extensions/browser/extension_registry_observer.h b/extensions/browser/extension_registry_observer.h
index 5880add..6ad0666 100644
--- a/extensions/browser/extension_registry_observer.h
+++ b/extensions/browser/extension_registry_observer.h
@@ -33,6 +33,21 @@ class ExtensionRegistryObserver {
virtual void OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {}
+
+ // Called when |extension| is about to be installed. |is_update| is true if
+ // the installation is the result of it updating, in which case |old_name| is
+ // the name of the extension's previous version.
+ // The ExtensionRegistry will not be tracking |extension| at the time this
+ // event is fired, but will be immediately afterwards (note: not necessarily
+ // enabled; it might be installed in the disabled or even blacklisted sets,
+ // for example).
+ // Note that it's much more common to care about extensions being loaded
+ // (OnExtensionLoaded).
+ virtual void OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ bool is_update,
+ const std::string& old_name) {}
};
} // namespace extensions
diff --git a/extensions/browser/extension_registry_unittest.cc b/extensions/browser/extension_registry_unittest.cc
index f212f6c..8281ee0 100644
--- a/extensions/browser/extension_registry_unittest.cc
+++ b/extensions/browser/extension_registry_unittest.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/memory/ref_counted.h"
+#include "base/strings/string_util.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
#include "extensions/common/test_util.h"
@@ -37,10 +38,12 @@ class TestObserver : public ExtensionRegistryObserver {
void Reset() {
loaded_.clear();
unloaded_.clear();
+ installed_.clear();
}
const ExtensionList& loaded() { return loaded_; }
const ExtensionList& unloaded() { return unloaded_; }
+ const ExtensionList& installed() { return installed_; }
private:
virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
@@ -55,8 +58,17 @@ class TestObserver : public ExtensionRegistryObserver {
unloaded_.push_back(extension);
}
+ virtual void OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ bool is_update,
+ const std::string& old_name) OVERRIDE {
+ installed_.push_back(extension);
+ }
+
ExtensionList loaded_;
ExtensionList unloaded_;
+ ExtensionList installed_;
};
TEST_F(ExtensionRegistryTest, FillAndClearRegistry) {
@@ -215,13 +227,19 @@ TEST_F(ExtensionRegistryTest, Observer) {
EXPECT_TRUE(observer.loaded().empty());
EXPECT_TRUE(observer.unloaded().empty());
+ EXPECT_TRUE(observer.installed().empty());
scoped_refptr<const Extension> extension =
test_util::CreateExtensionWithID("id");
+ registry.TriggerOnWillBeInstalled(extension, false, base::EmptyString());
+ EXPECT_TRUE(HasSingleExtension(observer.installed(), extension.get()));
+
registry.AddEnabled(extension);
registry.TriggerOnLoaded(extension);
+ registry.TriggerOnWillBeInstalled(extension, true, "foo");
+
EXPECT_TRUE(HasSingleExtension(observer.loaded(), extension.get()));
EXPECT_TRUE(observer.unloaded().empty());
observer.Reset();