• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_
6 #define EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_
7 
8 #include <string>
9 
10 #include "extensions/common/features/feature.h"
11 #include "extensions/renderer/object_backed_native_handler.h"
12 #include "v8/include/v8.h"
13 
14 namespace extensions {
15 
16 // Used to log extension API calls and events that are implemented with custom
17 // bindings.The actions are sent via IPC to extensions::ActivityLog for
18 // recording and display.
19 class APIActivityLogger : public ObjectBackedNativeHandler {
20  public:
21   explicit APIActivityLogger(ScriptContext* context);
22 
23  private:
24   // Used to distinguish API calls & events from each other in LogInternal.
25   enum CallType { APICALL, EVENT };
26 
27   // This is ultimately invoked in bindings.js with JavaScript arguments.
28   //    arg0 - extension ID as a string
29   //    arg1 - API call name as a string
30   //    arg2 - arguments to the API call
31   //    arg3 - any extra logging info as a string (optional)
32   static void LogAPICall(const v8::FunctionCallbackInfo<v8::Value>& args);
33 
34   // This is ultimately invoked in bindings.js with JavaScript arguments.
35   //    arg0 - extension ID as a string
36   //    arg1 - Event name as a string
37   //    arg2 - Event arguments
38   //    arg3 - any extra logging info as a string (optional)
39   static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
40 
41   // LogAPICall and LogEvent are really the same underneath except for
42   // how they are ultimately dispatched to the log.
43   static void LogInternal(const CallType call_type,
44                           const v8::FunctionCallbackInfo<v8::Value>& args);
45 
46   DISALLOW_COPY_AND_ASSIGN(APIActivityLogger);
47 };
48 
49 }  // namespace extensions
50 
51 #endif  // EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_
52