OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/processes/processes_api.h" | 5 #include "chrome/browser/extensions/api/processes/processes_api.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 | 14 |
15 #include "chrome/browser/extensions/api/processes/processes_api_constants.h" | 15 #include "chrome/browser/extensions/api/processes/processes_api_constants.h" |
| 16 #include "chrome/browser/extensions/api/processes/processes_api_service.h" |
16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 17 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
17 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
18 #include "chrome/browser/extensions/extension_function_util.h" | 19 #include "chrome/browser/extensions/extension_function_util.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
21 #include "chrome/browser/extensions/extension_tab_util.h" | 22 #include "chrome/browser/extensions/extension_tab_util.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/task_manager/task_manager.h" | 24 #include "chrome/browser/task_manager/task_manager.h" |
24 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/extensions/extension_error_utils.h" | 26 #include "chrome/common/extensions/extension_error_utils.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 size_t mem; | 206 size_t mem; |
206 int64 pr_mem = model->GetPrivateMemory(index, &mem) ? | 207 int64 pr_mem = model->GetPrivateMemory(index, &mem) ? |
207 static_cast<int64>(mem) : -1; | 208 static_cast<int64>(mem) : -1; |
208 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem)); | 209 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem)); |
209 } | 210 } |
210 | 211 |
211 #endif // defined(ENABLE_TASK_MANAGER) | 212 #endif // defined(ENABLE_TASK_MANAGER) |
212 | 213 |
213 } // namespace | 214 } // namespace |
214 | 215 |
215 ProcessesEventRouter* ProcessesEventRouter::GetInstance() { | 216 ProcessesEventRouter::ProcessesEventRouter(Profile* profile) |
216 return Singleton<ProcessesEventRouter>::get(); | 217 : profile_(profile), |
217 } | 218 listeners_(0), |
218 | |
219 ProcessesEventRouter::ProcessesEventRouter() | |
220 : listeners_(0), | |
221 task_manager_listening_(false) { | 219 task_manager_listening_(false) { |
222 #if defined(ENABLE_TASK_MANAGER) | 220 #if defined(ENABLE_TASK_MANAGER) |
223 model_ = TaskManager::GetInstance()->model(); | 221 model_ = TaskManager::GetInstance()->model(); |
224 model_->AddObserver(this); | 222 model_->AddObserver(this); |
225 | 223 |
226 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, | 224 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, |
227 content::NotificationService::AllSources()); | 225 content::NotificationService::AllSources()); |
228 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 226 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
229 content::NotificationService::AllSources()); | 227 content::NotificationService::AllSources()); |
230 #endif // defined(ENABLE_TASK_MANAGER) | 228 #endif // defined(ENABLE_TASK_MANAGER) |
231 } | 229 } |
232 | 230 |
233 ProcessesEventRouter::~ProcessesEventRouter() { | 231 ProcessesEventRouter::~ProcessesEventRouter() { |
234 #if defined(ENABLE_TASK_MANAGER) | 232 #if defined(ENABLE_TASK_MANAGER) |
235 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, | 233 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, |
236 content::NotificationService::AllSources()); | 234 content::NotificationService::AllSources()); |
237 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 235 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
238 content::NotificationService::AllSources()); | 236 content::NotificationService::AllSources()); |
239 | 237 |
240 if (task_manager_listening_) | 238 if (task_manager_listening_) |
241 model_->StopListening(); | 239 model_->StopListening(); |
242 | 240 |
243 model_->RemoveObserver(this); | 241 model_->RemoveObserver(this); |
244 #endif // defined(ENABLE_TASK_MANAGER) | 242 #endif // defined(ENABLE_TASK_MANAGER) |
245 } | 243 } |
246 | 244 |
247 void ProcessesEventRouter::ObserveProfile(Profile* profile) { | |
248 profiles_.insert(profile); | |
249 } | |
250 | |
251 void ProcessesEventRouter::ListenerAdded() { | 245 void ProcessesEventRouter::ListenerAdded() { |
252 #if defined(ENABLE_TASK_MANAGER) | 246 #if defined(ENABLE_TASK_MANAGER) |
253 // The task manager has its own ref count to balance other callers of | 247 // The task manager has its own ref count to balance other callers of |
254 // StartUpdating/StopUpdating. | 248 // StartUpdating/StopUpdating. |
255 model_->StartUpdating(); | 249 model_->StartUpdating(); |
256 #endif // defined(ENABLE_TASK_MANAGER) | 250 #endif // defined(ENABLE_TASK_MANAGER) |
257 ++listeners_; | 251 ++listeners_; |
258 } | 252 } |
259 | 253 |
260 void ProcessesEventRouter::ListenerRemoved() { | 254 void ProcessesEventRouter::ListenerRemoved() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 scoped_ptr<ListValue> args(new ListValue()); | 310 scoped_ptr<ListValue> args(new ListValue()); |
317 DictionaryValue* process = CreateProcessFromModel( | 311 DictionaryValue* process = CreateProcessFromModel( |
318 model_->GetUniqueChildProcessId(index), model_, index, false); | 312 model_->GetUniqueChildProcessId(index), model_, index, false); |
319 DCHECK(process != NULL); | 313 DCHECK(process != NULL); |
320 | 314 |
321 if (process == NULL) | 315 if (process == NULL) |
322 return; | 316 return; |
323 | 317 |
324 args->Append(process); | 318 args->Append(process); |
325 | 319 |
326 NotifyProfiles(keys::kOnCreated, args.Pass()); | 320 DispatchEvent(keys::kOnCreated, args.Pass()); |
327 #endif // defined(ENABLE_TASK_MANAGER) | 321 #endif // defined(ENABLE_TASK_MANAGER) |
328 } | 322 } |
329 | 323 |
330 void ProcessesEventRouter::OnItemsChanged(int start, int length) { | 324 void ProcessesEventRouter::OnItemsChanged(int start, int length) { |
331 #if defined(ENABLE_TASK_MANAGER) | 325 #if defined(ENABLE_TASK_MANAGER) |
332 // If we don't have any listeners, return immediately. | 326 // If we don't have any listeners, return immediately. |
333 if (listeners_ == 0) | 327 if (listeners_ == 0) |
334 return; | 328 return; |
335 | 329 |
336 if (!model_) | 330 if (!model_) |
(...skipping 26 matching lines...) Expand all Loading... |
363 for (; !it.IsAtEnd(); it.Advance()) { | 357 for (; !it.IsAtEnd(); it.Advance()) { |
364 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) | 358 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) |
365 continue; | 359 continue; |
366 | 360 |
367 // Store each process indexed by the string version of its id. | 361 // Store each process indexed by the string version of its id. |
368 processes->Set(base::IntToString(id), it.GetCurrentValue()); | 362 processes->Set(base::IntToString(id), it.GetCurrentValue()); |
369 } | 363 } |
370 | 364 |
371 scoped_ptr<ListValue> args(new ListValue()); | 365 scoped_ptr<ListValue> args(new ListValue()); |
372 args->Append(processes); | 366 args->Append(processes); |
373 NotifyProfiles(keys::kOnUpdated, args.Pass()); | 367 DispatchEvent(keys::kOnUpdated, args.Pass()); |
374 } | 368 } |
375 | 369 |
376 if (updated_memory) { | 370 if (updated_memory) { |
377 IDMap<DictionaryValue>::iterator it(&processes_map); | 371 IDMap<DictionaryValue>::iterator it(&processes_map); |
378 for (; !it.IsAtEnd(); it.Advance()) { | 372 for (; !it.IsAtEnd(); it.Advance()) { |
379 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) | 373 if (!it.GetCurrentValue()->GetInteger(idkey, &id)) |
380 continue; | 374 continue; |
381 | 375 |
382 AddMemoryDetails(it.GetCurrentValue(), model_, it.GetCurrentKey()); | 376 AddMemoryDetails(it.GetCurrentValue(), model_, it.GetCurrentKey()); |
383 | 377 |
384 // Store each process indexed by the string version of its id if we didn't | 378 // Store each process indexed by the string version of its id if we didn't |
385 // already insert it as part of the onUpdated processing above. | 379 // already insert it as part of the onUpdated processing above. |
386 if (!updated) | 380 if (!updated) |
387 processes->Set(base::IntToString(id), it.GetCurrentValue()); | 381 processes->Set(base::IntToString(id), it.GetCurrentValue()); |
388 } | 382 } |
389 | 383 |
390 scoped_ptr<ListValue> args(new ListValue()); | 384 scoped_ptr<ListValue> args(new ListValue()); |
391 args->Append(processes); | 385 args->Append(processes); |
392 NotifyProfiles(keys::kOnUpdatedWithMemory, args.Pass()); | 386 DispatchEvent(keys::kOnUpdatedWithMemory, args.Pass()); |
393 } | 387 } |
394 #endif // defined(ENABLE_TASK_MANAGER) | 388 #endif // defined(ENABLE_TASK_MANAGER) |
395 } | 389 } |
396 | 390 |
397 void ProcessesEventRouter::OnItemsToBeRemoved(int start, int length) { | 391 void ProcessesEventRouter::OnItemsToBeRemoved(int start, int length) { |
398 #if defined(ENABLE_TASK_MANAGER) | 392 #if defined(ENABLE_TASK_MANAGER) |
399 DCHECK_EQ(length, 1); | 393 DCHECK_EQ(length, 1); |
400 | 394 |
401 // Process exit for renderer processes has the data about exit code and | 395 // Process exit for renderer processes has the data about exit code and |
402 // termination status, therefore we will rely on notifications and not on | 396 // termination status, therefore we will rely on notifications and not on |
403 // the Task Manager data. We do use the rest of this method for non-renderer | 397 // the Task Manager data. We do use the rest of this method for non-renderer |
404 // processes. | 398 // processes. |
405 if (model_->GetResourceType(start) == TaskManager::Resource::RENDERER) | 399 if (model_->GetResourceType(start) == TaskManager::Resource::RENDERER) |
406 return; | 400 return; |
407 | 401 |
408 // The callback function parameters. | 402 // The callback function parameters. |
409 scoped_ptr<ListValue> args(new ListValue()); | 403 scoped_ptr<ListValue> args(new ListValue()); |
410 | 404 |
411 // First arg: The id of the process that was closed. | 405 // First arg: The id of the process that was closed. |
412 args->Append(Value::CreateIntegerValue( | 406 args->Append(Value::CreateIntegerValue( |
413 model_->GetUniqueChildProcessId(start))); | 407 model_->GetUniqueChildProcessId(start))); |
414 | 408 |
415 // Second arg: The exit type for the process. | 409 // Second arg: The exit type for the process. |
416 args->Append(Value::CreateIntegerValue(0)); | 410 args->Append(Value::CreateIntegerValue(0)); |
417 | 411 |
418 // Third arg: The exit code for the process. | 412 // Third arg: The exit code for the process. |
419 args->Append(Value::CreateIntegerValue(0)); | 413 args->Append(Value::CreateIntegerValue(0)); |
420 | 414 |
421 NotifyProfiles(keys::kOnExited, args.Pass()); | 415 DispatchEvent(keys::kOnExited, args.Pass()); |
422 #endif // defined(ENABLE_TASK_MANAGER) | 416 #endif // defined(ENABLE_TASK_MANAGER) |
423 } | 417 } |
424 | 418 |
425 void ProcessesEventRouter::ProcessHangEvent(content::RenderWidgetHost* widget) { | 419 void ProcessesEventRouter::ProcessHangEvent(content::RenderWidgetHost* widget) { |
426 #if defined(ENABLE_TASK_MANAGER) | 420 #if defined(ENABLE_TASK_MANAGER) |
427 std::string event(keys::kOnUnresponsive); | 421 std::string event(keys::kOnUnresponsive); |
428 if (!HasEventListeners(event)) | 422 if (!HasEventListeners(event)) |
429 return; | 423 return; |
430 | 424 |
431 DictionaryValue* process = NULL; | 425 DictionaryValue* process = NULL; |
432 int count = model_->ResourceCount(); | 426 int count = model_->ResourceCount(); |
433 int id = widget->GetProcess()->GetID(); | 427 int id = widget->GetProcess()->GetID(); |
434 | 428 |
435 for (int i = 0; i < count; ++i) { | 429 for (int i = 0; i < count; ++i) { |
436 if (model_->IsResourceFirstInGroup(i)) { | 430 if (model_->IsResourceFirstInGroup(i)) { |
437 if (id == model_->GetUniqueChildProcessId(i)) { | 431 if (id == model_->GetUniqueChildProcessId(i)) { |
438 process = CreateProcessFromModel(id, model_, i, false); | 432 process = CreateProcessFromModel(id, model_, i, false); |
439 break; | 433 break; |
440 } | 434 } |
441 } | 435 } |
442 } | 436 } |
443 | 437 |
444 DCHECK(process); | 438 DCHECK(process); |
445 if (process == NULL) | 439 if (process == NULL) |
446 return; | 440 return; |
447 | 441 |
448 scoped_ptr<ListValue> args(new ListValue()); | 442 scoped_ptr<ListValue> args(new ListValue()); |
449 args->Append(process); | 443 args->Append(process); |
450 | 444 |
451 NotifyProfiles(keys::kOnUnresponsive, args.Pass()); | 445 DispatchEvent(keys::kOnUnresponsive, args.Pass()); |
452 #endif // defined(ENABLE_TASK_MANAGER) | 446 #endif // defined(ENABLE_TASK_MANAGER) |
453 } | 447 } |
454 | 448 |
455 void ProcessesEventRouter::ProcessClosedEvent( | 449 void ProcessesEventRouter::ProcessClosedEvent( |
456 content::RenderProcessHost* rph, | 450 content::RenderProcessHost* rph, |
457 content::RenderProcessHost::RendererClosedDetails* details) { | 451 content::RenderProcessHost::RendererClosedDetails* details) { |
458 #if defined(ENABLE_TASK_MANAGER) | 452 #if defined(ENABLE_TASK_MANAGER) |
459 // The callback function parameters. | 453 // The callback function parameters. |
460 scoped_ptr<ListValue> args(new ListValue()); | 454 scoped_ptr<ListValue> args(new ListValue()); |
461 | 455 |
462 // First arg: The id of the process that was closed. | 456 // First arg: The id of the process that was closed. |
463 args->Append(Value::CreateIntegerValue(rph->GetID())); | 457 args->Append(Value::CreateIntegerValue(rph->GetID())); |
464 | 458 |
465 // Second arg: The exit type for the process. | 459 // Second arg: The exit type for the process. |
466 args->Append(Value::CreateIntegerValue(details->status)); | 460 args->Append(Value::CreateIntegerValue(details->status)); |
467 | 461 |
468 // Third arg: The exit code for the process. | 462 // Third arg: The exit code for the process. |
469 args->Append(Value::CreateIntegerValue(details->exit_code)); | 463 args->Append(Value::CreateIntegerValue(details->exit_code)); |
470 | 464 |
471 NotifyProfiles(keys::kOnExited, args.Pass()); | 465 DispatchEvent(keys::kOnExited, args.Pass()); |
472 #endif // defined(ENABLE_TASK_MANAGER) | 466 #endif // defined(ENABLE_TASK_MANAGER) |
473 } | 467 } |
474 | 468 |
475 void ProcessesEventRouter::DispatchEvent(Profile* profile, | 469 void ProcessesEventRouter::DispatchEvent(const char* event_name, |
476 const char* event_name, | |
477 scoped_ptr<ListValue> event_args) { | 470 scoped_ptr<ListValue> event_args) { |
478 if (profile && extensions::ExtensionSystem::Get(profile)->event_router()) { | 471 if (extensions::ExtensionSystem::Get(profile_)->event_router()) { |
479 extensions::ExtensionSystem::Get(profile)->event_router()-> | 472 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
480 DispatchEventToRenderers(event_name, event_args.Pass(), NULL, GURL(), | 473 DispatchEventToRenderers(event_name, event_args.Pass(), NULL, GURL(), |
481 extensions::EventFilteringInfo()); | 474 extensions::EventFilteringInfo()); |
482 } | 475 } |
483 } | 476 } |
484 | 477 |
485 void ProcessesEventRouter::NotifyProfiles(const char* event_name, | |
486 scoped_ptr<ListValue> event_args) { | |
487 for (ProfileSet::iterator it = profiles_.begin(); | |
488 it != profiles_.end(); ++it) { | |
489 Profile* profile = *it; | |
490 scoped_ptr<ListValue> event_args_copy(event_args->DeepCopy()); | |
491 DispatchEvent(profile, event_name, event_args_copy.Pass()); | |
492 } | |
493 } | |
494 | |
495 // In order to determine whether there are any listeners for the event of | |
496 // interest, we need to ask each profile whether it has one registered. | |
497 // We only need to look for the profiles that have registered with the | |
498 // this extension API. | |
499 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { | 478 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { |
500 for (ProfileSet::iterator it = profiles_.begin(); | 479 extensions::EventRouter* router = |
501 it != profiles_.end(); ++it) { | 480 extensions::ExtensionSystem::Get(profile_)->event_router(); |
502 Profile* profile = *it; | 481 if (router && router->HasEventListener(event_name)) |
503 extensions::EventRouter* router = | |
504 extensions::ExtensionSystem::Get(profile)->event_router(); | |
505 if (!router) | |
506 continue; | |
507 | |
508 if (router->HasEventListener(event_name)) | |
509 return true; | 482 return true; |
510 } | |
511 return false; | 483 return false; |
512 } | 484 } |
513 | 485 |
514 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { | 486 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { |
515 } | 487 } |
516 | 488 |
517 bool GetProcessIdForTabFunction::RunImpl() { | 489 bool GetProcessIdForTabFunction::RunImpl() { |
518 #if defined(ENABLE_TASK_MANAGER) | 490 #if defined(ENABLE_TASK_MANAGER) |
519 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); | 491 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); |
520 | 492 |
521 // Add a reference, which is balanced in GetProcessIdForTab to keep the object | 493 // Add a reference, which is balanced in GetProcessIdForTab to keep the object |
522 // around and allow for the callback to be invoked. | 494 // around and allow for the callback to be invoked. |
523 AddRef(); | 495 AddRef(); |
524 | 496 |
525 // If the task manager is already listening, just post a task to execute | 497 // If the task manager is already listening, just post a task to execute |
526 // which will invoke the callback once we have returned from this function. | 498 // which will invoke the callback once we have returned from this function. |
527 // Otherwise, wait for the notification that the task manager is done with | 499 // Otherwise, wait for the notification that the task manager is done with |
528 // the data gathering. | 500 // the data gathering. |
529 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) { | 501 if (ProcessesAPIService::Get(profile_)->processes_event_router()-> |
| 502 is_task_manager_listening()) { |
530 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 503 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
531 &GetProcessIdForTabFunction::GetProcessIdForTab, this)); | 504 &GetProcessIdForTabFunction::GetProcessIdForTab, this)); |
532 } else { | 505 } else { |
533 registrar_.Add(this, | 506 registrar_.Add(this, |
534 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, | 507 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, |
535 content::NotificationService::AllSources()); | 508 content::NotificationService::AllSources()); |
536 ProcessesEventRouter::GetInstance()->StartTaskManagerListening(); | 509 ProcessesAPIService::Get(profile_)->processes_event_router()-> |
| 510 StartTaskManagerListening(); |
537 } | 511 } |
538 | 512 |
539 return true; | 513 return true; |
540 #else | 514 #else |
541 error_ = errors::kExtensionNotSupported; | 515 error_ = errors::kExtensionNotSupported; |
542 return false; | 516 return false; |
543 #endif // defined(ENABLE_TASK_MANAGER) | 517 #endif // defined(ENABLE_TASK_MANAGER) |
544 } | 518 } |
545 | 519 |
546 void GetProcessIdForTabFunction::Observe( | 520 void GetProcessIdForTabFunction::Observe( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_)); | 554 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_)); |
581 | 555 |
582 // Add a reference, which is balanced in TerminateProcess to keep the object | 556 // Add a reference, which is balanced in TerminateProcess to keep the object |
583 // around and allow for the callback to be invoked. | 557 // around and allow for the callback to be invoked. |
584 AddRef(); | 558 AddRef(); |
585 | 559 |
586 // If the task manager is already listening, just post a task to execute | 560 // If the task manager is already listening, just post a task to execute |
587 // which will invoke the callback once we have returned from this function. | 561 // which will invoke the callback once we have returned from this function. |
588 // Otherwise, wait for the notification that the task manager is done with | 562 // Otherwise, wait for the notification that the task manager is done with |
589 // the data gathering. | 563 // the data gathering. |
590 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) { | 564 if (ProcessesAPIService::Get(profile_)->processes_event_router()-> |
| 565 is_task_manager_listening()) { |
591 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 566 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
592 &TerminateFunction::TerminateProcess, this)); | 567 &TerminateFunction::TerminateProcess, this)); |
593 } else { | 568 } else { |
594 registrar_.Add(this, | 569 registrar_.Add(this, |
595 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, | 570 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, |
596 content::NotificationService::AllSources()); | 571 content::NotificationService::AllSources()); |
597 ProcessesEventRouter::GetInstance()->StartTaskManagerListening(); | 572 ProcessesAPIService::Get(profile_)->processes_event_router()-> |
| 573 StartTaskManagerListening(); |
598 } | 574 } |
599 | 575 |
600 return true; | 576 return true; |
601 #else | 577 #else |
602 error_ = errors::kExtensionNotSupported; | 578 error_ = errors::kExtensionNotSupported; |
603 return false; | 579 return false; |
604 #endif // defined(ENABLE_TASK_MANAGER) | 580 #endif // defined(ENABLE_TASK_MANAGER) |
605 } | 581 } |
606 | 582 |
607 void TerminateFunction::Observe( | 583 void TerminateFunction::Observe( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 processes, &process_ids_)); | 642 processes, &process_ids_)); |
667 | 643 |
668 // Add a reference, which is balanced in GatherProcessInfo to keep the object | 644 // Add a reference, which is balanced in GatherProcessInfo to keep the object |
669 // around and allow for the callback to be invoked. | 645 // around and allow for the callback to be invoked. |
670 AddRef(); | 646 AddRef(); |
671 | 647 |
672 // If the task manager is already listening, just post a task to execute | 648 // If the task manager is already listening, just post a task to execute |
673 // which will invoke the callback once we have returned from this function. | 649 // which will invoke the callback once we have returned from this function. |
674 // Otherwise, wait for the notification that the task manager is done with | 650 // Otherwise, wait for the notification that the task manager is done with |
675 // the data gathering. | 651 // the data gathering. |
676 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) { | 652 if (ProcessesAPIService::Get(profile_)->processes_event_router()-> |
| 653 is_task_manager_listening()) { |
677 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 654 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
678 &GetProcessInfoFunction::GatherProcessInfo, this)); | 655 &GetProcessInfoFunction::GatherProcessInfo, this)); |
679 } else { | 656 } else { |
680 registrar_.Add(this, | 657 registrar_.Add(this, |
681 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, | 658 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, |
682 content::NotificationService::AllSources()); | 659 content::NotificationService::AllSources()); |
683 ProcessesEventRouter::GetInstance()->StartTaskManagerListening(); | 660 ProcessesAPIService::Get(profile_)->processes_event_router()-> |
| 661 StartTaskManagerListening(); |
684 } | 662 } |
685 return true; | 663 return true; |
686 | 664 |
687 #else | 665 #else |
688 error_ = errors::kExtensionNotSupported; | 666 error_ = errors::kExtensionNotSupported; |
689 return false; | 667 return false; |
690 #endif // defined(ENABLE_TASK_MANAGER) | 668 #endif // defined(ENABLE_TASK_MANAGER) |
691 } | 669 } |
692 | 670 |
693 void GetProcessInfoFunction::Observe( | 671 void GetProcessInfoFunction::Observe( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 | 719 |
742 SetResult(processes); | 720 SetResult(processes); |
743 SendResponse(true); | 721 SendResponse(true); |
744 | 722 |
745 // Balance the AddRef in the RunImpl. | 723 // Balance the AddRef in the RunImpl. |
746 Release(); | 724 Release(); |
747 #endif // defined(ENABLE_TASK_MANAGER) | 725 #endif // defined(ENABLE_TASK_MANAGER) |
748 } | 726 } |
749 | 727 |
750 } // namespace extensions | 728 } // namespace extensions |
OLD | NEW |