| OLD | NEW | 
| (Empty) |  | 
 |   1 // Copyright 2017 The Chromium Authors. All rights reserved. | 
 |   2 // Use of this source code is governed by a BSD-style license that can be | 
 |   3 // found in the LICENSE file. | 
 |   4  | 
 |   5 #ifndef CHROME_BROWSER_CONFLICTS_MODULE_INSPECTOR_WIN_H_ | 
 |   6 #define CHROME_BROWSER_CONFLICTS_MODULE_INSPECTOR_WIN_H_ | 
 |   7  | 
 |   8 #include <memory> | 
 |   9 #include <queue> | 
 |  10  | 
 |  11 #include "base/callback.h" | 
 |  12 #include "base/macros.h" | 
 |  13 #include "base/memory/weak_ptr.h" | 
 |  14 #include "base/task_scheduler/task_traits.h" | 
 |  15 #include "base/threading/thread_checker.h" | 
 |  16 #include "chrome/browser/conflicts/module_info_win.h" | 
 |  17  | 
 |  18 // This class takes care of inspecting several modules (identified by their | 
 |  19 // ModuleInfoKey) and returning the result via the OnModuleInspectedCallback on | 
 |  20 // the SequencedTaskRunner where it was created. | 
 |  21 // | 
 |  22 // The inspection of all modules is quite expensive in terms of resources, so it | 
 |  23 // is done one by one, in a task with a background priority level. If needed, it | 
 |  24 // is possible to increase the priority level of these tasks by calling | 
 |  25 // IncreaseInspectionPriority(). | 
 |  26 // | 
 |  27 // This class is not thread safe and it enforces safety via a ThreadChecker. | 
 |  28 class ModuleInspector { | 
 |  29  public: | 
 |  30   using OnModuleInspectedCallback = | 
 |  31       base::Callback<void(const ModuleInfoKey& module_key, | 
 |  32                           std::unique_ptr<ModuleInspectionResult>)>; | 
 |  33  | 
 |  34   explicit ModuleInspector( | 
 |  35       const OnModuleInspectedCallback& on_module_inspected_callback); | 
 |  36   ~ModuleInspector(); | 
 |  37  | 
 |  38   // Adds the module to the queue of modules to inspect. Starts the inspection | 
 |  39   // process if the |queue_| is empty. | 
 |  40   void AddModule(const ModuleInfoKey& module_key); | 
 |  41  | 
 |  42   // Removes the throttling. | 
 |  43   void IncreaseInspectionPriority(); | 
 |  44  | 
 |  45  private: | 
 |  46   // Starts inspecting the module at the front of the queue. | 
 |  47   void StartInspectingModule(); | 
 |  48  | 
 |  49   // Called back on the execution context on which the ModuleInspector was | 
 |  50   // created when a module has finished being inspected. The callback will be | 
 |  51   // executed and, if the |queue_| is not empty, the next module will be sent | 
 |  52   // for inspection. | 
 |  53   void OnInspectionFinished( | 
 |  54       const ModuleInfoKey& module_key, | 
 |  55       std::unique_ptr<ModuleInspectionResult> inspection_result); | 
 |  56  | 
 |  57   OnModuleInspectedCallback on_module_inspected_callback_; | 
 |  58  | 
 |  59   // The modules are put in queue until they are sent for inspection. | 
 |  60   std::queue<ModuleInfoKey> queue_; | 
 |  61  | 
 |  62   // The traits used on the task that inspects the modules. It originally starts | 
 |  63   // at a BACKGROUND priority, but is changed to USER_VISIBLE when | 
 |  64   // IncreaseInspectionPriority() is called. | 
 |  65   base::TaskTraits inspection_task_traits_; | 
 |  66  | 
 |  67   // The vector of paths to %env_var%, used to account for differences in | 
 |  68   // localization and where people keep their files. | 
 |  69   // e.g. c:\windows vs d:\windows | 
 |  70   StringMapping path_mapping_; | 
 |  71  | 
 |  72   base::ThreadChecker thread_checker_; | 
 |  73  | 
 |  74   // Weak pointers are used to safely post the inspection result back to the | 
 |  75   // ModuleInspector from the task scheduler. | 
 |  76   base::WeakPtrFactory<ModuleInspector> weak_ptr_factory_; | 
 |  77  | 
 |  78   DISALLOW_COPY_AND_ASSIGN(ModuleInspector); | 
 |  79 }; | 
 |  80  | 
 |  81 #endif  // CHROME_BROWSER_CONFLICTS_MODULE_INSPECTOR_WIN_H_ | 
| OLD | NEW |