chrome_exts_command.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifndef TOOLS_WIN_CHROMEEXTS_CHROME_EXTS_COMMAND_H_
  5. #define TOOLS_WIN_CHROMEEXTS_CHROME_EXTS_COMMAND_H_
  6. #include <dbgeng.h>
  7. #include <stdarg.h>
  8. #include <wrl/client.h>
  9. #include <memory>
  10. #include <string>
  11. #include "base/macros.h"
  12. #include "base/memory/ptr_util.h"
  13. namespace tools {
  14. namespace win {
  15. namespace chromeexts {
  16. namespace {
  17. using Microsoft::WRL::ComPtr;
  18. } // namespace
  19. // Superclass of all commands in the debugger extension.
  20. // To implement your own command, just follow these steps:
  21. // 1) Create a new class and subclass ChromeExtsCommand.
  22. // 2) Implement Execute().
  23. // 3) Add a function that calls Run<Your Subclass>() to chromeexts.cc.
  24. // 4) Add your new function to the exports list in chromeexts.def.
  25. // Done!
  26. class ChromeExtsCommand {
  27. public:
  28. template <typename T>
  29. static HRESULT Run(IDebugClient* debug_client, const char* args) {
  30. std::unique_ptr<ChromeExtsCommand> command = std::make_unique<T>();
  31. HRESULT hr = command->Initialize(debug_client, args);
  32. if (SUCCEEDED(hr)) {
  33. hr = command->Execute();
  34. }
  35. return hr;
  36. }
  37. virtual ~ChromeExtsCommand();
  38. protected:
  39. ChromeExtsCommand();
  40. virtual HRESULT Initialize(IDebugClient* debug_client, const char* args);
  41. virtual HRESULT Execute() = 0;
  42. HRESULT Printf(const char* format, ...);
  43. HRESULT PrintV(const char* format, va_list ap);
  44. HRESULT PrintErrorf(const char* format, ...);
  45. HRESULT PrintErrorV(const char* format, va_list ap);
  46. const std::string& args() const { return args_; }
  47. IDebugClient* debug_client() { return debug_client_.Get(); }
  48. IDebugControl* debug_control() { return debug_control_.Get(); }
  49. private:
  50. std::string args_;
  51. ComPtr<IDebugClient> debug_client_;
  52. ComPtr<IDebugControl> debug_control_;
  53. DISALLOW_COPY_AND_ASSIGN(ChromeExtsCommand);
  54. };
  55. } // namespace chromeexts
  56. } // namespace win
  57. } // namespace tools
  58. #endif // TOOLS_WIN_CHROMEEXTS_CHROME_EXTS_COMMAND_H_