forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove AMD-style module support from gin/."
This reverts commit c1ab49a. Reason for revert: Likely the cause of RunnerTest.Run failure in gin_unittests: Check failed: (isolate->snapshot_blob()) == nullptr. Original change's description: > Remove AMD-style module support from gin/. > > Bug: 718047 > Change-Id: If480fff65a2e5993ed5143eede8354f890de3a3b > Reviewed-on: https://chromium-review.googlesource.com/812172 > Commit-Queue: Yuzhu Shen <yzshen@chromium.org> > Reviewed-by: Jochen Eisinger <jochen@chromium.org> > Cr-Commit-Position: refs/heads/master@{#522850} TBR=yzshen@chromium.org,jochen@chromium.org Change-Id: I4a6efb21dd7972994a06ddab1316fa43e5d3e060 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: 718047, 793480 Reviewed-on: https://chromium-review.googlesource.com/817373 Reviewed-by: Yuzhu Shen <yzshen@chromium.org> Commit-Queue: Yuzhu Shen <yzshen@chromium.org> Cr-Commit-Position: refs/heads/master@{#522921}
- Loading branch information
Showing
33 changed files
with
2,064 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "gin/modules/file_module_provider.h" | ||
|
||
#include <stddef.h> | ||
|
||
#include "base/bind.h" | ||
#include "base/files/file_util.h" | ||
#include "base/location.h" | ||
#include "base/single_thread_task_runner.h" | ||
#include "base/strings/string_split.h" | ||
#include "base/threading/thread_task_runner_handle.h" | ||
#include "gin/converter.h" | ||
|
||
namespace gin { | ||
|
||
namespace { | ||
|
||
void AttempToLoadModule(const base::WeakPtr<Runner>& runner, | ||
const std::vector<base::FilePath>& search_paths, | ||
const std::string& id) { | ||
if (!runner) | ||
return; | ||
|
||
std::vector<std::string> components = base::SplitString( | ||
id, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | ||
|
||
base::FilePath path; | ||
for (size_t i = 0; i < components.size(); ++i) { | ||
// TODO(abarth): Technically the path components can be UTF-8. We don't | ||
// handle that case correctly yet. | ||
path = path.AppendASCII(components[i]); | ||
} | ||
path = path.AddExtension(FILE_PATH_LITERAL("js")); | ||
|
||
for (size_t i = 0; i < search_paths.size(); ++i) { | ||
std::string source; | ||
if (!ReadFileToString(search_paths[i].Append(path), &source)) | ||
continue; | ||
|
||
Runner::Scope scope(runner.get()); | ||
runner->Run(source, id); | ||
return; | ||
} | ||
LOG(ERROR) << "Failed to load module from disk: " << id; | ||
} | ||
|
||
} // namespace | ||
|
||
FileModuleProvider::FileModuleProvider( | ||
const std::vector<base::FilePath>& search_paths) | ||
: search_paths_(search_paths) { | ||
} | ||
|
||
FileModuleProvider::~FileModuleProvider() = default; | ||
|
||
void FileModuleProvider::AttempToLoadModules( | ||
Runner* runner, const std::set<std::string>& ids) { | ||
std::set<std::string> modules = ids; | ||
for (std::set<std::string>::const_iterator it = modules.begin(); | ||
it != modules.end(); ++it) { | ||
const std::string& id = *it; | ||
if (attempted_ids_.count(id)) | ||
continue; | ||
attempted_ids_.insert(id); | ||
base::ThreadTaskRunnerHandle::Get()->PostTask( | ||
FROM_HERE, base::Bind(AttempToLoadModule, runner->GetWeakPtr(), | ||
search_paths_, id)); | ||
} | ||
} | ||
|
||
} // namespace gin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef GIN_MODULES_FILE_MODULE_PROVIDER_H_ | ||
#define GIN_MODULES_FILE_MODULE_PROVIDER_H_ | ||
|
||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/macros.h" | ||
#include "gin/gin_export.h" | ||
#include "gin/runner.h" | ||
|
||
namespace gin { | ||
|
||
// FileModuleProvider knows how to load AMD modules off disk. It searches for | ||
// modules in the directories indiciated by |search_paths|. Although we still | ||
// read from the file system on the main thread, we'll eventually want to move | ||
// the reads to a background thread. | ||
class GIN_EXPORT FileModuleProvider { | ||
public: | ||
explicit FileModuleProvider( | ||
const std::vector<base::FilePath>& search_paths); | ||
~FileModuleProvider(); | ||
|
||
// Searches for modules with |ids| in the file system. If found, the modules | ||
// will be executed asynchronously by |runner|. | ||
void AttempToLoadModules(Runner* runner, const std::set<std::string>& ids); | ||
|
||
private: | ||
std::vector<base::FilePath> search_paths_; | ||
|
||
// We'll only search for a given module once. We remember the set of modules | ||
// we've already looked for in |attempted_ids_|. | ||
std::set<std::string> attempted_ids_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(FileModuleProvider); | ||
}; | ||
|
||
} // namespace gin | ||
|
||
#endif // GIN_MODULES_FILE_MODULE_PROVIDER_H_ |
Oops, something went wrong.