Index: chrome/browser/conflicts/module_inspector_win.h |
diff --git a/chrome/browser/conflicts/module_inspector_win.h b/chrome/browser/conflicts/module_inspector_win.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3a036d69dc97e733cdc2640bf6cf2793a2b5f88b |
--- /dev/null |
+++ b/chrome/browser/conflicts/module_inspector_win.h |
@@ -0,0 +1,81 @@ |
+// Copyright 2017 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 CHROME_BROWSER_CONFLICTS_MODULE_INSPECTOR_WIN_H_ |
+#define CHROME_BROWSER_CONFLICTS_MODULE_INSPECTOR_WIN_H_ |
+ |
+#include <memory> |
+#include <queue> |
+ |
+#include "base/callback.h" |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/task_scheduler/task_traits.h" |
+#include "base/threading/thread_checker.h" |
+#include "chrome/browser/conflicts/module_info_win.h" |
+ |
+// This class takes care of inspecting several modules (identified by their |
+// ModuleInfoKey) and returning the result via the OnModuleInspectedCallback on |
+// the SequencedTaskRunner where it was created. |
+// |
+// The inspection of all modules is quite expensive in terms of resources, so it |
+// is done one by one, in a task with a background priority level. If needed, it |
+// is possible to increase the priority level of these tasks by calling |
+// IncreaseInspectionPriority(). |
+// |
+// This class is not thread safe and it enforces safety via a ThreadChecker. |
+class ModuleInspector { |
+ public: |
+ using OnModuleInspectedCallback = |
+ base::Callback<void(const ModuleInfoKey& module_key, |
+ std::unique_ptr<ModuleInspectionResult>)>; |
+ |
+ explicit ModuleInspector( |
+ const OnModuleInspectedCallback& on_module_inspected_callback); |
+ ~ModuleInspector(); |
+ |
+ // Adds the module to the queue of modules to inspect. Starts the inspection |
+ // process if the |queue_| is empty. |
+ void AddModule(const ModuleInfoKey& module_key); |
+ |
+ // Removes the throttling. |
+ void IncreaseInspectionPriority(); |
+ |
+ private: |
+ // Starts inspecting the module at the front of the queue. |
+ void StartInspectingModule(); |
+ |
+ // Called back on the execution context on which the ModuleInspector was |
+ // created when a module has finished being inspected. The callback will be |
+ // executed and, if the |queue_| is not empty, the next module will be sent |
+ // for inspection. |
+ void OnInspectionFinished( |
+ const ModuleInfoKey& module_key, |
+ std::unique_ptr<ModuleInspectionResult> inspection_result); |
+ |
+ OnModuleInspectedCallback on_module_inspected_callback_; |
+ |
+ // The modules are put in queue until they are sent for inspection. |
+ std::queue<ModuleInfoKey> queue_; |
+ |
+ // The traits used on the task that inspects the modules. It originally starts |
+ // at a BACKGROUND priority, but is changed to USER_VISIBLE when |
+ // IncreaseInspectionPriority() is called. |
+ base::TaskTraits inspection_task_traits_; |
+ |
+ // The vector of paths to %env_var%, used to account for differences in |
+ // localization and where people keep their files. |
+ // e.g. c:\windows vs d:\windows |
+ StringMapping path_mapping_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ // Weak pointers are used to safely post the inspection result back to the |
+ // ModuleInspector from the task scheduler. |
+ base::WeakPtrFactory<ModuleInspector> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ModuleInspector); |
+}; |
+ |
+#endif // CHROME_BROWSER_CONFLICTS_MODULE_INSPECTOR_WIN_H_ |