Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: chrome/browser/extensions/activity_log.cc

Issue 10824198: Move small c/b/extensions classes into extensions namespace no.1 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest-er master for cq Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/extensions/extension_activity_log.h" 5 #include "chrome/browser/extensions/activity_log.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 11
12 ExtensionActivityLog::ExtensionActivityLog() { 12 namespace extensions {
13
14 ActivityLog::ActivityLog() {
13 log_activity_to_stdout_ = CommandLine::ForCurrentProcess()-> 15 log_activity_to_stdout_ = CommandLine::ForCurrentProcess()->
14 HasSwitch(switches::kEnableExtensionActivityLogging); 16 HasSwitch(switches::kEnableExtensionActivityLogging);
15 } 17 }
16 18
17 ExtensionActivityLog::~ExtensionActivityLog() { 19 ActivityLog::~ActivityLog() {
18 } 20 }
19 21
20 // static 22 // static
21 ExtensionActivityLog* ExtensionActivityLog::GetInstance() { 23 ActivityLog* ActivityLog::GetInstance() {
22 return Singleton<ExtensionActivityLog>::get(); 24 return Singleton<ActivityLog>::get();
23 } 25 }
24 26
25 void ExtensionActivityLog::AddObserver( 27 void ActivityLog::AddObserver(const Extension* extension,
26 const extensions::Extension* extension, 28 ActivityLog::Observer* observer) {
27 ExtensionActivityLog::Observer* observer) {
28 base::AutoLock scoped_lock(lock_); 29 base::AutoLock scoped_lock(lock_);
29 30
30 if (observers_.count(extension) == 0) { 31 if (observers_.count(extension) == 0) {
31 observers_[extension] = new ObserverListThreadSafe<Observer>; 32 observers_[extension] = new ObserverListThreadSafe<Observer>;
32 } 33 }
33 34
34 observers_[extension]->AddObserver(observer); 35 observers_[extension]->AddObserver(observer);
35 } 36 }
36 37
37 void ExtensionActivityLog::RemoveObserver( 38 void ActivityLog::RemoveObserver(const Extension* extension,
38 const extensions::Extension* extension, 39 ActivityLog::Observer* observer) {
39 ExtensionActivityLog::Observer* observer) {
40 base::AutoLock scoped_lock(lock_); 40 base::AutoLock scoped_lock(lock_);
41 41
42 if (observers_.count(extension) == 1) { 42 if (observers_.count(extension) == 1) {
43 observers_[extension]->RemoveObserver(observer); 43 observers_[extension]->RemoveObserver(observer);
44 } 44 }
45 } 45 }
46
46 // Extension* 47 // Extension*
47 bool ExtensionActivityLog::HasObservers( 48 bool ActivityLog::HasObservers(const Extension* extension) const {
48 const extensions::Extension* extension) const {
49 base::AutoLock scoped_lock(lock_); 49 base::AutoLock scoped_lock(lock_);
50 50
51 // We also return true if extension activity logging is enabled since in that 51 // We also return true if extension activity logging is enabled since in that
52 // case this class is observing all extensions. 52 // case this class is observing all extensions.
53 return observers_.count(extension) > 0 || log_activity_to_stdout_; 53 return observers_.count(extension) > 0 || log_activity_to_stdout_;
54 } 54 }
55 55
56 void ExtensionActivityLog::Log(const extensions::Extension* extension, 56 void ActivityLog::Log(const Extension* extension,
57 Activity activity, 57 Activity activity,
58 const std::string& msg) const { 58 const std::string& msg) const {
59 base::AutoLock scoped_lock(lock_); 59 base::AutoLock scoped_lock(lock_);
60 60
61 ObserverMap::const_iterator iter = observers_.find(extension); 61 ObserverMap::const_iterator iter = observers_.find(extension);
62 if (iter != observers_.end()) { 62 if (iter != observers_.end()) {
63 iter->second->Notify(&Observer::OnExtensionActivity, extension, activity, 63 iter->second->Notify(&Observer::OnExtensionActivity, extension, activity,
64 msg); 64 msg);
65 } 65 }
66 66
67 if (log_activity_to_stdout_) { 67 if (log_activity_to_stdout_) {
68 LOG(INFO) << extension->id() + ":" + ActivityToString(activity) + ":" + msg; 68 LOG(INFO) << extension->id() + ":" + ActivityToString(activity) + ":" + msg;
69 } 69 }
70 } 70 }
71 71
72 // static 72 // static
73 const char* ExtensionActivityLog::ActivityToString(Activity activity) { 73 const char* ActivityLog::ActivityToString(Activity activity) {
74 switch (activity) { 74 switch (activity) {
75 case ExtensionActivityLog::ACTIVITY_EXTENSION_API_CALL: 75 case ActivityLog::ACTIVITY_EXTENSION_API_CALL:
76 return "api_call"; 76 return "api_call";
77 case ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK: 77 case ActivityLog::ACTIVITY_EXTENSION_API_BLOCK:
78 return "api_block"; 78 return "api_block";
79 default: 79 default:
80 NOTREACHED(); 80 NOTREACHED();
81 return ""; 81 return "";
82 } 82 }
83 } 83 }
84
85 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log.h ('k') | chrome/browser/extensions/api/management/management_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698