| 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 <stddef.h> | 7 #include <stddef.h> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 97 | 97 | 
| 98 void DialAPI::SendEventOnUIThread(const DialRegistry::DeviceList& devices) { | 98 void DialAPI::SendEventOnUIThread(const DialRegistry::DeviceList& devices) { | 
| 99   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 99   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 100 | 100 | 
| 101   std::vector<api::dial::DialDevice> args; | 101   std::vector<api::dial::DialDevice> args; | 
| 102   for (const DialDeviceData& device : devices) { | 102   for (const DialDeviceData& device : devices) { | 
| 103     api::dial::DialDevice api_device; | 103     api::dial::DialDevice api_device; | 
| 104     device.FillDialDevice(&api_device); | 104     device.FillDialDevice(&api_device); | 
| 105     args.push_back(std::move(api_device)); | 105     args.push_back(std::move(api_device)); | 
| 106   } | 106   } | 
| 107   scoped_ptr<base::ListValue> results = api::dial::OnDeviceList::Create(args); | 107   std::unique_ptr<base::ListValue> results = | 
| 108   scoped_ptr<Event> event(new Event(events::DIAL_ON_DEVICE_LIST, | 108       api::dial::OnDeviceList::Create(args); | 
| 109                                     dial::OnDeviceList::kEventName, | 109   std::unique_ptr<Event> event(new Event(events::DIAL_ON_DEVICE_LIST, | 
| 110                                     std::move(results))); | 110                                          dial::OnDeviceList::kEventName, | 
|  | 111                                          std::move(results))); | 
| 111   EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); | 112   EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); | 
| 112 } | 113 } | 
| 113 | 114 | 
| 114 void DialAPI::SendErrorOnUIThread(const DialRegistry::DialErrorCode code) { | 115 void DialAPI::SendErrorOnUIThread(const DialRegistry::DialErrorCode code) { | 
| 115   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 116   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 116 | 117 | 
| 117   api::dial::DialError dial_error; | 118   api::dial::DialError dial_error; | 
| 118   switch (code) { | 119   switch (code) { | 
| 119     case DialRegistry::DIAL_NO_LISTENERS: | 120     case DialRegistry::DIAL_NO_LISTENERS: | 
| 120       dial_error.code = api::dial::DIAL_ERROR_CODE_NO_LISTENERS; | 121       dial_error.code = api::dial::DIAL_ERROR_CODE_NO_LISTENERS; | 
| 121       break; | 122       break; | 
| 122     case DialRegistry::DIAL_NO_INTERFACES: | 123     case DialRegistry::DIAL_NO_INTERFACES: | 
| 123       dial_error.code = api::dial::DIAL_ERROR_CODE_NO_VALID_NETWORK_INTERFACES; | 124       dial_error.code = api::dial::DIAL_ERROR_CODE_NO_VALID_NETWORK_INTERFACES; | 
| 124       break; | 125       break; | 
| 125     case DialRegistry::DIAL_CELLULAR_NETWORK: | 126     case DialRegistry::DIAL_CELLULAR_NETWORK: | 
| 126       dial_error.code = api::dial::DIAL_ERROR_CODE_CELLULAR_NETWORK; | 127       dial_error.code = api::dial::DIAL_ERROR_CODE_CELLULAR_NETWORK; | 
| 127       break; | 128       break; | 
| 128     case DialRegistry::DIAL_NETWORK_DISCONNECTED: | 129     case DialRegistry::DIAL_NETWORK_DISCONNECTED: | 
| 129       dial_error.code = api::dial::DIAL_ERROR_CODE_NETWORK_DISCONNECTED; | 130       dial_error.code = api::dial::DIAL_ERROR_CODE_NETWORK_DISCONNECTED; | 
| 130       break; | 131       break; | 
| 131     case DialRegistry::DIAL_SOCKET_ERROR: | 132     case DialRegistry::DIAL_SOCKET_ERROR: | 
| 132       dial_error.code = api::dial::DIAL_ERROR_CODE_SOCKET_ERROR; | 133       dial_error.code = api::dial::DIAL_ERROR_CODE_SOCKET_ERROR; | 
| 133       break; | 134       break; | 
| 134     default: | 135     default: | 
| 135       dial_error.code = api::dial::DIAL_ERROR_CODE_UNKNOWN; | 136       dial_error.code = api::dial::DIAL_ERROR_CODE_UNKNOWN; | 
| 136       break; | 137       break; | 
| 137   } | 138   } | 
| 138 | 139 | 
| 139   scoped_ptr<base::ListValue> results = api::dial::OnError::Create(dial_error); | 140   std::unique_ptr<base::ListValue> results = | 
| 140   scoped_ptr<Event> event(new Event( | 141       api::dial::OnError::Create(dial_error); | 
|  | 142   std::unique_ptr<Event> event(new Event( | 
| 141       events::DIAL_ON_ERROR, dial::OnError::kEventName, std::move(results))); | 143       events::DIAL_ON_ERROR, dial::OnError::kEventName, std::move(results))); | 
| 142   EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); | 144   EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); | 
| 143 } | 145 } | 
| 144 | 146 | 
| 145 void DialAPI::ShutdownOnUIThread() {} | 147 void DialAPI::ShutdownOnUIThread() {} | 
| 146 | 148 | 
| 147 namespace api { | 149 namespace api { | 
| 148 | 150 | 
| 149 DialDiscoverNowFunction::DialDiscoverNowFunction() | 151 DialDiscoverNowFunction::DialDiscoverNowFunction() | 
| 150     : dial_(NULL), result_(false) { | 152     : dial_(NULL), result_(false) { | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 164 | 166 | 
| 165 bool DialDiscoverNowFunction::Respond() { | 167 bool DialDiscoverNowFunction::Respond() { | 
| 166   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 168   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 167   SetResult(new base::FundamentalValue(result_)); | 169   SetResult(new base::FundamentalValue(result_)); | 
| 168   return true; | 170   return true; | 
| 169 } | 171 } | 
| 170 | 172 | 
| 171 }  // namespace api | 173 }  // namespace api | 
| 172 | 174 | 
| 173 }  // namespace extensions | 175 }  // namespace extensions | 
| OLD | NEW | 
|---|