Chromium Code Reviews| Index: gin/modules/file_module_provider.cc |
| diff --git a/gin/modules/file_module_provider.cc b/gin/modules/file_module_provider.cc |
| index 660d9b1b9ac2e2a1e60f56cc78827abc0975fce3..dfadf8e6a5a54c01eaeabb531fa1fa5d93de62c3 100644 |
| --- a/gin/modules/file_module_provider.cc |
| +++ b/gin/modules/file_module_provider.cc |
| @@ -14,11 +14,14 @@ namespace gin { |
| namespace { |
| -void AttempToLoadModule(const base::WeakPtr<Runner>& runner, |
| - const std::vector<base::FilePath>& search_paths, |
| - const std::string& id) { |
| - if (!runner) |
| +void AttemptToLoadModule(const base::WeakPtr<Runner>& runner, |
| + const std::vector<base::FilePath>& search_paths, |
| + const std::string& id, |
| + base::Callback<void(bool)> callback) { |
| + if (!runner) { |
| + callback.Run(false); |
| return; |
| + } |
| std::vector<std::string> components; |
| base::SplitString(id, '/', &components); |
| @@ -38,21 +41,23 @@ void AttempToLoadModule(const base::WeakPtr<Runner>& runner, |
| Runner::Scope scope(runner.get()); |
| runner->Run(source, id); |
| + callback.Run(true); |
| return; |
| } |
| + callback.Run(false); |
|
abarth-chromium
2014/07/22 22:16:15
Maybe we should just log something at this point a
Matt Perry
2014/07/22 22:24:40
Huh.. I thought I tried that and it resulted in fa
|
| } |
| } // namespace |
| FileModuleProvider::FileModuleProvider( |
| const std::vector<base::FilePath>& search_paths) |
| - : search_paths_(search_paths) { |
| + : weak_factory_(this), search_paths_(search_paths) { |
| } |
| FileModuleProvider::~FileModuleProvider() { |
| } |
| -void FileModuleProvider::AttempToLoadModules( |
| +void FileModuleProvider::AttemptToLoadModules( |
| Runner* runner, const std::set<std::string>& ids) { |
| std::set<std::string> modules = ids; |
| for (std::set<std::string>::const_iterator it = modules.begin(); |
| @@ -62,7 +67,22 @@ void FileModuleProvider::AttempToLoadModules( |
| continue; |
| attempted_ids_.insert(id); |
| base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| - AttempToLoadModule, runner->GetWeakPtr(), search_paths_, id)); |
| + AttemptToLoadModule, runner->GetWeakPtr(), search_paths_, id, |
| + base::Bind(&FileModuleProvider::OnReadCompleted, |
| + weak_factory_.GetWeakPtr(), id))); |
| + } |
| +} |
| + |
| +void FileModuleProvider::OnReadCompleted(const std::string& id, bool success) { |
| + if (success) { |
| + successful_ids_.insert(id); |
| + } else { |
| + failed_ids_.insert(id); |
| + } |
| + |
| + if (failed_ids_.size() + successful_ids_.size() == attempted_ids_.size()) { |
| + if (!completion_callback_.is_null()) |
| + completion_callback_.Run(successful_ids_); |
| } |
| } |