Chromium Code Reviews| Index: chrome/browser/ui/webui/extensions/extension_loader_handler.cc |
| diff --git a/chrome/browser/ui/webui/extensions/extension_loader_handler.cc b/chrome/browser/ui/webui/extensions/extension_loader_handler.cc |
| index 6e43177a4a3abd3fe57b684c2c362b5012a36f9b..97ec4d318a3dfb7cd3bd326790c7cb43843046bb 100644 |
| --- a/chrome/browser/ui/webui/extensions/extension_loader_handler.cc |
| +++ b/chrome/browser/ui/webui/extensions/extension_loader_handler.cc |
| @@ -128,11 +128,31 @@ void ExtensionLoaderHandler::FileHelper::MultiFilesSelected( |
| NOTREACHED(); |
| } |
| +// Class to hold failure data when NotifyFrontendOfFailure is called before |
| +// the extensions page is fully loaded. |
| +class ExtensionLoaderHandler::FailureData { |
| + public: |
|
Devlin
2014/06/27 22:31:10
fix indentation.
gpdavis
2014/06/28 02:31:18
Done.
|
| + explicit FailureData(base::FilePath path, std::string error, |
|
Devlin
2014/06/27 22:31:09
nit: one param per line.
Devlin
2014/06/27 22:31:10
const & on non-simple arguments.
gpdavis
2014/06/28 02:31:18
Done.
gpdavis
2014/06/28 02:31:18
Done.
|
| + size_t line, std::string manifest) |
| + : file_path(path), |
| + error(error), |
| + line_number(line), |
| + manifest(manifest) {} |
| + |
| + base::FilePath file_path; |
|
Devlin
2014/06/27 22:31:09
entirely public classes are what structs are for ;
gpdavis
2014/06/27 23:42:54
That was what I started with, but I wasn't sure if
Devlin
2014/06/28 08:40:02
A couple of C++ finer points:
- A vector of struct
|
| + std::string error; |
| + size_t line_number; |
| + std::string manifest; |
| +}; |
| + |
| ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile) |
| : profile_(profile), |
| file_helper_(new FileHelper(this)), |
| - weak_ptr_factory_(this) { |
| + weak_ptr_factory_(this), |
|
Devlin
2014/06/27 22:31:09
weak_ptr_factory_ should be the final data member.
gpdavis
2014/06/28 02:31:18
Done.
|
| + extension_error_reporter_observer_(this), |
| + display_ready_(false) { |
| DCHECK(profile_); |
| + extension_error_reporter_observer_.Add(ExtensionErrorReporter::GetInstance()); |
| } |
| ExtensionLoaderHandler::~ExtensionLoaderHandler() { |
| @@ -166,6 +186,14 @@ void ExtensionLoaderHandler::RegisterMessages() { |
| "extensionLoaderRetry", |
| base::Bind(&ExtensionLoaderHandler::HandleRetry, |
| weak_ptr_factory_.GetWeakPtr())); |
| + web_ui()->RegisterMessageCallback( |
| + "extensionLoaderSetDisplayLoading", |
| + base::Bind(&ExtensionLoaderHandler::HandleSetDisplayLoading, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + web_ui()->RegisterMessageCallback( |
| + "extensionLoaderDisplayFailures", |
| + base::Bind(&ExtensionLoaderHandler::HandleDisplayFailures, |
| + weak_ptr_factory_.GetWeakPtr())); |
| } |
| void ExtensionLoaderHandler::HandleLoadUnpacked(const base::ListValue* args) { |
| @@ -178,18 +206,45 @@ void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) { |
| LoadUnpackedExtensionImpl(failed_path_); |
| } |
| +void ExtensionLoaderHandler::HandleSetDisplayLoading( |
| + const base::ListValue* args) { |
| + DCHECK(args->empty()); |
| + display_ready_ = false; |
| +} |
| + |
| +void ExtensionLoaderHandler::HandleDisplayFailures( |
| + const base::ListValue* args) { |
| + DCHECK(args->empty()); |
| + display_ready_ = true; |
| + if (!failures_.empty()) { |
|
Devlin
2014/06/27 22:31:09
instead of:
function {
if (condition) {
<lot
gpdavis
2014/06/27 23:42:54
That is indeed much better. Will fix (y)
gpdavis
2014/06/28 02:31:18
Done.
|
| + FailureData *failure = failures_[0]; |
|
Devlin
2014/06/27 22:31:09
nit: FailureData* failure
gpdavis
2014/06/28 02:31:18
Done.
|
| + NotifyFrontendOfFailure(failure->file_path, failure->error, |
|
Devlin
2014/06/27 22:31:09
one arg per line.
gpdavis
2014/06/28 02:31:18
Done.
|
| + failure->line_number, failure->manifest); |
| + |
| + std::string list("Additional failures:"); |
|
Devlin
2014/06/27 22:31:09
This needs to be i18n.
gpdavis
2014/06/28 02:31:18
Could you elaborate a little on this? I looked up
Devlin
2014/06/28 08:40:02
Ah, sorry :) i18n = internationalization. (See w
|
| + for (size_t i = 1; i < failures_.size(); i++) { |
|
Devlin
2014/06/27 22:31:09
++i.
gpdavis
2014/06/28 02:31:18
Done.
|
| + FailureData *failure = failures_[i]; |
| + list.append("\n"); |
| + list.append(failure->file_path.value()); |
|
Devlin
2014/06/27 22:31:10
Use one of the display functions in FilePath.
gpdavis
2014/06/27 23:42:54
Sounds good. LossyDisplayName seem reasonable?
Devlin
2014/06/28 08:40:02
Yep!
|
| + } |
| + failures_.clear(); |
|
Devlin
2014/06/27 22:31:09
Gaaah! Leaaaaaaak!
;)
But really. Leaks are bad
gpdavis
2014/06/27 23:42:54
I had a feeling there was going to be a memory lea
Devlin
2014/06/28 08:40:02
For vectors, take a look at scoped_vector.h. Hand
|
| + base::StringValue list_value(list); |
| + web_ui()->CallJavascriptFunction( |
| + "extensions.ExtensionLoader.notifyAdditional", |
| + list_value); |
|
Devlin
2014/06/27 22:31:09
If we go with this approach for multi errors, I th
gpdavis
2014/06/27 23:42:54
This is certainly going to require heavier UI adju
Devlin
2014/06/28 08:40:02
Sure, I'm not too worried about it. But the only
|
| + } |
| +} |
| + |
| void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( |
| const base::FilePath& file_path) { |
| scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( |
| ExtensionSystem::Get(profile_)->extension_service()); |
| - installer->set_on_failure_callback( |
| - base::Bind(&ExtensionLoaderHandler::OnLoadFailure, |
| - weak_ptr_factory_.GetWeakPtr())); |
| // We do our own error handling, so we don't want a load failure to trigger |
| // a dialog. |
| installer->set_be_noisy_on_failure(false); |
| + display_ready_ = true; |
|
Devlin
2014/06/27 22:31:10
This seems like an odd time to set |display_ready_
gpdavis
2014/06/28 02:31:18
Done.
|
| installer->Load(file_path); |
| } |
| @@ -227,6 +282,15 @@ void ExtensionLoaderHandler::NotifyFrontendOfFailure( |
| const std::string& error, |
| size_t line_number, |
| const std::string& manifest) { |
| + // If the extensions page is not loaded, delay frontend notification. |
| + if (!display_ready_) { |
| + failures_.push_back(new FailureData(file_path, |
| + error, |
| + line_number, |
| + manifest)); |
| + return; |
| + } |
| + |
| base::StringValue file_value(file_path.LossyDisplayName()); |
| base::StringValue error_value(base::UTF8ToUTF16(error)); |
| @@ -241,6 +305,7 @@ void ExtensionLoaderHandler::NotifyFrontendOfFailure( |
| file_value, |
| error_value, |
| manifest_value); |
| + display_ready_ = false; |
|
Devlin
2014/06/27 22:31:09
This too seems like an odd time to set display rea
gpdavis
2014/06/27 23:42:54
This was initially done because I started off impl
gpdavis
2014/06/28 02:31:18
Done.
|
| } |
| } // namespace extensions |