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

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

Issue 11232066: Remove GetExtensionEventRouter from Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rerebase 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/tabs/tabs_constants.h" 16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
17 #include "chrome/browser/extensions/event_router.h" 17 #include "chrome/browser/extensions/event_router.h"
18 #include "chrome/browser/extensions/extension_function_util.h" 18 #include "chrome/browser/extensions/extension_function_util.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_system.h"
20 #include "chrome/browser/extensions/extension_tab_util.h" 21 #include "chrome/browser/extensions/extension_tab_util.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/task_manager/task_manager.h" 23 #include "chrome/browser/task_manager/task_manager.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents.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"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 // Third arg: The exit code for the process. 469 // Third arg: The exit code for the process.
469 args->Append(Value::CreateIntegerValue(details->exit_code)); 470 args->Append(Value::CreateIntegerValue(details->exit_code));
470 471
471 NotifyProfiles(keys::kOnExited, args.Pass()); 472 NotifyProfiles(keys::kOnExited, args.Pass());
472 #endif // defined(ENABLE_TASK_MANAGER) 473 #endif // defined(ENABLE_TASK_MANAGER)
473 } 474 }
474 475
475 void ProcessesEventRouter::DispatchEvent(Profile* profile, 476 void ProcessesEventRouter::DispatchEvent(Profile* profile,
476 const char* event_name, 477 const char* event_name,
477 scoped_ptr<ListValue> event_args) { 478 scoped_ptr<ListValue> event_args) {
478 if (profile && profile->GetExtensionEventRouter()) { 479 if (profile && extensions::ExtensionSystem::Get(profile)->event_router()) {
479 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 480 extensions::ExtensionSystem::Get(profile)->event_router()->
480 event_name, event_args.Pass(), NULL, GURL(), 481 DispatchEventToRenderers(event_name, event_args.Pass(), NULL, GURL(),
481 extensions::EventFilteringInfo()); 482 extensions::EventFilteringInfo());
482 } 483 }
483 } 484 }
484 485
485 void ProcessesEventRouter::NotifyProfiles(const char* event_name, 486 void ProcessesEventRouter::NotifyProfiles(const char* event_name,
486 scoped_ptr<ListValue> event_args) { 487 scoped_ptr<ListValue> event_args) {
487 for (ProfileSet::iterator it = profiles_.begin(); 488 for (ProfileSet::iterator it = profiles_.begin();
488 it != profiles_.end(); ++it) { 489 it != profiles_.end(); ++it) {
489 Profile* profile = *it; 490 Profile* profile = *it;
490 scoped_ptr<ListValue> event_args_copy(event_args->DeepCopy()); 491 scoped_ptr<ListValue> event_args_copy(event_args->DeepCopy());
491 DispatchEvent(profile, event_name, event_args_copy.Pass()); 492 DispatchEvent(profile, event_name, event_args_copy.Pass());
492 } 493 }
493 } 494 }
494 495
495 // In order to determine whether there are any listeners for the event of 496 // 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 // 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 // We only need to look for the profiles that have registered with the
498 // this extension API. 499 // this extension API.
499 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { 500 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) {
500 for (ProfileSet::iterator it = profiles_.begin(); 501 for (ProfileSet::iterator it = profiles_.begin();
501 it != profiles_.end(); ++it) { 502 it != profiles_.end(); ++it) {
502 Profile* profile = *it; 503 Profile* profile = *it;
503 extensions::EventRouter* router = profile->GetExtensionEventRouter(); 504 extensions::EventRouter* router =
505 extensions::ExtensionSystem::Get(profile)->event_router();
504 if (!router) 506 if (!router)
505 continue; 507 continue;
506 508
507 if (router->HasEventListener(event_name)) 509 if (router->HasEventListener(event_name))
508 return true; 510 return true;
509 } 511 }
510 return false; 512 return false;
511 } 513 }
512 514
513 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { 515 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 742
741 SetResult(processes); 743 SetResult(processes);
742 SendResponse(true); 744 SendResponse(true);
743 745
744 // Balance the AddRef in the RunImpl. 746 // Balance the AddRef in the RunImpl.
745 Release(); 747 Release();
746 #endif // defined(ENABLE_TASK_MANAGER) 748 #endif // defined(ENABLE_TASK_MANAGER)
747 } 749 }
748 750
749 } // namespace extensions 751 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698