| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui/copresence_ui_handler.h" | 5 #include "chrome/browser/ui/webui/copresence_ui_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 js_directive->SetString("medium", FormatMedium( | 164 js_directive->SetString("medium", FormatMedium( |
| 165 directive.token_instruction().medium())); | 165 directive.token_instruction().medium())); |
| 166 js_directive->SetString("duration", ui::TimeFormat::Simple( | 166 js_directive->SetString("duration", ui::TimeFormat::Simple( |
| 167 ui::TimeFormat::FORMAT_DURATION, | 167 ui::TimeFormat::FORMAT_DURATION, |
| 168 ui::TimeFormat::LENGTH_LONG, | 168 ui::TimeFormat::LENGTH_LONG, |
| 169 base::TimeDelta::FromMilliseconds(directive.ttl_millis()))); | 169 base::TimeDelta::FromMilliseconds(directive.ttl_millis()))); |
| 170 | 170 |
| 171 js_directives.Append(js_directive.release()); | 171 js_directives.Append(js_directive.release()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 web_ui()->CallJavascriptFunction("refreshDirectives", js_directives); | 174 web_ui()->CallJavascriptFunctionUnsafe("refreshDirectives", js_directives); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void CopresenceUIHandler::TokenTransmitted(const TransmittedToken& token) { | 177 void CopresenceUIHandler::TokenTransmitted(const TransmittedToken& token) { |
| 178 web_ui()->CallJavascriptFunction("updateTransmittedToken", | 178 web_ui()->CallJavascriptFunctionUnsafe("updateTransmittedToken", |
| 179 *FormatToken(token)); | 179 *FormatToken(token)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void CopresenceUIHandler::TokenReceived(const ReceivedToken& token) { | 182 void CopresenceUIHandler::TokenReceived(const ReceivedToken& token) { |
| 183 web_ui()->CallJavascriptFunction("updateReceivedToken", | 183 web_ui()->CallJavascriptFunctionUnsafe("updateReceivedToken", |
| 184 *FormatToken(token)); | 184 *FormatToken(token)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void CopresenceUIHandler::HandlePopulateState(const ListValue* args) { | 187 void CopresenceUIHandler::HandlePopulateState(const ListValue* args) { |
| 188 DCHECK(args->empty()); | 188 DCHECK(args->empty()); |
| 189 DirectivesUpdated(); | 189 DirectivesUpdated(); |
| 190 // TODO(ckehoe): Pass tokens to JS as a batch. | 190 // TODO(ckehoe): Pass tokens to JS as a batch. |
| 191 for (const auto& token_entry : state_->transmitted_tokens()) | 191 for (const auto& token_entry : state_->transmitted_tokens()) |
| 192 TokenTransmitted(token_entry.second); | 192 TokenTransmitted(token_entry.second); |
| 193 for (const auto& token_entry : state_->received_tokens()) | 193 for (const auto& token_entry : state_->received_tokens()) |
| 194 TokenReceived(token_entry.second); | 194 TokenReceived(token_entry.second); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void CopresenceUIHandler::HandleClearState(const ListValue* args) { | 197 void CopresenceUIHandler::HandleClearState(const ListValue* args) { |
| 198 DCHECK(args->empty()); | 198 DCHECK(args->empty()); |
| 199 | 199 |
| 200 CopresenceService* service = GetCopresenceService(web_ui()); | 200 CopresenceService* service = GetCopresenceService(web_ui()); |
| 201 DCHECK(service); | 201 DCHECK(service); |
| 202 service->ResetState(); | 202 service->ResetState(); |
| 203 | 203 |
| 204 // CopresenceService::ResetState() deletes the CopresenceState object | 204 // CopresenceService::ResetState() deletes the CopresenceState object |
| 205 // we were using. We have to get the new one and reconnect to it. | 205 // we were using. We have to get the new one and reconnect to it. |
| 206 state_ = GetCopresenceState(service); | 206 state_ = GetCopresenceState(service); |
| 207 DCHECK(state_); | 207 DCHECK(state_); |
| 208 state_->AddObserver(this); | 208 state_->AddObserver(this); |
| 209 | 209 |
| 210 web_ui()->CallJavascriptFunction("clearTokens"); | 210 web_ui()->CallJavascriptFunctionUnsafe("clearTokens"); |
| 211 DirectivesUpdated(); | 211 DirectivesUpdated(); |
| 212 } | 212 } |
| OLD | NEW |