OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_ |
6 #define EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_ | 6 #define EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 class GURL; | |
11 | 12 |
12 namespace base { | 13 namespace base { |
14 class DictionaryValue; | |
13 class ListValue; | 15 class ListValue; |
14 } | 16 } |
15 | 17 |
18 namespace content { | |
19 class BrowserContext; | |
20 } | |
21 | |
16 namespace extensions { | 22 namespace extensions { |
23 namespace activity_monitor { | |
17 | 24 |
18 // ApiActivityMonitor is used to monitor extension API event dispatch and API | 25 using Monitor = void (*)(content::BrowserContext* browser_context, |
19 // function calls. An embedder can use this interface to log low-level extension | 26 const std::string& extension_id, |
20 // activity. | 27 const std::string& activity_name, |
21 class ApiActivityMonitor { | 28 const base::ListValue& event_args); |
22 public: | 29 using WebRequestMonitor = |
23 // Called when an API event is dispatched to an extension. | 30 void (*)(content::BrowserContext* browser_context, |
24 virtual void OnApiEventDispatched( | 31 const std::string& extension_id, |
25 const std::string& extension_id, | 32 const GURL& url, |
26 const std::string& event_name, | 33 bool is_incognito, |
27 std::unique_ptr<base::ListValue> event_args) = 0; | 34 const std::string& api_call, |
35 std::unique_ptr<base::DictionaryValue> details); | |
28 | 36 |
29 // Called when an extension calls an API function. | 37 // Get or set the current global monitor for API events and functions. Note that |
30 virtual void OnApiFunctionCalled(const std::string& extension_id, | 38 // these handlers *must* be allowed to be called on any thread! |
31 const std::string& api_name, | 39 Monitor GetApiEventMonitor(); |
32 std::unique_ptr<base::ListValue> args) = 0; | 40 Monitor GetApiFunctionMonitor(); |
41 WebRequestMonitor GetWebRequestMonitor(); | |
42 void SetApiEventMonitor(Monitor event_monitor); | |
43 void SetApiFunctionMonitor(Monitor function_monitor); | |
44 void SetWebRequestMonitor(WebRequestMonitor web_request_monitor); | |
33 | 45 |
34 protected: | 46 // Called when an API event is dispatched to an extension. May be called on any |
35 virtual ~ApiActivityMonitor() {} | 47 // thread. |
36 }; | 48 void OnApiEventDispatched(content::BrowserContext* browser_context, |
49 const std::string& extension_id, | |
50 const std::string& event_name, | |
51 const base::ListValue& event_args); | |
37 | 52 |
53 // Called when an extension calls an API function. May be called on any thread. | |
54 void OnApiFunctionCalled(content::BrowserContext* browser_context, | |
55 const std::string& extension_id, | |
56 const std::string& api_name, | |
57 const base::ListValue& args); | |
58 | |
59 // Called when an extension uses the web request API. | |
asargent_no_longer_on_chrome
2016/06/20 22:13:11
Looks like this can be called from IO thread - wor
Devlin
2016/06/21 17:07:51
Added more comments.
| |
60 void OnWebRequestApiUsed(content::BrowserContext* browser_context, | |
61 const std::string& extension_id, | |
62 const GURL& url, | |
63 bool is_incognito, | |
64 const std::string& api_call, | |
65 std::unique_ptr<base::DictionaryValue> details); | |
66 | |
67 } // namespace activity_monitor | |
38 } // namespace extensions | 68 } // namespace extensions |
39 | 69 |
40 #endif // EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_ | 70 #endif // EXTENSIONS_BROWSER_API_ACTIVITY_MONITOR_H_ |
OLD | NEW |