Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Unified Diff: chrome/browser/conflicts/module_inspector_win.h

Issue 2721503003: Add ModuleInspector (Closed)
Patch Set: merge Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/conflicts/module_info_win.cc ('k') | chrome/browser/conflicts/module_inspector_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « chrome/browser/conflicts/module_info_win.cc ('k') | chrome/browser/conflicts/module_inspector_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698