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

Side by Side Diff: chrome/browser/extensions/api/processes/processes_api.cc

Issue 11359081: Lazy initialization for ProcessesEventRouter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixor Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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_factory.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
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
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
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, 478 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) {
486 scoped_ptr<ListValue> event_args) { 479 extensions::EventRouter* router =
487 for (ProfileSet::iterator it = profiles_.begin(); 480 extensions::ExtensionSystem::Get(profile_)->event_router();
488 it != profiles_.end(); ++it) { 481 if (router && router->HasEventListener(event_name))
489 Profile* profile = *it; 482 return true;
490 scoped_ptr<ListValue> event_args_copy(event_args->DeepCopy()); 483 return false;
491 DispatchEvent(profile, event_name, event_args_copy.Pass());
492 }
493 } 484 }
494 485
495 // In order to determine whether there are any listeners for the event of 486 ProcessesAPI::ProcessesAPI(Profile* profile)
496 // interest, we need to ask each profile whether it has one registered. 487 : profile_(profile),
497 // We only need to look for the profiles that have registered with the 488 processes_event_router_(new ProcessesEventRouter(profile)) {
498 // this extension API. 489 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
499 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { 490 this, processes_api_constants::kOnUpdated);
500 for (ProfileSet::iterator it = profiles_.begin(); 491 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
501 it != profiles_.end(); ++it) { 492 this, processes_api_constants::kOnUpdatedWithMemory);
502 Profile* profile = *it; 493 }
503 extensions::EventRouter* router =
504 extensions::ExtensionSystem::Get(profile)->event_router();
505 if (!router)
506 continue;
507 494
508 if (router->HasEventListener(event_name)) 495 ProcessesAPI::~ProcessesAPI() {
509 return true; 496 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
510 } 497 }
511 return false; 498
499 // static
500 ProcessesAPI* ProcessesAPI::Get(Profile* profile) {
501 return ProcessesAPIFactory::GetForProfile(profile);
502 }
503
504 void ProcessesAPI::OnListenerAdded(const std::string& event_name) {
505 // We lazily tell the TaskManager to start updating when listeners to the
506 // processes.onUpdated or processes.onUpdatedWithMemory events arrive.
507 processes_event_router_->ListenerAdded();
508 }
509
510 void ProcessesAPI::OnListenerRemoved(const std::string& event_name) {
511 // If a processes.onUpdated or processes.onUpdatedWithMemory event listener
512 // is removed (or a process with one exits), then we let the extension API
513 // know that it has one fewer listener.
514 processes_event_router_->ListenerRemoved();
512 } 515 }
513 516
514 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { 517 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) {
515 } 518 }
516 519
517 bool GetProcessIdForTabFunction::RunImpl() { 520 bool GetProcessIdForTabFunction::RunImpl() {
518 #if defined(ENABLE_TASK_MANAGER) 521 #if defined(ENABLE_TASK_MANAGER)
519 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); 522 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_));
520 523
521 // Add a reference, which is balanced in GetProcessIdForTab to keep the object 524 // Add a reference, which is balanced in GetProcessIdForTab to keep the object
522 // around and allow for the callback to be invoked. 525 // around and allow for the callback to be invoked.
523 AddRef(); 526 AddRef();
524 527
525 // If the task manager is already listening, just post a task to execute 528 // 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. 529 // 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 530 // Otherwise, wait for the notification that the task manager is done with
528 // the data gathering. 531 // the data gathering.
529 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) { 532 if (ProcessesAPI::Get(profile_)->processes_event_router()->
533 is_task_manager_listening()) {
530 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 534 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
531 &GetProcessIdForTabFunction::GetProcessIdForTab, this)); 535 &GetProcessIdForTabFunction::GetProcessIdForTab, this));
532 } else { 536 } else {
533 registrar_.Add(this, 537 registrar_.Add(this,
534 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, 538 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY,
535 content::NotificationService::AllSources()); 539 content::NotificationService::AllSources());
536 ProcessesEventRouter::GetInstance()->StartTaskManagerListening(); 540 ProcessesAPI::Get(profile_)->processes_event_router()->
541 StartTaskManagerListening();
537 } 542 }
538 543
539 return true; 544 return true;
540 #else 545 #else
541 error_ = errors::kExtensionNotSupported; 546 error_ = errors::kExtensionNotSupported;
542 return false; 547 return false;
543 #endif // defined(ENABLE_TASK_MANAGER) 548 #endif // defined(ENABLE_TASK_MANAGER)
544 } 549 }
545 550
546 void GetProcessIdForTabFunction::Observe( 551 void GetProcessIdForTabFunction::Observe(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_)); 585 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_));
581 586
582 // Add a reference, which is balanced in TerminateProcess to keep the object 587 // Add a reference, which is balanced in TerminateProcess to keep the object
583 // around and allow for the callback to be invoked. 588 // around and allow for the callback to be invoked.
584 AddRef(); 589 AddRef();
585 590
586 // If the task manager is already listening, just post a task to execute 591 // 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. 592 // 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 593 // Otherwise, wait for the notification that the task manager is done with
589 // the data gathering. 594 // the data gathering.
590 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) { 595 if (ProcessesAPI::Get(profile_)->processes_event_router()->
596 is_task_manager_listening()) {
591 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 597 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
592 &TerminateFunction::TerminateProcess, this)); 598 &TerminateFunction::TerminateProcess, this));
593 } else { 599 } else {
594 registrar_.Add(this, 600 registrar_.Add(this,
595 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, 601 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY,
596 content::NotificationService::AllSources()); 602 content::NotificationService::AllSources());
597 ProcessesEventRouter::GetInstance()->StartTaskManagerListening(); 603 ProcessesAPI::Get(profile_)->processes_event_router()->
604 StartTaskManagerListening();
598 } 605 }
599 606
600 return true; 607 return true;
601 #else 608 #else
602 error_ = errors::kExtensionNotSupported; 609 error_ = errors::kExtensionNotSupported;
603 return false; 610 return false;
604 #endif // defined(ENABLE_TASK_MANAGER) 611 #endif // defined(ENABLE_TASK_MANAGER)
605 } 612 }
606 613
607 void TerminateFunction::Observe( 614 void TerminateFunction::Observe(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 processes, &process_ids_)); 673 processes, &process_ids_));
667 674
668 // Add a reference, which is balanced in GatherProcessInfo to keep the object 675 // Add a reference, which is balanced in GatherProcessInfo to keep the object
669 // around and allow for the callback to be invoked. 676 // around and allow for the callback to be invoked.
670 AddRef(); 677 AddRef();
671 678
672 // If the task manager is already listening, just post a task to execute 679 // 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. 680 // 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 681 // Otherwise, wait for the notification that the task manager is done with
675 // the data gathering. 682 // the data gathering.
676 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) { 683 if (ProcessesAPI::Get(profile_)->processes_event_router()->
684 is_task_manager_listening()) {
677 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 685 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
678 &GetProcessInfoFunction::GatherProcessInfo, this)); 686 &GetProcessInfoFunction::GatherProcessInfo, this));
679 } else { 687 } else {
680 registrar_.Add(this, 688 registrar_.Add(this,
681 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, 689 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY,
682 content::NotificationService::AllSources()); 690 content::NotificationService::AllSources());
683 ProcessesEventRouter::GetInstance()->StartTaskManagerListening(); 691 ProcessesAPI::Get(profile_)->processes_event_router()->
692 StartTaskManagerListening();
684 } 693 }
685 return true; 694 return true;
686 695
687 #else 696 #else
688 error_ = errors::kExtensionNotSupported; 697 error_ = errors::kExtensionNotSupported;
689 return false; 698 return false;
690 #endif // defined(ENABLE_TASK_MANAGER) 699 #endif // defined(ENABLE_TASK_MANAGER)
691 } 700 }
692 701
693 void GetProcessInfoFunction::Observe( 702 void GetProcessInfoFunction::Observe(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 750
742 SetResult(processes); 751 SetResult(processes);
743 SendResponse(true); 752 SendResponse(true);
744 753
745 // Balance the AddRef in the RunImpl. 754 // Balance the AddRef in the RunImpl.
746 Release(); 755 Release();
747 #endif // defined(ENABLE_TASK_MANAGER) 756 #endif // defined(ENABLE_TASK_MANAGER)
748 } 757 }
749 758
750 } // namespace extensions 759 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698