OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef TOOLS_GN_LOADER_H_ | 5 #ifndef TOOLS_GN_LOADER_H_ |
6 #define TOOLS_GN_LOADER_H_ | 6 #define TOOLS_GN_LOADER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/single_thread_task_runner.h" |
14 #include "tools/gn/label.h" | 15 #include "tools/gn/label.h" |
15 #include "tools/gn/scope.h" | 16 #include "tools/gn/scope.h" |
16 | 17 |
17 namespace base { | |
18 class MessageLoop; | |
19 } | |
20 | |
21 class BuildSettings; | 18 class BuildSettings; |
22 class LocationRange; | 19 class LocationRange; |
23 class Settings; | 20 class Settings; |
24 class SourceFile; | 21 class SourceFile; |
25 class Toolchain; | 22 class Toolchain; |
26 | 23 |
27 // The loader manages execution of the different build files. It receives | 24 // The loader manages execution of the different build files. It receives |
28 // requests (normally from the Builder) when new references are found, and also | 25 // requests (normally from the Builder) when new references are found, and also |
29 // manages loading the build config files. | 26 // manages loading the build config files. |
30 // | 27 // |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 explicit LoaderImpl(const BuildSettings* build_settings); | 80 explicit LoaderImpl(const BuildSettings* build_settings); |
84 | 81 |
85 // Loader implementation. | 82 // Loader implementation. |
86 void Load(const SourceFile& file, | 83 void Load(const SourceFile& file, |
87 const LocationRange& origin, | 84 const LocationRange& origin, |
88 const Label& toolchain_name) override; | 85 const Label& toolchain_name) override; |
89 void ToolchainLoaded(const Toolchain* toolchain) override; | 86 void ToolchainLoaded(const Toolchain* toolchain) override; |
90 Label GetDefaultToolchain() const override; | 87 Label GetDefaultToolchain() const override; |
91 const Settings* GetToolchainSettings(const Label& label) const override; | 88 const Settings* GetToolchainSettings(const Label& label) const override; |
92 | 89 |
93 // Sets the message loop corresponding to the main thread. By default this | 90 // Sets the task runner corresponding to the main thread. By default this |
94 // class will use the thread active during construction, but there is not | 91 // class will use the thread active during construction, but there is not |
95 // a message loop active during construction all the time. | 92 // a task runner active during construction all the time. |
96 void set_main_loop(base::MessageLoop* loop) { main_loop_ = loop; } | 93 void set_task_runner( |
| 94 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 95 task_runner_ = task_runner; |
| 96 } |
97 | 97 |
98 // The complete callback is called whenever there are no more pending loads. | 98 // The complete callback is called whenever there are no more pending loads. |
99 // Called on the main thread only. This may be called more than once if the | 99 // Called on the main thread only. This may be called more than once if the |
100 // queue is drained, but then more stuff gets added. | 100 // queue is drained, but then more stuff gets added. |
101 void set_complete_callback(const base::Closure& cb) { | 101 void set_complete_callback(const base::Closure& cb) { |
102 complete_callback_ = cb; | 102 complete_callback_ = cb; |
103 } | 103 } |
104 | 104 |
105 // This callback is used when the loader finds it wants to load a file. | 105 // This callback is used when the loader finds it wants to load a file. |
106 void set_async_load_file(const AsyncLoadFileCallback& cb) { | 106 void set_async_load_file(const AsyncLoadFileCallback& cb) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // necessary. | 152 // necessary. |
153 void DecrementPendingLoads(); | 153 void DecrementPendingLoads(); |
154 | 154 |
155 // Forwards to the appropriate location to load the file. | 155 // Forwards to the appropriate location to load the file. |
156 bool AsyncLoadFile(const LocationRange& origin, | 156 bool AsyncLoadFile(const LocationRange& origin, |
157 const BuildSettings* build_settings, | 157 const BuildSettings* build_settings, |
158 const SourceFile& file_name, | 158 const SourceFile& file_name, |
159 const base::Callback<void(const ParseNode*)>& callback, | 159 const base::Callback<void(const ParseNode*)>& callback, |
160 Err* err); | 160 Err* err); |
161 | 161 |
162 base::MessageLoop* main_loop_; | 162 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
163 | 163 |
164 int pending_loads_; | 164 int pending_loads_; |
165 base::Closure complete_callback_; | 165 base::Closure complete_callback_; |
166 | 166 |
167 // When non-null, use this callback instead of the InputFileManager for | 167 // When non-null, use this callback instead of the InputFileManager for |
168 // mocking purposes. | 168 // mocking purposes. |
169 AsyncLoadFileCallback async_load_file_; | 169 AsyncLoadFileCallback async_load_file_; |
170 | 170 |
171 typedef std::set<LoadID> LoadIDSet; | 171 typedef std::set<LoadID> LoadIDSet; |
172 LoadIDSet invocations_; | 172 LoadIDSet invocations_; |
173 | 173 |
174 const BuildSettings* build_settings_; | 174 const BuildSettings* build_settings_; |
175 Label default_toolchain_label_; | 175 Label default_toolchain_label_; |
176 | 176 |
177 // Records for the build config file loads. | 177 // Records for the build config file loads. |
178 typedef std::map<Label, std::unique_ptr<ToolchainRecord>> ToolchainRecordMap; | 178 typedef std::map<Label, std::unique_ptr<ToolchainRecord>> ToolchainRecordMap; |
179 ToolchainRecordMap toolchain_records_; | 179 ToolchainRecordMap toolchain_records_; |
180 }; | 180 }; |
181 | 181 |
182 #endif // TOOLS_GN_LOADER_H_ | 182 #endif // TOOLS_GN_LOADER_H_ |
OLD | NEW |