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