Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1323)

Unified Diff: chrome/browser/extensions/external_provider_impl.cc

Issue 1495403002: Observe adding external extensions via windows registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleaned up, removed logs Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/external_provider_impl.cc
diff --git a/chrome/browser/extensions/external_provider_impl.cc b/chrome/browser/extensions/external_provider_impl.cc
index 9b62f0f43c3d092d0295db9f60867bb8f8e6b31c..fd015c560d6a690ac44cf7a7b8d1d65bc3d78a2c 100644
--- a/chrome/browser/extensions/external_provider_impl.cc
+++ b/chrome/browser/extensions/external_provider_impl.cc
@@ -119,7 +119,139 @@ void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
prefs_.reset(prefs);
ready_ = true; // Queries for extensions are allowed from this point.
+ NotifyExtensionsFromPrefs(true);
+ service_->OnExternalProviderReady(this);
+}
+
+void ExternalProviderImpl::UpdatePrefs(base::DictionaryValue* prefs) {
Devlin 2016/01/21 00:14:26 This is a little hard to review - can you un-move
lazyboy 2016/01/21 21:02:12 Done.
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // We only expect updates from windows registry.
+ CHECK(crx_location_ == Manifest::EXTERNAL_REGISTRY);
+
+ // Check if the service is still alive. It is possible that it went
+ // away while |loader_| was working on the FILE thread.
+ if (!service_)
+ return;
+ std::set<std::string> removed_extensions;
+ // Find extensions that were removed by this ExternalProvider.
+ for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) {
+ const std::string& extension_id = i.key();
+ // Don't bother about invalid ids.
+ if (!crx_file::id_util::IdIsValid(extension_id))
+ continue;
+ if (!prefs->HasKey(extension_id))
+ removed_extensions.insert(extension_id);
+ }
+
+ prefs_.reset(prefs);
+
+ // Notify ExtensionService about all the extension this provider has found
+ // "updates" for.
+ // For each update found, this will end up calling
+ // OnExternalExtensionUpdateUrlFound() or OnExternalExtensionFileFound().
+ NotifyExtensionsFromPrefs(false);
+ // Then notify about the completion of update, with list of extensions that
+ // were removed.
+ service_->OnExternalProviderUpdateComplete(this, removed_extensions);
+}
+
+void ExternalProviderImpl::ServiceShutdown() {
+ service_ = NULL;
+}
+
+bool ExternalProviderImpl::IsReady() const {
+ return ready_;
+}
+
+bool ExternalProviderImpl::HasExtension(
+ const std::string& id) const {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CHECK(prefs_.get());
+ CHECK(ready_);
+ return prefs_->HasKey(id);
+}
+
+bool ExternalProviderImpl::GetExtensionDetails(
+ const std::string& id, Manifest::Location* location,
+ scoped_ptr<Version>* version) const {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CHECK(prefs_.get());
+ CHECK(ready_);
+ base::DictionaryValue* extension = NULL;
+ if (!prefs_->GetDictionary(id, &extension))
+ return false;
+
+ Manifest::Location loc = Manifest::INVALID_LOCATION;
+ if (extension->HasKey(kExternalUpdateUrl)) {
+ loc = download_location_;
+
+ } else if (extension->HasKey(kExternalCrx)) {
+ loc = crx_location_;
+
+ std::string external_version;
+ if (!extension->GetString(kExternalVersion, &external_version))
+ return false;
+
+ if (version)
+ version->reset(new Version(external_version));
+
+ } else {
+ NOTREACHED(); // Chrome should not allow prefs to get into this state.
+ return false;
+ }
+
+ if (location)
+ *location = loc;
+
+ return true;
+}
+
+bool ExternalProviderImpl::HandleMinProfileVersion(
+ const base::DictionaryValue* extension,
+ const std::string& extension_id,
+ std::set<std::string>* unsupported_extensions) {
+ std::string min_profile_created_by_version;
+ if (profile_ &&
+ extension->GetString(kMinProfileCreatedByVersion,
+ &min_profile_created_by_version)) {
+ Version profile_version(
+ profile_->GetPrefs()->GetString(prefs::kProfileCreatedByVersion));
+ Version min_version(min_profile_created_by_version);
+ if (min_version.IsValid() && profile_version.CompareTo(min_version) < 0) {
+ unsupported_extensions->insert(extension_id);
+ VLOG(1) << "Skip installing (or uninstall) external extension: "
+ << extension_id
+ << " profile.created_by_version: " << profile_version.GetString()
+ << " min_profile_created_by_version: "
+ << min_profile_created_by_version;
+ return false;
+ }
+ }
+ return true;
+}
+
+bool ExternalProviderImpl::HandleDoNotInstallForEnterprise(
+ const base::DictionaryValue* extension,
+ const std::string& extension_id,
+ std::set<std::string>* unsupported_extensions) {
+ bool do_not_install_for_enterprise = false;
+ if (extension->GetBoolean(kDoNotInstallForEnterprise,
+ &do_not_install_for_enterprise) &&
+ do_not_install_for_enterprise) {
+ const policy::ProfilePolicyConnector* const connector =
+ policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_);
+ if (connector->IsManaged()) {
+ unsupported_extensions->insert(extension_id);
+ VLOG(1) << "Skip installing (or uninstall) external extension "
+ << extension_id << " restricted for managed user";
+ return false;
+ }
+ }
+ return true;
+}
+
+void ExternalProviderImpl::NotifyExtensionsFromPrefs(bool is_initial_load) {
// Set of unsupported extensions that need to be deleted from prefs_.
std::set<std::string> unsupported_extensions;
@@ -320,7 +452,8 @@ void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
update_url,
download_location_,
creation_flags,
- auto_acknowledge_);
+ auto_acknowledge_,
+ is_initial_load);
}
}
@@ -330,103 +463,6 @@ void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
// will be uninstalled later because provider doesn't provide it anymore.
prefs_->Remove(*it, NULL);
}
-
- service_->OnExternalProviderReady(this);
-}
-
-void ExternalProviderImpl::ServiceShutdown() {
- service_ = NULL;
-}
-
-bool ExternalProviderImpl::IsReady() const {
- return ready_;
-}
-
-bool ExternalProviderImpl::HasExtension(
- const std::string& id) const {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CHECK(prefs_.get());
- CHECK(ready_);
- return prefs_->HasKey(id);
-}
-
-bool ExternalProviderImpl::GetExtensionDetails(
- const std::string& id, Manifest::Location* location,
- scoped_ptr<Version>* version) const {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CHECK(prefs_.get());
- CHECK(ready_);
- base::DictionaryValue* extension = NULL;
- if (!prefs_->GetDictionary(id, &extension))
- return false;
-
- Manifest::Location loc = Manifest::INVALID_LOCATION;
- if (extension->HasKey(kExternalUpdateUrl)) {
- loc = download_location_;
-
- } else if (extension->HasKey(kExternalCrx)) {
- loc = crx_location_;
-
- std::string external_version;
- if (!extension->GetString(kExternalVersion, &external_version))
- return false;
-
- if (version)
- version->reset(new Version(external_version));
-
- } else {
- NOTREACHED(); // Chrome should not allow prefs to get into this state.
- return false;
- }
-
- if (location)
- *location = loc;
-
- return true;
-}
-
-bool ExternalProviderImpl::HandleMinProfileVersion(
- const base::DictionaryValue* extension,
- const std::string& extension_id,
- std::set<std::string>* unsupported_extensions) {
- std::string min_profile_created_by_version;
- if (profile_ &&
- extension->GetString(kMinProfileCreatedByVersion,
- &min_profile_created_by_version)) {
- Version profile_version(
- profile_->GetPrefs()->GetString(prefs::kProfileCreatedByVersion));
- Version min_version(min_profile_created_by_version);
- if (min_version.IsValid() && profile_version.CompareTo(min_version) < 0) {
- unsupported_extensions->insert(extension_id);
- VLOG(1) << "Skip installing (or uninstall) external extension: "
- << extension_id
- << " profile.created_by_version: " << profile_version.GetString()
- << " min_profile_created_by_version: "
- << min_profile_created_by_version;
- return false;
- }
- }
- return true;
-}
-
-bool ExternalProviderImpl::HandleDoNotInstallForEnterprise(
- const base::DictionaryValue* extension,
- const std::string& extension_id,
- std::set<std::string>* unsupported_extensions) {
- bool do_not_install_for_enterprise = false;
- if (extension->GetBoolean(kDoNotInstallForEnterprise,
- &do_not_install_for_enterprise) &&
- do_not_install_for_enterprise) {
- const policy::ProfilePolicyConnector* const connector =
- policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_);
- if (connector->IsManaged()) {
- unsupported_extensions->insert(extension_id);
- VLOG(1) << "Skip installing (or uninstall) external extension "
- << extension_id << " restricted for managed user";
- return false;
- }
- }
- return true;
}
// static

Powered by Google App Engine
This is Rietveld 408576698