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

Side by Side Diff: chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc

Issue 329853010: Additional methods for chrome.logPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 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/command_line.h"
10 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/download/download_prefs.h"
18 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
16 #include "chrome/browser/extensions/api/log_private/filter_handler.h" 19 #include "chrome/browser/extensions/api/log_private/filter_handler.h"
17 #include "chrome/browser/extensions/api/log_private/log_parser.h" 20 #include "chrome/browser/extensions/api/log_private/log_parser.h"
18 #include "chrome/browser/extensions/api/log_private/syslog_parser.h" 21 #include "chrome/browser/extensions/api/log_private/syslog_parser.h"
19 #include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h" 22 #include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h"
20 #include "chrome/browser/io_thread.h" 23 #include "chrome/browser/io_thread.h"
21 #include "chrome/browser/net/chrome_net_log.h" 24 #include "chrome/browser/net/chrome_net_log.h"
22 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/common/extensions/api/log_private.h" 27 #include "chrome/common/extensions/api/log_private.h"
28 #include "chrome/common/logging_chrome.h"
29 #include "content/public/browser/render_process_host.h"
24 #include "extensions/browser/event_router.h" 30 #include "extensions/browser/event_router.h"
25 #include "extensions/browser/extension_function.h" 31 #include "extensions/browser/extension_function.h"
26 #include "extensions/browser/extension_registry.h" 32 #include "extensions/browser/extension_registry.h"
33 #include "extensions/browser/granted_file_entry.h"
34
35 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h"
37 #endif
27 38
28 using content::BrowserThread; 39 using content::BrowserThread;
29 40
30 namespace events { 41 namespace events {
31 const char kOnAddNetInternalsEntries[] = "logPrivate.onAddNetInternalsEntries"; 42 const char kOnCapturedEvents[] = "logPrivate.onCapturedEvents";
32 } // namespace events 43 } // namespace events
33 44
34 namespace extensions { 45 namespace extensions {
35 namespace { 46 namespace {
36 47
48 const char kAppLogsSubdir[] = "apps";
49 const char kLogDumpsSubdir[] = "log_dumps";
50 const char kLogFileNameBase[] = "net-internals";
37 const int kNetLogEventDelayMilliseconds = 100; 51 const int kNetLogEventDelayMilliseconds = 100;
38 52
39 scoped_ptr<LogParser> CreateLogParser(const std::string& log_type) { 53 scoped_ptr<LogParser> CreateLogParser(const std::string& log_type) {
40 if (log_type == "syslog") 54 if (log_type == "syslog")
41 return scoped_ptr<LogParser>(new SyslogParser()); 55 return scoped_ptr<LogParser>(new SyslogParser());
42 // TODO(shinfan): Add more parser here 56 // TODO(shinfan): Add more parser here
43 57
44 NOTREACHED() << "Invalid log type: " << log_type; 58 NOTREACHED() << "Invalid log type: " << log_type;
45 return scoped_ptr<LogParser>(); 59 return scoped_ptr<LogParser>();
46 } 60 }
47 61
48 void CollectLogInfo( 62 void CollectLogInfo(
49 FilterHandler* filter_handler, 63 FilterHandler* filter_handler,
50 system_logs::SystemLogsResponse* logs, 64 system_logs::SystemLogsResponse* logs,
51 std::vector<linked_ptr<api::log_private::LogEntry> >* output) { 65 std::vector<linked_ptr<api::log_private::LogEntry> >* output) {
52 for (system_logs::SystemLogsResponse::const_iterator 66 for (system_logs::SystemLogsResponse::const_iterator
53 request_it = logs->begin(); request_it != logs->end(); ++request_it) { 67 request_it = logs->begin(); request_it != logs->end(); ++request_it) {
54 if (!filter_handler->IsValidSource(request_it->first)) { 68 if (!filter_handler->IsValidSource(request_it->first)) {
55 continue; 69 continue;
56 } 70 }
57 scoped_ptr<LogParser> parser(CreateLogParser(request_it->first)); 71 scoped_ptr<LogParser> parser(CreateLogParser(request_it->first));
58 if (parser) { 72 if (parser) {
59 parser->Parse(request_it->second, output, filter_handler); 73 parser->Parse(request_it->second, output, filter_handler);
60 } 74 }
61 } 75 }
62 } 76 }
63 77
78 // Returns directory location of app-specific logs that are initiated with
79 // logPrivate.startEventRecorder() calls - /home/chronos/user/log/apps
80 base::FilePath GetAppLogDirectory() {
81 return logging::GetSessionLogDir(
82 *CommandLine::ForCurrentProcess()).Append(kAppLogsSubdir);
83 }
84
85 // Returns directory location where logs dumps initiated with chrome.dumpLogs
86 // will be stored - /home/chronos/<user_profile_dir>/Downloads/log_dumps
87 base::FilePath GetLogDumpDirectory(content::BrowserContext* context) {
88 const DownloadPrefs* const prefs =
89 DownloadPrefs::FromBrowserContext(context);
90 return prefs->DownloadPath().Append(kLogDumpsSubdir);
91 }
92
93 // Removes direcotry content of |logs_dumps| and |app_logs_dir| (only for the
94 // primary profile).
95 void CleanUpLeftoverLogs(bool is_primary_profile,
96 const base::FilePath& app_logs_dir,
97 const base::FilePath& logs_dumps) {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
99 base::DeleteFile(logs_dumps, true);
100
101 // App-specific logs are stored in /home/chronos/user/log/apps directory that
102 // is shared between all profiles in multi-profile case. We should not
103 // nuke it for non-primary profiles.
104 if (!is_primary_profile)
105 return;
106
107 base::DeleteFile(app_logs_dir, true);
108 }
109
64 } // namespace 110 } // namespace
65 111
112 FileResource::FileResource(const std::string& owner_extension_id,
113 const base::FilePath& path)
114 : ApiResource(owner_extension_id),
115 path_(path) {
116 }
117
118 FileResource::~FileResource() {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
120 base::DeleteFile(path_, true);
121 }
122
123 bool FileResource::IsPersistent() const {
124 return false;
125 }
126
66 // static 127 // static
67 LogPrivateAPI* LogPrivateAPI::Get(content::BrowserContext* context) { 128 LogPrivateAPI* LogPrivateAPI::Get(content::BrowserContext* context) {
68 return GetFactoryInstance()->Get(context); 129 return GetFactoryInstance()->Get(context);
69 } 130 }
70 131
71 LogPrivateAPI::LogPrivateAPI(content::BrowserContext* context) 132 LogPrivateAPI::LogPrivateAPI(content::BrowserContext* context)
72 : browser_context_(context), 133 : browser_context_(context),
73 logging_net_internals_(false), 134 logging_net_internals_(false),
74 extension_registry_observer_(this) { 135 event_sink_(api::log_private::EVENT_SINK_CAPTURE),
136 extension_registry_observer_(this),
137 log_file_resources_(context) {
75 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); 138 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
139 BrowserThread::PostTask(
140 BrowserThread::FILE,
141 FROM_HERE,
142 base::Bind(&CleanUpLeftoverLogs,
143 Profile::FromBrowserContext(context) ==
144 ProfileManager::GetPrimaryUserProfile(),
145 GetAppLogDirectory(),
146 GetLogDumpDirectory(context)));
76 } 147 }
77 148
78 LogPrivateAPI::~LogPrivateAPI() { 149 LogPrivateAPI::~LogPrivateAPI() {
79 } 150 }
80 151
81 void LogPrivateAPI::StartNetInternalsWatch(const std::string& extension_id) { 152 void LogPrivateAPI::Shutdown() {
82 net_internal_watches_.insert(extension_id);
83 BrowserThread::PostTask(
84 BrowserThread::IO, FROM_HERE,
85 base::Bind(&LogPrivateAPI::MaybeStartNetInternalLogging,
86 base::Unretained(this)));
87 } 153 }
88 154
89 void LogPrivateAPI::StopNetInternalsWatch(const std::string& extension_id) { 155 void LogPrivateAPI::StartNetInternalsWatch(
156 const std::string& extension_id,
157 api::log_private::EventSink event_sink,
158 const base::Closure& closure) {
159 net_internal_watches_.insert(extension_id);
160
161 // Nuke any leftover app-specific or dumped log files from previous sessions.
162 BrowserThread::PostTaskAndReply(
163 BrowserThread::IO,
164 FROM_HERE,
165 base::Bind(&LogPrivateAPI::MaybeStartNetInternalLogging,
166 base::Unretained(this),
167 extension_id,
168 g_browser_process->io_thread(),
169 event_sink),
170 closure);
171 }
172
173 void LogPrivateAPI::StopNetInternalsWatch(const std::string& extension_id,
174 const base::Closure& closure) {
90 net_internal_watches_.erase(extension_id); 175 net_internal_watches_.erase(extension_id);
91 MaybeStopNetInternalLogging(); 176 MaybeStopNetInternalLogging(closure);
177 }
178
179 void LogPrivateAPI::StopAllWatches(const std::string& extension_id,
180 const base::Closure& closure) {
181 StopNetInternalsWatch(extension_id, closure);
182 }
183
184 void LogPrivateAPI::RegisterTempFile(const std::string& owner_extension_id,
185 const base::FilePath& file_path) {
186 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
187 BrowserThread::PostTask(
188 BrowserThread::FILE,
189 FROM_HERE,
190 base::Bind(&LogPrivateAPI::RegisterTempFile,
191 base::Unretained(this),
192 owner_extension_id,
193 file_path));
194 return;
195 }
196
197 log_file_resources_.Add(new FileResource(owner_extension_id, file_path));
92 } 198 }
93 199
94 static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> > 200 static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> >
95 g_factory = LAZY_INSTANCE_INITIALIZER; 201 g_factory = LAZY_INSTANCE_INITIALIZER;
96 202
97 // static 203 // static
98 BrowserContextKeyedAPIFactory<LogPrivateAPI>* 204 BrowserContextKeyedAPIFactory<LogPrivateAPI>*
99 LogPrivateAPI::GetFactoryInstance() { 205 LogPrivateAPI::GetFactoryInstance() {
100 return g_factory.Pointer(); 206 return g_factory.Pointer();
101 } 207 }
102 208
103 void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) { 209 void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) {
104 DCHECK_CURRENTLY_ON(BrowserThread::IO); 210 // We could receive events on whatever thread they happen to be generated,
211 // since we are only interested in network events, we should ignore any
212 // other thread than BrowserThread::IO.
213 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
214 return;
215 }
216
105 if (!pending_entries_.get()) { 217 if (!pending_entries_.get()) {
106 pending_entries_.reset(new base::ListValue()); 218 pending_entries_.reset(new base::ListValue());
107 BrowserThread::PostDelayedTask( 219 BrowserThread::PostDelayedTask(
108 BrowserThread::IO, FROM_HERE, 220 BrowserThread::IO, FROM_HERE,
109 base::Bind(&LogPrivateAPI::PostPendingEntries, base::Unretained(this)), 221 base::Bind(&LogPrivateAPI::PostPendingEntries, base::Unretained(this)),
110 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); 222 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds));
111 } 223 }
112 pending_entries_->Append(entry.ToValue()); 224 pending_entries_->Append(entry.ToValue());
113 } 225 }
114 226
115 void LogPrivateAPI::PostPendingEntries() { 227 void LogPrivateAPI::PostPendingEntries() {
116 BrowserThread::PostTask( 228 BrowserThread::PostTask(
117 BrowserThread::UI, FROM_HERE, 229 BrowserThread::UI, FROM_HERE,
118 base::Bind(&LogPrivateAPI:: AddEntriesOnUI, 230 base::Bind(&LogPrivateAPI:: AddEntriesOnUI,
119 base::Unretained(this), 231 base::Unretained(this),
120 base::Passed(&pending_entries_))); 232 base::Passed(&pending_entries_)));
121 } 233 }
122 234
123 void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) { 235 void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) {
124 DCHECK_CURRENTLY_ON(BrowserThread::UI); 236 DCHECK_CURRENTLY_ON(BrowserThread::UI);
125 237
126 for (std::set<std::string>::iterator ix = net_internal_watches_.begin(); 238 for (std::set<std::string>::iterator ix = net_internal_watches_.begin();
127 ix != net_internal_watches_.end(); ++ix) { 239 ix != net_internal_watches_.end(); ++ix) {
128 // Create the event's arguments value. 240 // Create the event's arguments value.
129 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 241 scoped_ptr<base::ListValue> event_args(new base::ListValue());
130 event_args->Append(value->DeepCopy()); 242 event_args->Append(value->DeepCopy());
131 scoped_ptr<Event> event(new Event(events::kOnAddNetInternalsEntries, 243 scoped_ptr<Event> event(new Event(events::kOnCapturedEvents,
132 event_args.Pass())); 244 event_args.Pass()));
133 EventRouter::Get(browser_context_) 245 EventRouter::Get(browser_context_)
134 ->DispatchEventToExtension(*ix, event.Pass()); 246 ->DispatchEventToExtension(*ix, event.Pass());
135 } 247 }
136 } 248 }
137 249
138 void LogPrivateAPI::MaybeStartNetInternalLogging() { 250 void LogPrivateAPI::InitializeNetLogger(
251 const std::string& owner_extension_id,
252 net::NetLogLogger** net_log_logger) {
253 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
254 (*net_log_logger) = NULL;
255
256 // Create app-specific subdirectory in session logs folder.
257 base::FilePath app_log_dir = GetAppLogDirectory().Append(owner_extension_id);
258 if (!base::DirectoryExists(app_log_dir)) {
259 if (!base::CreateDirectory(app_log_dir)) {
260 LOG(ERROR) << "Could not create dir " << app_log_dir.value();
261 return;
262 }
263 }
264
265 base::FilePath file_path = app_log_dir.Append(kLogFileNameBase);
266 file_path = logging::GenerateTimestampedName(file_path,
267 base::Time::Now());
268 FILE* file = NULL;
269 file = fopen(file_path.value().c_str(), "w");
270 if (file == NULL) {
271 LOG(ERROR) << "Could not open " << file_path.value();
272 return;
273 }
274
275 RegisterTempFile(owner_extension_id, file_path);
276 scoped_ptr<base::Value> constants(net::NetLogLogger::GetConstants());
277 *net_log_logger = new net::NetLogLogger(file, *constants);
278 (*net_log_logger)->set_log_level(net::NetLog::LOG_ALL_BUT_BYTES);
279 }
280
281 void LogPrivateAPI::StartObservingNetEvents(
282 IOThread* io_thread,
283 net::NetLogLogger** net_log_logger) {
284 DCHECK_CURRENTLY_ON(BrowserThread::IO);
285 if (!(*net_log_logger))
286 return;
287
288 net_log_logger_.reset(*net_log_logger);
289 net_log_logger_->StartObserving(io_thread->net_log());
290 }
291
292 void LogPrivateAPI::MaybeStartNetInternalLogging(
293 const std::string& caller_extension_id,
294 IOThread* io_thread,
295 api::log_private::EventSink event_sink) {
139 DCHECK_CURRENTLY_ON(BrowserThread::IO); 296 DCHECK_CURRENTLY_ON(BrowserThread::IO);
140 if (!logging_net_internals_) { 297 if (!logging_net_internals_) {
141 g_browser_process->io_thread()->net_log()->AddThreadSafeObserver(
142 this, net::NetLog::LOG_ALL_BUT_BYTES);
143 logging_net_internals_ = true; 298 logging_net_internals_ = true;
299 event_sink_ = event_sink;
300 switch (event_sink_) {
301 case api::log_private::EVENT_SINK_CAPTURE: {
302 io_thread->net_log()->AddThreadSafeObserver(
303 this, net::NetLog::LOG_ALL_BUT_BYTES);
304 break;
305 }
306 case api::log_private::EVENT_SINK_FILE: {
307 net::NetLogLogger** net_logger_ptr = new net::NetLogLogger*[1];
308 // Initialize net logger on the blocking pool and start observing event
309 // with in on IO thread.
310 BrowserThread::PostTaskAndReply(
311 BrowserThread::FILE,
312 FROM_HERE,
313 base::Bind(&LogPrivateAPI::InitializeNetLogger,
314 base::Unretained(this),
315 caller_extension_id,
316 net_logger_ptr),
317 base::Bind(&LogPrivateAPI::StartObservingNetEvents,
318 base::Unretained(this),
319 io_thread,
320 base::Owned(net_logger_ptr)));
321 break;
322 }
323 case api::log_private::EVENT_SINK_NONE: {
324 NOTREACHED();
325 break;
326 }
327 }
144 } 328 }
145 } 329 }
146 330
147 void LogPrivateAPI::MaybeStopNetInternalLogging() { 331 void LogPrivateAPI::MaybeStopNetInternalLogging(const base::Closure& closure) {
148 if (net_internal_watches_.empty()) { 332 if (net_internal_watches_.empty()) {
149 BrowserThread::PostTask( 333 BrowserThread::PostTaskAndReply(
150 BrowserThread::IO, FROM_HERE, 334 BrowserThread::IO, FROM_HERE,
151 base::Bind(&LogPrivateAPI:: StopNetInternalLogging, 335 base::Bind(&LogPrivateAPI:: StopNetInternalLogging,
152 base::Unretained(this))); 336 base::Unretained(this)),
337 closure);
153 } 338 }
154 } 339 }
155 340
156 void LogPrivateAPI::StopNetInternalLogging() { 341 void LogPrivateAPI::StopNetInternalLogging() {
157 DCHECK_CURRENTLY_ON(BrowserThread::IO); 342 DCHECK_CURRENTLY_ON(BrowserThread::IO);
158 if (net_log() && logging_net_internals_) { 343 if (net_log() && logging_net_internals_) {
159 net_log()->RemoveThreadSafeObserver(this);
160 logging_net_internals_ = false; 344 logging_net_internals_ = false;
345 switch (event_sink_) {
346 case api::log_private::EVENT_SINK_CAPTURE:
347 net_log()->RemoveThreadSafeObserver(this);
348 break;
349 case api::log_private::EVENT_SINK_FILE:
350 net_log_logger_->StopObserving();
351 net_log_logger_.reset();
352 break;
353 case api::log_private::EVENT_SINK_NONE:
354 NOTREACHED();
355 break;
356 }
161 } 357 }
162 } 358 }
163 359
164 void LogPrivateAPI::OnExtensionUnloaded( 360 void LogPrivateAPI::OnExtensionUnloaded(
165 content::BrowserContext* browser_context, 361 content::BrowserContext* browser_context,
166 const Extension* extension, 362 const Extension* extension,
167 UnloadedExtensionInfo::Reason reason) { 363 UnloadedExtensionInfo::Reason reason) {
168 StopNetInternalsWatch(extension->id()); 364 StopNetInternalsWatch(extension->id(), base::Closure());
169 } 365 }
170 366
171 LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() { 367 LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() {
172 } 368 }
173 369
174 LogPrivateGetHistoricalFunction::~LogPrivateGetHistoricalFunction() { 370 LogPrivateGetHistoricalFunction::~LogPrivateGetHistoricalFunction() {
175 } 371 }
176 372
177 bool LogPrivateGetHistoricalFunction::RunAsync() { 373 bool LogPrivateGetHistoricalFunction::RunAsync() {
178 // Get parameters 374 // Get parameters
(...skipping 22 matching lines...) Expand all
201 397
202 // Prepare result 398 // Prepare result
203 api::log_private::Result result; 399 api::log_private::Result result;
204 result.data = data; 400 result.data = data;
205 api::log_private::Filter::Populate( 401 api::log_private::Filter::Populate(
206 *((filter_handler_->GetFilter())->ToValue()), &result.filter); 402 *((filter_handler_->GetFilter())->ToValue()), &result.filter);
207 SetResult(result.ToValue().release()); 403 SetResult(result.ToValue().release());
208 SendResponse(true); 404 SendResponse(true);
209 } 405 }
210 406
211 LogPrivateStartNetInternalsWatchFunction:: 407 LogPrivateStartEventRecorderFunction::LogPrivateStartEventRecorderFunction() {
212 LogPrivateStartNetInternalsWatchFunction() {
213 } 408 }
214 409
215 LogPrivateStartNetInternalsWatchFunction:: 410 LogPrivateStartEventRecorderFunction::~LogPrivateStartEventRecorderFunction() {
216 ~LogPrivateStartNetInternalsWatchFunction() {
217 } 411 }
218 412
219 bool LogPrivateStartNetInternalsWatchFunction::RunSync() { 413 bool LogPrivateStartEventRecorderFunction::RunAsync() {
220 LogPrivateAPI::Get(GetProfile())->StartNetInternalsWatch(extension_id()); 414 scoped_ptr<api::log_private::StartEventRecorder::Params> params(
415 api::log_private::StartEventRecorder::Params::Create(*args_));
416 EXTENSION_FUNCTION_VALIDATE(params.get());
417 switch (params->event_type) {
418 case api::log_private::EVENT_TYPE_NETWORK:
419 LogPrivateAPI::Get(Profile::FromBrowserContext(
420 browser_context()))->StartNetInternalsWatch(
421 extension_id(),
422 params->sink,
423 base::Bind(
424 &LogPrivateStartEventRecorderFunction::OnEventRecorderStarted,
425 this));
426 break;
427 case api::log_private::EVENT_TYPE_NONE:
428 NOTREACHED();
429 return false;
430 }
431
221 return true; 432 return true;
222 } 433 }
223 434
224 LogPrivateStopNetInternalsWatchFunction:: 435 void LogPrivateStartEventRecorderFunction::OnEventRecorderStarted() {
225 LogPrivateStopNetInternalsWatchFunction() { 436 SendResponse(true);
226 } 437 }
227 438
228 LogPrivateStopNetInternalsWatchFunction:: 439 LogPrivateStopEventRecorderFunction::LogPrivateStopEventRecorderFunction() {
229 ~LogPrivateStopNetInternalsWatchFunction() {
230 } 440 }
231 441
232 bool LogPrivateStopNetInternalsWatchFunction::RunSync() { 442 LogPrivateStopEventRecorderFunction::~LogPrivateStopEventRecorderFunction() {
233 LogPrivateAPI::Get(GetProfile())->StopNetInternalsWatch(extension_id()); 443 }
444
445 bool LogPrivateStopEventRecorderFunction::RunAsync() {
446 scoped_ptr<api::log_private::StopEventRecorder::Params> params(
447 api::log_private::StopEventRecorder::Params::Create(*args_));
448 EXTENSION_FUNCTION_VALIDATE(params.get());
449 switch (params->event_type) {
450 case api::log_private::EVENT_TYPE_NETWORK:
451 LogPrivateAPI::Get(Profile::FromBrowserContext(
452 browser_context()))->StopNetInternalsWatch(
453 extension_id(),
454 base::Bind(
455 &LogPrivateStopEventRecorderFunction::OnEventRecorderStopped,
456 this));
457 break;
458 case api::log_private::EVENT_TYPE_NONE:
459 NOTREACHED();
460 return false;
461 }
234 return true; 462 return true;
235 } 463 }
236 464
465 void LogPrivateStopEventRecorderFunction::OnEventRecorderStopped() {
466 SendResponse(true);
467 }
468
469 LogPrivateDumpLogsFunction::LogPrivateDumpLogsFunction() {
470 }
471
472 LogPrivateDumpLogsFunction::~LogPrivateDumpLogsFunction() {
473 }
474
475 bool LogPrivateDumpLogsFunction::RunAsync() {
476 LogPrivateAPI::Get(Profile::FromBrowserContext(browser_context()))->
477 StopAllWatches(
478 extension_id(),
479 base::Bind(&LogPrivateDumpLogsFunction::OnStopAllWatches, this));
480 return true;
481 }
482
483 void LogPrivateDumpLogsFunction::OnStopAllWatches() {
484 chromeos::DebugLogWriter::StoreCombinedLogs(
485 GetLogDumpDirectory(browser_context()).Append(extension_id()),
486 base::Bind(&LogPrivateDumpLogsFunction::OnStoreLogsCompleted,
487 this));
488 }
489
490 void LogPrivateDumpLogsFunction::OnStoreLogsCompleted(
491 const base::FilePath& log_path, bool succeeded) {
492 if (succeeded) {
493 LogPrivateAPI::Get(Profile::FromBrowserContext(
494 browser_context()))->RegisterTempFile(
495 extension_id(),
496 log_path);
497 }
498
499 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
500 extensions::GrantedFileEntry file_entry =
501 extensions::app_file_handler_util::CreateFileEntry(
502 Profile::FromBrowserContext(browser_context()),
503 GetExtension(),
504 render_view_host_->GetProcess()->GetID(),
505 log_path,
506 false);
507
508 base::DictionaryValue* entry = new base::DictionaryValue();
509 entry->SetString("fileSystemId", file_entry.filesystem_id);
510 entry->SetString("baseName", file_entry.registered_name);
511 entry->SetString("id", file_entry.id);
512 entry->SetBoolean("isDirectory", false);
513 response->Set("entry", entry);
514 SetResult(response.release());
515 SendResponse(succeeded);
516 }
517
237 } // namespace extensions 518 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698