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 #include "chrome/browser/extensions/extension_io_event_router.h" | 5 #include "chrome/browser/extensions/extension_io_event_router.h" |
6 | 6 |
7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "chrome/browser/browser_thread.h" | 8 #include "chrome/browser/browser_thread.h" |
9 #include "chrome/browser/extensions/extension_event_router.h" | 9 #include "chrome/browser/extensions/extension_event_router.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 | 11 |
12 ExtensionIOEventRouter::ExtensionIOEventRouter(Profile* profile) | 12 ExtensionIOEventRouter::ExtensionIOEventRouter(Profile* profile) |
13 : profile_(profile) { | 13 : profile_(profile) { |
14 } | 14 } |
15 | 15 |
16 ExtensionIOEventRouter::~ExtensionIOEventRouter() { | 16 ExtensionIOEventRouter::~ExtensionIOEventRouter() { |
17 } | 17 } |
18 | 18 |
19 void ExtensionIOEventRouter::DispatchEventToExtension( | 19 void ExtensionIOEventRouter::DispatchEventToExtension( |
20 const std::string& extension_id, | 20 const std::string& extension_id, |
21 const std::string& event_name, | 21 const std::string& event_name, |
22 const std::string& event_args) const { | 22 const std::string& event_args) const { |
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
24 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 24 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
25 NewRunnableMethod(this, | 25 NewRunnableMethod(this, |
26 &ExtensionIOEventRouter::DispatchEventOnUIThread, | 26 &ExtensionIOEventRouter::DispatchEventOnUIThread, |
27 extension_id, event_name, event_args)); | 27 extension_id, event_name, event_args)); |
28 } | 28 } |
29 | 29 |
| 30 void ExtensionIOEventRouter::DispatchEventToRenderers( |
| 31 const std::string& event_name, |
| 32 const std::string& event_args, |
| 33 const GURL& event_url) const { |
| 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 35 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 36 NewRunnableMethod(this, |
| 37 &ExtensionIOEventRouter::DispatchEventToRenderersOnUIThread, |
| 38 event_name, event_args, event_url)); |
| 39 } |
| 40 |
30 void ExtensionIOEventRouter::DispatchEventOnUIThread( | 41 void ExtensionIOEventRouter::DispatchEventOnUIThread( |
31 const std::string& extension_id, | 42 const std::string& extension_id, |
32 const std::string& event_name, | 43 const std::string& event_name, |
33 const std::string& event_args) const { | 44 const std::string& event_args) const { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
35 | 46 |
36 // If the profile has gone away, we're shutting down. If there's no event | 47 // If the profile has gone away, we're shutting down. If there's no event |
37 // router, the extension system hasn't been initialized. | 48 // router, the extension system hasn't been initialized. |
38 if (!profile_ || !profile_->GetExtensionEventRouter()) | 49 if (!profile_ || !profile_->GetExtensionEventRouter()) |
39 return; | 50 return; |
40 | 51 |
41 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 52 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
42 extension_id, event_name, event_args, profile_, GURL()); | 53 extension_id, event_name, event_args, profile_, GURL()); |
43 } | 54 } |
| 55 |
| 56 void ExtensionIOEventRouter::DispatchEventToRenderersOnUIThread( |
| 57 const std::string& event_name, |
| 58 const std::string& event_args, |
| 59 const GURL& event_url) const { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 61 |
| 62 // If the profile has gone away, we're shutting down. If there's no event |
| 63 // router, the extension system hasn't been initialized. |
| 64 if (!profile_ || !profile_->GetExtensionEventRouter()) |
| 65 return; |
| 66 |
| 67 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 68 event_name, event_args, profile_, event_url); |
| 69 } |
OLD | NEW |