Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Add support for installing / updating extensions #59

Merged
merged 2 commits into from
Sep 27, 2016

Conversation

bbondy
Copy link
Member

@bbondy bbondy commented Sep 20, 2016

Auditors: @darkdh @bridiver

@@ -0,0 +1,172 @@
// Copyright 2016 The Brave Authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to brave/browser in a follow-up? Trying to keep non-upstreamable stuff separate so we can split out the repos

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

const content::NotificationDetails& details) {
switch (type) {
case extensions::NOTIFICATION_EXTENSION_ENABLED: {
Emit("extension-enabled");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably have one for extension-disabled as well, but maybe both should go in atom_api_extensions? Can also be follow-up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't even use this so I can remove it.

void Extension::Remove(const std::string& extension_id) {
const extensions::Extension* extension =
GetInstance()->extensions_.GetByID(extension_id);
if (extension) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this just call Extension::Disable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I would disable in AtomExtensionSystem because there is a check there to prevent uninstalling component extensions (like brave)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't NOTIFICATION_DISABLE_USER_EXTENSION_REQUEST handled in AtomExtensionSystem to disable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but there are other checks that should happen and I think it's better to keep all of that within AtomExtensionSystem. See ExtensionService::UninstallExtension and ExtensionService::UnloadExtension. We don't need everything in there, but I think we should keep the basic structure the same because it's much easier to follow changes in libchromiumcontent that way


base::FilePath install_directory;
PathService::Get(component_updater::DIR_COMPONENT_USER, &install_directory);
extensions::file_util::UninstallExtension(install_directory, extension_id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should run on the file thread and should probably also happen in AtomExtensionSystem to prevent uninstall of component extensions. See ExtensionService::OnExtensionInstalled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k will move it.

&install_directory);
std::string extension_id = extension->id();
auto registry = ExtensionRegistry::Get(browser_context_);
registry->RemoveEnabled(extension_id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if these methods should be called or not, but ExtensionRegistry::TriggerOnUninstalled does. See ExtensionService::UninstallExtension

mate::Handle<UpdateClient> UpdateClient::Create(
v8::Isolate* isolate,
content::BrowserContext* browser_context) {
return mate::CreateHandle(isolate,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the update client should use chrome::GetBrowserContextRedirectedInIncognito to make sure that there is only one per user since the extensions are shared across private and session contexts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually see above because I think using AtomBrowserCreateUpdateClient::CreateUpdateClient is the right way to handle this

UpdateClient::UpdateClient(v8::Isolate* isolate,
content::BrowserContext* browser_context)
: browser_context_(browser_context) {
cus_ = component_updater::ComponentUpdateServiceFactory(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is only supposed to be one component updater globally, but maybe this is ok for now with the change below that creates a shared update client for all contexts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's only used for the default session, even know it can be used for others as well (there would be no point). Is there a way to get the default session browser context as a singleton or something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, there are two things going on here. The update client really should be retrieved from AtomBrowserCreateUpdateClient::CreateUpdateClient with something like

return update_client::UpdateClientFactory(
      make_scoped_refptr(new AtomUpdateClientConfig(GetOriginalContext(context))));

If you do that the UpdateServiceFactory::GetForBrowserContext(browser_context) will work correctly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the component updater service itself can be initialized with the default browser context and in chrome it's attached to the BrowserProcess

@bbondy bbondy force-pushed the component_updater53 branch 10 times, most recently from e547c0c to 67f2294 Compare September 24, 2016 15:20
@bbondy
Copy link
Member Author

bbondy commented Sep 24, 2016

@darkdh @bridiver this is ready for another review. You'll notice I didn't end up needing to uninstall to upgrade, so this adds some code for uninstalling that is not currently used, but I think it's useful to keep anyway.

@bbondy bbondy force-pushed the component_updater53 branch 5 times, most recently from 563ed2e to b478e10 Compare September 26, 2016 20:26
@@ -148,7 +154,8 @@ bool BraveConfigurator::UseBackgroundDownloader() const {
}

bool BraveConfigurator::UseCupSigning() const {
return configurator_impl_.UseCupSigning();
// return configurator_impl_.UseCupSigning();
return false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked with Yan and she said this is ok.

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few small changes, otherwise ++

@@ -220,6 +220,26 @@ void Extension::Enable(const std::string& extension_id) {
}

// static
void Extension::Remove(const std::string& extension_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make this remove to be consistent?

//
// If the return value is true, |deletion_done_callback| is invoked when
// data deletion is done or at least is scheduled.
bool UninstallExtension(const std::string& extension_id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method should also be a virtual method on the extension service so it can be called with

return extensions::ExtensionSystem::Get(context)
          ->extension_service()
          ->UninstallExtension(transient_extension_id, reason,
                               deletion_done_callback, error);

from atom_extensions_api_client

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just remove uninstall and remove since they aren't used for now.

&install_directory);

// Tell the backend to start deleting installed extensions on the file thread.
BrowserThread::PostTask(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it could be a problem here if we don't use the blocking thread pool because the remove could still be in progress when the new install starts on an update

// Notify interested parties that we've uninstalled this extension.
ExtensionRegistry::Get(browser_context_)
->TriggerOnUninstalled(extension.get(), reason);

Copy link
Collaborator

@bridiver bridiver Sep 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extension_prefs_->OnExtensionUninstalled(
      extension->id(), extension->location(), external_uninstall);

content::Source<content::BrowserContext>(browser_context_),
content::Details<const Extension>(extension));
} else {
// All apps that are displayed in the launcher are ordered by their ordinals
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this section should be left out because it deals with chrome apps, not extensions and app_sorting() returns nullptr

@@ -59,6 +60,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
extensions::StorageFrontend::GetFactoryInstance();
extensions::WebRequestAPI::GetFactoryInstance();
extensions::AtomExtensionSystemFactory::GetInstance();
extensions::UpdateServiceFactory::GetInstance();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateServiceFactory won't work correctly unless AtomExtensionBrowserClient implements ExtensionsBrowserClient::CreateUpdateClient

return update_client::UpdateClientFactory(
      make_scoped_refptr(new BraveUpdateClientConfig(context)));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this doesn't appear to be implemented in chrome so we should probably remove it because it will pass nullptr to the `UpdateService if it is called anywhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya this was left over from when I did have CreateUpdateClient which I didn't end up needing, removing.

@bbondy bbondy force-pushed the component_updater53 branch 2 times, most recently from 1ea9e4b to 76fc5ae Compare September 27, 2016 04:29
@bridiver bridiver merged commit 60da0fd into master Sep 27, 2016
@bridiver
Copy link
Collaborator

++

@bbondy bbondy deleted the component_updater53 branch September 27, 2016 12:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants