Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: remoting/webapp/me2mom/client_screen.js

Issue 8573024: Clean up client state callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Functions related to the 'client screen' for Chromoting. 7 * Functions related to the 'client screen' for Chromoting.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } else { 172 } else {
173 showConnectError_(remoting.Error.AUTHENTICATION_FAILED); 173 showConnectError_(remoting.Error.AUTHENTICATION_FAILED);
174 } 174 }
175 } 175 }
176 176
177 /** 177 /**
178 * Callback function called when the state of the client plugin changes. The 178 * Callback function called when the state of the client plugin changes. The
179 * current state is available via the |state| member variable. 179 * current state is available via the |state| member variable.
180 * 180 *
181 * @param {number} oldState The previous state of the plugin. 181 * @param {number} oldState The previous state of the plugin.
182 * @param {number} newState The current state of the plugin.
182 */ 183 */
183 // TODO(jamiewalch): Make this pass both the current and old states to avoid 184 // TODO(jamiewalch): Make this pass both the current and old states to avoid
184 // race conditions. 185 // race conditions.
185 function onClientStateChange_(oldState) { 186 function onClientStateChange_(oldState, newState) {
186 if (!remoting.clientSession) { 187 if (!remoting.clientSession) {
187 // If the connection has been cancelled, then we no longer have a reference 188 // If the connection has been cancelled, then we no longer have a reference
188 // to the session object and should ignore any state changes. 189 // to the session object and should ignore any state changes.
189 return; 190 return;
190 } 191 }
191 var state = remoting.clientSession.state; 192 if (newState == remoting.ClientSession.State.CREATED) {
192 if (state == remoting.ClientSession.State.CREATED) {
193 remoting.debug.log('Created plugin'); 193 remoting.debug.log('Created plugin');
194 194
195 } else if (state == remoting.ClientSession.State.BAD_PLUGIN_VERSION) { 195 } else if (newState == remoting.ClientSession.State.BAD_PLUGIN_VERSION) {
196 showConnectError_(remoting.Error.BAD_PLUGIN_VERSION); 196 showConnectError_(remoting.Error.BAD_PLUGIN_VERSION);
197 197
198 } else if (state == remoting.ClientSession.State.CONNECTING) { 198 } else if (newState == remoting.ClientSession.State.CONNECTING) {
199 remoting.debug.log('Connecting as ' + remoting.oauth2.getCachedEmail()); 199 remoting.debug.log('Connecting as ' + remoting.oauth2.getCachedEmail());
200 200
201 } else if (state == remoting.ClientSession.State.INITIALIZING) { 201 } else if (newState == remoting.ClientSession.State.INITIALIZING) {
202 remoting.debug.log('Initializing connection'); 202 remoting.debug.log('Initializing connection');
203 203
204 } else if (state == remoting.ClientSession.State.CONNECTED) { 204 } else if (newState == remoting.ClientSession.State.CONNECTED) {
205 if (remoting.clientSession) { 205 if (remoting.clientSession) {
206 remoting.setMode(remoting.AppMode.IN_SESSION); 206 remoting.setMode(remoting.AppMode.IN_SESSION);
207 recenterToolbar_(); 207 recenterToolbar_();
208 showToolbarPreview_(); 208 showToolbarPreview_();
209 updateStatistics_(); 209 updateStatistics_();
210 } 210 }
211 211
212 } else if (state == remoting.ClientSession.State.CLOSED) { 212 } else if (newState == remoting.ClientSession.State.CLOSED) {
213 if (oldState == remoting.ClientSession.State.CONNECTED) { 213 if (oldState == remoting.ClientSession.State.CONNECTED) {
214 remoting.clientSession.removePlugin(); 214 remoting.clientSession.removePlugin();
215 remoting.clientSession = null; 215 remoting.clientSession = null;
216 remoting.debug.log('Connection closed by host'); 216 remoting.debug.log('Connection closed by host');
217 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED); 217 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED);
218 } else { 218 } else {
219 // The transition from CONNECTING to CLOSED state may happen 219 // The transition from CONNECTING to CLOSED state may happen
220 // only with older client plugins. Current version should go the 220 // only with older client plugins. Current version should go the
221 // FAILED state when connection fails. 221 // FAILED state when connection fails.
222 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); 222 showConnectError_(remoting.Error.INVALID_ACCESS_CODE);
223 } 223 }
224 224
225 } else if (state == remoting.ClientSession.State.CONNECTION_FAILED) { 225 } else if (newState == remoting.ClientSession.State.CONNECTION_FAILED) {
226 remoting.debug.log('Client plugin reported connection failed: ' + 226 remoting.debug.log('Client plugin reported connection failed: ' +
227 remoting.clientSession.error); 227 remoting.clientSession.error);
228 if (remoting.clientSession.error == 228 if (remoting.clientSession.error ==
229 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE) { 229 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE) {
230 showConnectError_(remoting.Error.HOST_IS_OFFLINE); 230 showConnectError_(remoting.Error.HOST_IS_OFFLINE);
231 } else if (remoting.clientSession.error == 231 } else if (remoting.clientSession.error ==
232 remoting.ClientSession.ConnectionError.SESSION_REJECTED) { 232 remoting.ClientSession.ConnectionError.SESSION_REJECTED) {
233 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); 233 showConnectError_(remoting.Error.INVALID_ACCESS_CODE);
234 } else if (remoting.clientSession.error == 234 } else if (remoting.clientSession.error ==
235 remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL) { 235 remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL) {
236 showConnectError_(remoting.Error.INCOMPATIBLE_PROTOCOL); 236 showConnectError_(remoting.Error.INCOMPATIBLE_PROTOCOL);
237 } else if (remoting.clientSession.error == 237 } else if (remoting.clientSession.error ==
238 remoting.ClientSession.ConnectionError.NETWORK_FAILURE) { 238 remoting.ClientSession.ConnectionError.NETWORK_FAILURE) {
239 showConnectError_(remoting.Error.GENERIC); 239 showConnectError_(remoting.Error.GENERIC);
240 } else { 240 } else {
241 showConnectError_(remoting.Error.GENERIC); 241 showConnectError_(remoting.Error.GENERIC);
242 } 242 }
243 243
244 } else { 244 } else {
245 remoting.debug.log('Unexpected client plugin state: ' + state); 245 remoting.debug.log('Unexpected client plugin state: ' + newState);
246 // This should only happen if the web-app and client plugin get out of 246 // This should only happen if the web-app and client plugin get out of
247 // sync, and even then the version check should allow compatibility. 247 // sync, and even then the version check should allow compatibility.
248 showConnectError_(remoting.Error.MISSING_PLUGIN); 248 showConnectError_(remoting.Error.MISSING_PLUGIN);
249 } 249 }
250 } 250 }
251 251
252 /** 252 /**
253 * Create the client session object and initiate the connection. 253 * Create the client session object and initiate the connection.
254 * 254 *
255 * @return {void} Nothing. 255 * @return {void} Nothing.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 remoting.clientSession.createPluginAndConnect( 436 remoting.clientSession.createPluginAndConnect(
437 document.getElementById('session-mode'), 437 document.getElementById('session-mode'),
438 token); 438 token);
439 }; 439 };
440 440
441 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); 441 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
442 remoting.oauth2.callWithToken(createPluginAndConnect); 442 remoting.oauth2.callWithToken(createPluginAndConnect);
443 } 443 }
444 444
445 }()); 445 }());
OLDNEW
« no previous file with comments | « remoting/client/plugin/chromoting_scriptable_object.cc ('k') | remoting/webapp/me2mom/client_session.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698