| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gin/modules/module_registry.h" | 5 #include "gin/modules/module_registry.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "gin/arguments.h" | 15 #include "gin/arguments.h" |
| 15 #include "gin/converter.h" | 16 #include "gin/converter.h" |
| 16 #include "gin/modules/module_registry_observer.h" | 17 #include "gin/modules/module_registry_observer.h" |
| 17 #include "gin/per_context_data.h" | 18 #include "gin/per_context_data.h" |
| 18 #include "gin/per_isolate_data.h" | 19 #include "gin/per_isolate_data.h" |
| 19 #include "gin/public/wrapper_info.h" | 20 #include "gin/public/wrapper_info.h" |
| 20 #include "gin/runner.h" | 21 #include "gin/runner.h" |
| 21 | 22 |
| 22 using v8::Context; | 23 using v8::Context; |
| 23 using v8::External; | 24 using v8::External; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 PerContextData* data = PerContextData::From(context); | 133 PerContextData* data = PerContextData::From(context); |
| 133 if (!data) | 134 if (!data) |
| 134 return NULL; | 135 return NULL; |
| 135 | 136 |
| 136 ModuleRegistryData* registry_data = static_cast<ModuleRegistryData*>( | 137 ModuleRegistryData* registry_data = static_cast<ModuleRegistryData*>( |
| 137 data->GetUserData(kModuleRegistryKey)); | 138 data->GetUserData(kModuleRegistryKey)); |
| 138 if (!registry_data) { | 139 if (!registry_data) { |
| 139 // PerContextData takes ownership of ModuleRegistryData. | 140 // PerContextData takes ownership of ModuleRegistryData. |
| 140 registry_data = new ModuleRegistryData; | 141 registry_data = new ModuleRegistryData; |
| 141 registry_data->registry.reset(new ModuleRegistry(context->GetIsolate())); | 142 registry_data->registry.reset(new ModuleRegistry(context->GetIsolate())); |
| 142 data->SetUserData(kModuleRegistryKey, registry_data); | 143 data->SetUserData(kModuleRegistryKey, base::WrapUnique(registry_data)); |
| 143 } | 144 } |
| 144 return registry_data->registry.get(); | 145 return registry_data->registry.get(); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void ModuleRegistry::AddObserver(ModuleRegistryObserver* observer) { | 148 void ModuleRegistry::AddObserver(ModuleRegistryObserver* observer) { |
| 148 observer_list_.AddObserver(observer); | 149 observer_list_.AddObserver(observer); |
| 149 } | 150 } |
| 150 | 151 |
| 151 void ModuleRegistry::RemoveObserver(ModuleRegistryObserver* observer) { | 152 void ModuleRegistry::RemoveObserver(ModuleRegistryObserver* observer) { |
| 152 observer_list_.RemoveObserver(observer); | 153 observer_list_.RemoveObserver(observer); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 for (size_t i = 0; i < pending_modules.size(); ++i) { | 281 for (size_t i = 0; i < pending_modules.size(); ++i) { |
| 281 std::unique_ptr<PendingModule> pending(pending_modules[i]); | 282 std::unique_ptr<PendingModule> pending(pending_modules[i]); |
| 282 pending_modules[i] = NULL; | 283 pending_modules[i] = NULL; |
| 283 if (AttemptToLoad(isolate, std::move(pending))) | 284 if (AttemptToLoad(isolate, std::move(pending))) |
| 284 keep_trying = true; | 285 keep_trying = true; |
| 285 } | 286 } |
| 286 } | 287 } |
| 287 } | 288 } |
| 288 | 289 |
| 289 } // namespace gin | 290 } // namespace gin |
| OLD | NEW |