| OLD | NEW |
| 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/dial/dial_api.h" | 5 #include "chrome/browser/extensions/api/dial/dial_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" | 10 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace extensions { | 35 namespace extensions { |
| 36 | 36 |
| 37 namespace dial = api::dial; | 37 namespace dial = api::dial; |
| 38 | 38 |
| 39 DialAPI::DialAPI(Profile* profile) | 39 DialAPI::DialAPI(Profile* profile) |
| 40 : RefcountedBrowserContextKeyedService(BrowserThread::IO), | 40 : RefcountedBrowserContextKeyedService(BrowserThread::IO), |
| 41 profile_(profile) { | 41 profile_(profile) { |
| 42 ExtensionSystem::Get(profile)->event_router()->RegisterObserver( | 42 EventRouter::Get(profile) |
| 43 this, dial::OnDeviceList::kEventName); | 43 ->RegisterObserver(this, dial::OnDeviceList::kEventName); |
| 44 } | 44 } |
| 45 | 45 |
| 46 DialAPI::~DialAPI() {} | 46 DialAPI::~DialAPI() {} |
| 47 | 47 |
| 48 DialRegistry* DialAPI::dial_registry() { | 48 DialRegistry* DialAPI::dial_registry() { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 50 if (!dial_registry_.get()) { | 50 if (!dial_registry_.get()) { |
| 51 dial_registry_.reset(new DialRegistry(this, | 51 dial_registry_.reset(new DialRegistry(this, |
| 52 TimeDelta::FromSeconds(kDialRefreshIntervalSecs), | 52 TimeDelta::FromSeconds(kDialRefreshIntervalSecs), |
| 53 TimeDelta::FromSeconds(kDialExpirationSecs), | 53 TimeDelta::FromSeconds(kDialExpirationSecs), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 for (DialRegistry::DeviceList::const_iterator it = devices.begin(); | 101 for (DialRegistry::DeviceList::const_iterator it = devices.begin(); |
| 102 it != devices.end(); ++it) { | 102 it != devices.end(); ++it) { |
| 103 linked_ptr<api::dial::DialDevice> api_device = | 103 linked_ptr<api::dial::DialDevice> api_device = |
| 104 make_linked_ptr(new api::dial::DialDevice); | 104 make_linked_ptr(new api::dial::DialDevice); |
| 105 it->FillDialDevice(api_device.get()); | 105 it->FillDialDevice(api_device.get()); |
| 106 args.push_back(api_device); | 106 args.push_back(api_device); |
| 107 } | 107 } |
| 108 scoped_ptr<base::ListValue> results = api::dial::OnDeviceList::Create(args); | 108 scoped_ptr<base::ListValue> results = api::dial::OnDeviceList::Create(args); |
| 109 scoped_ptr<Event> event( | 109 scoped_ptr<Event> event( |
| 110 new Event(dial::OnDeviceList::kEventName, results.Pass())); | 110 new Event(dial::OnDeviceList::kEventName, results.Pass())); |
| 111 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 111 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
| 112 BroadcastEvent(event.Pass()); | |
| 113 } | 112 } |
| 114 | 113 |
| 115 void DialAPI::SendErrorOnUIThread(const DialRegistry::DialErrorCode code) { | 114 void DialAPI::SendErrorOnUIThread(const DialRegistry::DialErrorCode code) { |
| 116 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 117 | 116 |
| 118 api::dial::DialError dial_error; | 117 api::dial::DialError dial_error; |
| 119 switch (code) { | 118 switch (code) { |
| 120 case DialRegistry::DIAL_NO_LISTENERS: | 119 case DialRegistry::DIAL_NO_LISTENERS: |
| 121 dial_error.code = api::dial::DIAL_ERROR_CODE_NO_LISTENERS; | 120 dial_error.code = api::dial::DIAL_ERROR_CODE_NO_LISTENERS; |
| 122 break; | 121 break; |
| 123 case DialRegistry::DIAL_NO_INTERFACES: | 122 case DialRegistry::DIAL_NO_INTERFACES: |
| 124 dial_error.code = api::dial::DIAL_ERROR_CODE_NO_VALID_NETWORK_INTERFACES; | 123 dial_error.code = api::dial::DIAL_ERROR_CODE_NO_VALID_NETWORK_INTERFACES; |
| 125 break; | 124 break; |
| 126 case DialRegistry::DIAL_CELLULAR_NETWORK: | 125 case DialRegistry::DIAL_CELLULAR_NETWORK: |
| 127 dial_error.code = api::dial::DIAL_ERROR_CODE_CELLULAR_NETWORK; | 126 dial_error.code = api::dial::DIAL_ERROR_CODE_CELLULAR_NETWORK; |
| 128 break; | 127 break; |
| 129 case DialRegistry::DIAL_NETWORK_DISCONNECTED: | 128 case DialRegistry::DIAL_NETWORK_DISCONNECTED: |
| 130 dial_error.code = api::dial::DIAL_ERROR_CODE_NETWORK_DISCONNECTED; | 129 dial_error.code = api::dial::DIAL_ERROR_CODE_NETWORK_DISCONNECTED; |
| 131 break; | 130 break; |
| 132 case DialRegistry::DIAL_SOCKET_ERROR: | 131 case DialRegistry::DIAL_SOCKET_ERROR: |
| 133 dial_error.code = api::dial::DIAL_ERROR_CODE_SOCKET_ERROR; | 132 dial_error.code = api::dial::DIAL_ERROR_CODE_SOCKET_ERROR; |
| 134 break; | 133 break; |
| 135 default: | 134 default: |
| 136 dial_error.code = api::dial::DIAL_ERROR_CODE_UNKNOWN; | 135 dial_error.code = api::dial::DIAL_ERROR_CODE_UNKNOWN; |
| 137 break; | 136 break; |
| 138 } | 137 } |
| 139 | 138 |
| 140 scoped_ptr<base::ListValue> results = api::dial::OnError::Create(dial_error); | 139 scoped_ptr<base::ListValue> results = api::dial::OnError::Create(dial_error); |
| 141 scoped_ptr<Event> event(new Event(dial::OnError::kEventName, results.Pass())); | 140 scoped_ptr<Event> event(new Event(dial::OnError::kEventName, results.Pass())); |
| 142 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 141 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
| 143 BroadcastEvent(event.Pass()); | |
| 144 } | 142 } |
| 145 | 143 |
| 146 void DialAPI::ShutdownOnUIThread() {} | 144 void DialAPI::ShutdownOnUIThread() {} |
| 147 | 145 |
| 148 namespace api { | 146 namespace api { |
| 149 | 147 |
| 150 DialDiscoverNowFunction::DialDiscoverNowFunction() | 148 DialDiscoverNowFunction::DialDiscoverNowFunction() |
| 151 : dial_(NULL), result_(false) { | 149 : dial_(NULL), result_(false) { |
| 152 } | 150 } |
| 153 | 151 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 168 if (!result_) | 166 if (!result_) |
| 169 error_ = kDialServiceError; | 167 error_ = kDialServiceError; |
| 170 | 168 |
| 171 SetResult(new base::FundamentalValue(result_)); | 169 SetResult(new base::FundamentalValue(result_)); |
| 172 return true; | 170 return true; |
| 173 } | 171 } |
| 174 | 172 |
| 175 } // namespace api | 173 } // namespace api |
| 176 | 174 |
| 177 } // namespace extensions | 175 } // namespace extensions |
| OLD | NEW |