| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/api/display_source/display_source_event_router.h" | 5 #include "extensions/browser/api/display_source/display_source_event_router.h" |
| 6 | 6 |
| 7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
| 8 #include "extensions/browser/api/display_source/display_source_api.h" | 8 #include "extensions/browser/api/display_source/display_source_api.h" |
| 9 #include "extensions/browser/api/display_source/display_source_connection_delega
te_factory.h" | 9 #include "extensions/browser/api/display_source/display_source_connection_delega
te_factory.h" |
| 10 #include "extensions/common/api/display_source.h" | 10 #include "extensions/common/api/display_source.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 bool should_listen = event_router->HasEventListener( | 58 bool should_listen = event_router->HasEventListener( |
| 59 api::display_source::OnSinksUpdated::kEventName); | 59 api::display_source::OnSinksUpdated::kEventName); |
| 60 if (should_listen && !listening_) { | 60 if (should_listen && !listening_) { |
| 61 DisplaySourceConnectionDelegate* delegate = | 61 DisplaySourceConnectionDelegate* delegate = |
| 62 DisplaySourceConnectionDelegateFactory::GetForBrowserContext( | 62 DisplaySourceConnectionDelegateFactory::GetForBrowserContext( |
| 63 browser_context_); | 63 browser_context_); |
| 64 if (delegate) { | 64 if (delegate) { |
| 65 delegate->AddObserver(this); | 65 delegate->AddObserver(this); |
| 66 delegate->StartWatchingSinks(); | 66 delegate->StartWatchingAvailableSinks(); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 if (!should_listen && listening_) { | 69 if (!should_listen && listening_) { |
| 70 DisplaySourceConnectionDelegate* delegate = | 70 DisplaySourceConnectionDelegate* delegate = |
| 71 DisplaySourceConnectionDelegateFactory::GetForBrowserContext( | 71 DisplaySourceConnectionDelegateFactory::GetForBrowserContext( |
| 72 browser_context_); | 72 browser_context_); |
| 73 if (delegate) { | 73 if (delegate) { |
| 74 delegate->RemoveObserver(this); | 74 delegate->RemoveObserver(this); |
| 75 delegate->StopWatchingSinks(); | 75 delegate->StopWatchingAvailableSinks(); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 listening_ = should_listen; | 79 listening_ = should_listen; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void DisplaySourceEventRouter::OnSinksUpdated( | 82 void DisplaySourceEventRouter::OnSinksUpdated( |
| 83 const DisplaySourceSinkInfoList& sinks) { | 83 const DisplaySourceSinkInfoList& sinks) { |
| 84 EventRouter* event_router = EventRouter::Get(browser_context_); | 84 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 85 if (!event_router) | 85 if (!event_router) |
| 86 return; | 86 return; |
| 87 scoped_ptr<base::ListValue> args( | 87 scoped_ptr<base::ListValue> args( |
| 88 api::display_source::OnSinksUpdated::Create(sinks)); | 88 api::display_source::OnSinksUpdated::Create(sinks)); |
| 89 scoped_ptr<Event> sinks_updated_event( | 89 scoped_ptr<Event> sinks_updated_event( |
| 90 new Event(events::DISPLAY_SOURCE_ON_SINKS_UPDATED, | 90 new Event(events::DISPLAY_SOURCE_ON_SINKS_UPDATED, |
| 91 api::display_source::OnSinksUpdated::kEventName, args.Pass())); | 91 api::display_source::OnSinksUpdated::kEventName, args.Pass())); |
| 92 event_router->BroadcastEvent(sinks_updated_event.Pass()); | 92 event_router->BroadcastEvent(sinks_updated_event.Pass()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 DisplaySourceEventRouter* DisplaySourceEventRouter::Create( | 95 DisplaySourceEventRouter* DisplaySourceEventRouter::Create( |
| 96 content::BrowserContext* browser_context) { | 96 content::BrowserContext* browser_context) { |
| 97 return new DisplaySourceEventRouter(browser_context); | 97 return new DisplaySourceEventRouter(browser_context); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace extensions | 100 } // namespace extensions |
| OLD | NEW |