| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 14 #include "chrome/browser/profiles/profile.h" |
| 14 | 15 |
| 15 class GURL; | 16 class GURL; |
| 16 class Profile; | |
| 17 | 17 |
| 18 // This class forwards events to ExtensionEventRouters. | 18 // This class forwards events to ExtensionEventRouters. |
| 19 // The advantages of this class over direct usage of ExtensionEventRouters are: | 19 // The advantages of this class over direct usage of ExtensionEventRouters are: |
| 20 // - this class is thread-safe, you can call the functions from UI and IO | 20 // - this class is thread-safe, you can call the functions from UI and IO |
| 21 // thread. | 21 // thread. |
| 22 // - the class can handle if a profile is deleted between the time of sending | 22 // - the class can handle if a profile is deleted between the time of sending |
| 23 // the event from the IO thread to the UI thread. | 23 // the event from the IO thread to the UI thread. |
| 24 // - this class can be used in contexts that are not governed by a profile, e.g. | 24 // - this class can be used in contexts that are not governed by a profile, e.g. |
| 25 // by system URLRequestContexts. In these cases the |restrict_to_profile| | 25 // by system URLRequestContexts. In these cases the |restrict_to_profile| |
| 26 // parameter remains NULL and events are broadcasted to all profiles. | 26 // parameter remains NULL and events are broadcasted to all profiles. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 46 const std::string& event_name, | 46 const std::string& event_name, |
| 47 const std::string& event_args, | 47 const std::string& event_args, |
| 48 const GURL& event_url); | 48 const GURL& event_url); |
| 49 | 49 |
| 50 // Calls | 50 // Calls |
| 51 // DispatchEventToRenderers(event_name, event_args, | 51 // DispatchEventToRenderers(event_name, event_args, |
| 52 // use_profile_to_restrict_events ? profile : NULL, event_url) | 52 // use_profile_to_restrict_events ? profile : NULL, event_url) |
| 53 // on |profile|'s ExtensionEventRouter. May be called on any thread. | 53 // on |profile|'s ExtensionEventRouter. May be called on any thread. |
| 54 void DispatchEventToRenderers(const std::string& event_name, | 54 void DispatchEventToRenderers(const std::string& event_name, |
| 55 const std::string& event_args, | 55 const std::string& event_args, |
| 56 Profile* profile, | 56 ProfileId profile_id, |
| 57 bool use_profile_to_restrict_events, | 57 bool use_profile_to_restrict_events, |
| 58 const GURL& event_url); | 58 const GURL& event_url); |
| 59 | 59 |
| 60 // Calls | 60 // Calls |
| 61 // DispatchEventToExtension(extension_id, event_name, event_args, | 61 // DispatchEventToExtension(extension_id, event_name, event_args, |
| 62 // use_profile_to_restrict_events ? profile : NULL, event_url) | 62 // use_profile_to_restrict_events ? profile : NULL, event_url) |
| 63 // on |profile|'s ExtensionEventRouter. May be called on any thread. | 63 // on |profile|'s ExtensionEventRouter. May be called on any thread. |
| 64 void DispatchEventToExtension(const std::string& extension_id, | 64 void DispatchEventToExtension(const std::string& extension_id, |
| 65 const std::string& event_name, | 65 const std::string& event_name, |
| 66 const std::string& event_args, | 66 const std::string& event_args, |
| 67 Profile* profile, | 67 ProfileId profile_id, |
| 68 bool use_profile_to_restrict_events, | 68 bool use_profile_to_restrict_events, |
| 69 const GURL& event_url); | 69 const GURL& event_url); |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 // Protected for testing. | 72 // Protected for testing. |
| 73 virtual ~ExtensionEventRouterForwarder(); | 73 virtual ~ExtensionEventRouterForwarder(); |
| 74 | 74 |
| 75 // Calls DispatchEventToRenderers or DispatchEventToExtension (depending on | 75 // Calls DispatchEventToRenderers or DispatchEventToExtension (depending on |
| 76 // whether extension_id == "" or not) of |profile|'s ExtensionEventRouter. | 76 // whether extension_id == "" or not) of |profile|'s ExtensionEventRouter. |
| 77 // |profile| may never be NULL. | 77 // |profile| may never be NULL. |
| 78 // Virtual for testing. | 78 // Virtual for testing. |
| 79 virtual void CallExtensionEventRouter(Profile* profile, | 79 virtual void CallExtensionEventRouter(Profile* profile, |
| 80 const std::string& extension_id, | 80 const std::string& extension_id, |
| 81 const std::string& event_name, | 81 const std::string& event_name, |
| 82 const std::string& event_args, | 82 const std::string& event_args, |
| 83 Profile* restrict_to_profile, | 83 Profile* restrict_to_profile, |
| 84 const GURL& event_url); | 84 const GURL& event_url); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 friend class base::RefCountedThreadSafe<ExtensionEventRouterForwarder>; | 87 friend class base::RefCountedThreadSafe<ExtensionEventRouterForwarder>; |
| 88 | 88 |
| 89 // Helper function for {Broadcast,Dispatch}EventTo{Extension,Renderers}. | 89 // Helper function for {Broadcast,Dispatch}EventTo{Extension,Renderers}. |
| 90 void HandleEvent(const std::string& extension_id, | 90 void HandleEvent(const std::string& extension_id, |
| 91 const std::string& event_name, | 91 const std::string& event_name, |
| 92 const std::string& event_args, | 92 const std::string& event_args, |
| 93 Profile* profile, | 93 ProfileId profile_id, |
| 94 bool use_profile_to_restrict_events, | 94 bool use_profile_to_restrict_events, |
| 95 const GURL& event_url); | 95 const GURL& event_url); |
| 96 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouterForwarder); | 97 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouterForwarder); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ | 100 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ |
| OLD | NEW |