| 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/file_module_provider.h" | 5 #include "gin/modules/file_module_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 path = path.AppendASCII(components[i]); | 30 path = path.AppendASCII(components[i]); |
| 31 } | 31 } |
| 32 path = path.AddExtension(FILE_PATH_LITERAL("js")); | 32 path = path.AddExtension(FILE_PATH_LITERAL("js")); |
| 33 | 33 |
| 34 for (size_t i = 0; i < search_paths.size(); ++i) { | 34 for (size_t i = 0; i < search_paths.size(); ++i) { |
| 35 std::string source; | 35 std::string source; |
| 36 if (!ReadFileToString(search_paths[i].Append(path), &source)) | 36 if (!ReadFileToString(search_paths[i].Append(path), &source)) |
| 37 continue; | 37 continue; |
| 38 | 38 |
| 39 Runner::Scope scope(runner.get()); | 39 Runner::Scope scope(runner.get()); |
| 40 v8::Handle<v8::Script> script = v8::Script::New( | 40 runner->Run(source, id); |
| 41 StringToV8(runner->isolate(), source), | |
| 42 StringToV8(runner->isolate(), id)); | |
| 43 runner->Run(script); | |
| 44 return; | 41 return; |
| 45 } | 42 } |
| 46 } | 43 } |
| 47 | 44 |
| 48 } // namespace | 45 } // namespace |
| 49 | 46 |
| 50 FileModuleProvider::FileModuleProvider( | 47 FileModuleProvider::FileModuleProvider( |
| 51 const std::vector<base::FilePath>& search_paths) | 48 const std::vector<base::FilePath>& search_paths) |
| 52 : search_paths_(search_paths) { | 49 : search_paths_(search_paths) { |
| 53 } | 50 } |
| 54 | 51 |
| 55 FileModuleProvider::~FileModuleProvider() { | 52 FileModuleProvider::~FileModuleProvider() { |
| 56 } | 53 } |
| 57 | 54 |
| 58 void FileModuleProvider::AttempToLoadModules( | 55 void FileModuleProvider::AttempToLoadModules( |
| 59 Runner* runner, const std::set<std::string>& ids) { | 56 Runner* runner, const std::set<std::string>& ids) { |
| 60 std::set<std::string> modules = ids; | 57 std::set<std::string> modules = ids; |
| 61 for (std::set<std::string>::const_iterator it = modules.begin(); | 58 for (std::set<std::string>::const_iterator it = modules.begin(); |
| 62 it != modules.end(); ++it) { | 59 it != modules.end(); ++it) { |
| 63 const std::string& id = *it; | 60 const std::string& id = *it; |
| 64 if (attempted_ids_.count(id)) | 61 if (attempted_ids_.count(id)) |
| 65 continue; | 62 continue; |
| 66 attempted_ids_.insert(id); | 63 attempted_ids_.insert(id); |
| 67 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 64 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 68 AttempToLoadModule, runner->GetWeakPtr(), search_paths_, id)); | 65 AttempToLoadModule, runner->GetWeakPtr(), search_paths_, id)); |
| 69 } | 66 } |
| 70 } | 67 } |
| 71 | 68 |
| 72 } // namespace gin | 69 } // namespace gin |
| OLD | NEW |