| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_EXTENSIONS_EXTENSION_ACTIVITY_LOG_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTIVITY_LOG_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "base/observer_list_threadsafe.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 | |
| 15 namespace extensions { | |
| 16 class Extension; | |
| 17 } | |
| 18 | |
| 19 // A utility for tracing interesting activity for each extension. | |
| 20 class ExtensionActivityLog { | |
| 21 public: | |
| 22 enum Activity { | |
| 23 ACTIVITY_EXTENSION_API_CALL, // Extension API invocation is called. | |
| 24 ACTIVITY_EXTENSION_API_BLOCK // Extension API invocation is blocked. | |
| 25 }; | |
| 26 | |
| 27 // Observers can listen for activity events. | |
| 28 class Observer { | |
| 29 public: | |
| 30 virtual void OnExtensionActivity(const extensions::Extension* extension, | |
| 31 Activity activity, | |
| 32 const std::string& msg) = 0; | |
| 33 }; | |
| 34 | |
| 35 ~ExtensionActivityLog(); | |
| 36 static ExtensionActivityLog* GetInstance(); | |
| 37 | |
| 38 // Add/remove observer. | |
| 39 void AddObserver(const extensions::Extension* extension, Observer* observer); | |
| 40 void RemoveObserver(const extensions::Extension* extension, | |
| 41 Observer* observer); | |
| 42 | |
| 43 // Check for the existence observer list by extension_id. | |
| 44 bool HasObservers(const extensions::Extension* extension) const; | |
| 45 | |
| 46 // Log |activity| for |extension|. | |
| 47 void Log(const extensions::Extension* extension, | |
| 48 Activity activity, | |
| 49 const std::string& msg) const; | |
| 50 | |
| 51 private: | |
| 52 ExtensionActivityLog(); | |
| 53 friend struct DefaultSingletonTraits<ExtensionActivityLog>; | |
| 54 | |
| 55 static const char* ActivityToString(Activity activity); | |
| 56 | |
| 57 // A lock used to synchronize access to member variables. | |
| 58 mutable base::Lock lock_; | |
| 59 | |
| 60 // Whether to log activity to stdout. This is set by checking the | |
| 61 // enable-extension-activity-logging switch. | |
| 62 bool log_activity_to_stdout_; | |
| 63 | |
| 64 typedef ObserverListThreadSafe<Observer> ObserverList; | |
| 65 typedef std::map<const extensions::Extension*, scoped_refptr<ObserverList> > | |
| 66 ObserverMap; | |
| 67 // A map of extensions to activity observers for that extension. | |
| 68 ObserverMap observers_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(ExtensionActivityLog); | |
| 71 }; | |
| 72 | |
| 73 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTIVITY_LOG_H_ | |
| OLD | NEW |