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

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

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

Powered by Google App Engine
This is Rietveld 408576698