api_activity_monitor.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2014 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 EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_
  5. #define EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/values.h"
  9. class GURL;
  10. namespace content {
  11. class BrowserContext;
  12. }
  13. namespace extensions {
  14. namespace activity_monitor {
  15. using Monitor = void (*)(content::BrowserContext* browser_context,
  16. const std::string& extension_id,
  17. const std::string& activity_name,
  18. const base::Value::List& event_args);
  19. using WebRequestMonitor =
  20. void (*)(content::BrowserContext* browser_context,
  21. const std::string& extension_id,
  22. const GURL& url,
  23. bool is_incognito,
  24. const std::string& api_call,
  25. std::unique_ptr<base::DictionaryValue> details);
  26. // Get or set the current global monitor for API events and functions. Note that
  27. // these handlers *must* be allowed to be called on any thread!
  28. // Additionally, since this may be called on any thead, |browser_context| is
  29. // unsafe to use unless posted to the UI thread.
  30. Monitor GetApiEventMonitor();
  31. Monitor GetApiFunctionMonitor();
  32. WebRequestMonitor GetWebRequestMonitor();
  33. void SetApiEventMonitor(Monitor event_monitor);
  34. void SetApiFunctionMonitor(Monitor function_monitor);
  35. void SetWebRequestMonitor(WebRequestMonitor web_request_monitor);
  36. // Called when an API event is dispatched to an extension. May be called on any
  37. // thread. |browser_context| is unsafe to use.
  38. void OnApiEventDispatched(content::BrowserContext* browser_context,
  39. const std::string& extension_id,
  40. const std::string& event_name,
  41. const base::Value::List& event_args);
  42. // Called when an extension calls an API function. May be called on any thread.
  43. // |browser_context| is unsafe to use.
  44. void OnApiFunctionCalled(content::BrowserContext* browser_context,
  45. const std::string& extension_id,
  46. const std::string& api_name,
  47. const base::Value::List& args);
  48. // Called when an extension uses the web request API. May be called on any
  49. // thread. |browser_context| is unsafe to use.
  50. void OnWebRequestApiUsed(content::BrowserContext* browser_context,
  51. const std::string& extension_id,
  52. const GURL& url,
  53. bool is_incognito,
  54. const std::string& api_call,
  55. std::unique_ptr<base::DictionaryValue> details);
  56. } // namespace activity_monitor
  57. } // namespace extensions
  58. #endif // EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_