OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/api/log_private/log_private_api.h" | 5 #include "chrome/browser/extensions/api/log_private/log_private_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> > | 98 static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> > |
99 g_factory = LAZY_INSTANCE_INITIALIZER; | 99 g_factory = LAZY_INSTANCE_INITIALIZER; |
100 | 100 |
101 // static | 101 // static |
102 BrowserContextKeyedAPIFactory<LogPrivateAPI>* | 102 BrowserContextKeyedAPIFactory<LogPrivateAPI>* |
103 LogPrivateAPI::GetFactoryInstance() { | 103 LogPrivateAPI::GetFactoryInstance() { |
104 return &g_factory.Get(); | 104 return &g_factory.Get(); |
105 } | 105 } |
106 | 106 |
107 void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) { | 107 void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) { |
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 108 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
109 if (!pending_entries_.get()) { | 109 if (!pending_entries_.get()) { |
110 pending_entries_.reset(new base::ListValue()); | 110 pending_entries_.reset(new base::ListValue()); |
111 BrowserThread::PostDelayedTask( | 111 BrowserThread::PostDelayedTask( |
112 BrowserThread::IO, FROM_HERE, | 112 BrowserThread::IO, FROM_HERE, |
113 base::Bind(&LogPrivateAPI::PostPendingEntries, base::Unretained(this)), | 113 base::Bind(&LogPrivateAPI::PostPendingEntries, base::Unretained(this)), |
114 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); | 114 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); |
115 } | 115 } |
116 pending_entries_->Append(entry.ToValue()); | 116 pending_entries_->Append(entry.ToValue()); |
117 } | 117 } |
118 | 118 |
119 void LogPrivateAPI::PostPendingEntries() { | 119 void LogPrivateAPI::PostPendingEntries() { |
120 BrowserThread::PostTask( | 120 BrowserThread::PostTask( |
121 BrowserThread::UI, FROM_HERE, | 121 BrowserThread::UI, FROM_HERE, |
122 base::Bind(&LogPrivateAPI:: AddEntriesOnUI, | 122 base::Bind(&LogPrivateAPI:: AddEntriesOnUI, |
123 base::Unretained(this), | 123 base::Unretained(this), |
124 base::Passed(&pending_entries_))); | 124 base::Passed(&pending_entries_))); |
125 } | 125 } |
126 | 126 |
127 void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) { | 127 void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) { |
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
129 | 129 |
130 for (std::set<std::string>::iterator ix = net_internal_watches_.begin(); | 130 for (std::set<std::string>::iterator ix = net_internal_watches_.begin(); |
131 ix != net_internal_watches_.end(); ++ix) { | 131 ix != net_internal_watches_.end(); ++ix) { |
132 // Create the event's arguments value. | 132 // Create the event's arguments value. |
133 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | 133 scoped_ptr<base::ListValue> event_args(new base::ListValue()); |
134 event_args->Append(value->DeepCopy()); | 134 event_args->Append(value->DeepCopy()); |
135 scoped_ptr<Event> event(new Event(events::kOnAddNetInternalsEntries, | 135 scoped_ptr<Event> event(new Event(events::kOnAddNetInternalsEntries, |
136 event_args.Pass())); | 136 event_args.Pass())); |
137 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 137 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( |
138 *ix, event.Pass()); | 138 *ix, event.Pass()); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 void LogPrivateAPI::MaybeStartNetInternalLogging() { | 142 void LogPrivateAPI::MaybeStartNetInternalLogging() { |
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 143 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
144 if (!logging_net_internals_) { | 144 if (!logging_net_internals_) { |
145 g_browser_process->io_thread()->net_log()->AddThreadSafeObserver( | 145 g_browser_process->io_thread()->net_log()->AddThreadSafeObserver( |
146 this, net::NetLog::LOG_ALL_BUT_BYTES); | 146 this, net::NetLog::LOG_ALL_BUT_BYTES); |
147 logging_net_internals_ = true; | 147 logging_net_internals_ = true; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void LogPrivateAPI::MaybeStopNetInternalLogging() { | 151 void LogPrivateAPI::MaybeStopNetInternalLogging() { |
152 if (net_internal_watches_.empty()) { | 152 if (net_internal_watches_.empty()) { |
153 BrowserThread::PostTask( | 153 BrowserThread::PostTask( |
154 BrowserThread::IO, FROM_HERE, | 154 BrowserThread::IO, FROM_HERE, |
155 base::Bind(&LogPrivateAPI:: StopNetInternalLogging, | 155 base::Bind(&LogPrivateAPI:: StopNetInternalLogging, |
156 base::Unretained(this))); | 156 base::Unretained(this))); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 void LogPrivateAPI::StopNetInternalLogging() { | 160 void LogPrivateAPI::StopNetInternalLogging() { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
162 if (net_log() && logging_net_internals_) { | 162 if (net_log() && logging_net_internals_) { |
163 net_log()->RemoveThreadSafeObserver(this); | 163 net_log()->RemoveThreadSafeObserver(this); |
164 logging_net_internals_ = false; | 164 logging_net_internals_ = false; |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 void LogPrivateAPI::Observe(int type, | 168 void LogPrivateAPI::Observe(int type, |
169 const content::NotificationSource& source, | 169 const content::NotificationSource& source, |
170 const content::NotificationDetails& details) { | 170 const content::NotificationDetails& details) { |
171 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { | 171 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 LogPrivateStopNetInternalsWatchFunction:: | 235 LogPrivateStopNetInternalsWatchFunction:: |
236 ~LogPrivateStopNetInternalsWatchFunction() { | 236 ~LogPrivateStopNetInternalsWatchFunction() { |
237 } | 237 } |
238 | 238 |
239 bool LogPrivateStopNetInternalsWatchFunction::RunImpl() { | 239 bool LogPrivateStopNetInternalsWatchFunction::RunImpl() { |
240 LogPrivateAPI::Get(GetProfile())->StopNetInternalsWatch(extension_id()); | 240 LogPrivateAPI::Get(GetProfile())->StopNetInternalsWatch(extension_id()); |
241 return true; | 241 return true; |
242 } | 242 } |
243 | 243 |
244 } // namespace extensions | 244 } // namespace extensions |
OLD | NEW |