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

Side by Side Diff: Source/bindings/dart/DartController.cpp

Issue 128733002: Refactor service usage in Dartium (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/1700
Patch Set: Created 6 years, 11 months 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) 2009, Google Inc. 1 // Copyright (c) 2009, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // so weak handles strong, see the corresponding logic in 237 // so weak handles strong, see the corresponding logic in
238 // DartGCController. 238 // DartGCController.
239 domData->setReachableWeakHandle(Dart_NewWeakPersistentHandle(localHandle , 0, 0)); 239 domData->setReachableWeakHandle(Dart_NewWeakPersistentHandle(localHandle , 0, 0));
240 240
241 DartDebugServer::shared().registerIsolate(isolate); 241 DartDebugServer::shared().registerIsolate(isolate);
242 } 242 }
243 243
244 return isolate; 244 return isolate;
245 } 245 }
246 246
247
248 void DartController::createDOMEnabledIsolateIfNeeded(const String& scriptURL, co nst String& entryPoint, Document* document) 247 void DartController::createDOMEnabledIsolateIfNeeded(const String& scriptURL, co nst String& entryPoint, Document* document)
249 { 248 {
250 if (m_isolate) { 249 if (m_isolate) {
251 Dart_EnterIsolate(m_isolate); 250 Dart_EnterIsolate(m_isolate);
252 return; 251 return;
253 } 252 }
254 253
254 // Start the service.
255 bool result = DartService::Start(document);
256 UNUSED_PARAM(result);
257 ASSERT(result);
258 ASSERT(!Dart_CurrentIsolate());
259
255 // FIXME: proper error reporting. 260 // FIXME: proper error reporting.
256 char* errorMessage = 0; 261 char* errorMessage = 0;
257 m_isolate = createIsolate(scriptURL.utf8().data(), entryPoint.utf8().data(), document, true, &errorMessage); 262 m_isolate = createIsolate(scriptURL.utf8().data(), entryPoint.utf8().data(), document, true, &errorMessage);
258 ASSERT(m_isolate); 263 ASSERT(m_isolate);
259 if (getenv("DARTIUM_VMSERVICE")) {
260 // createIsolate exits with current isolate set to m_isolate, we need to
261 // exit it so we can startup the service.
262 Dart_ExitIsolate();
263
264 bool result = DartService::Start(document);
265 UNUSED_PARAM(result);
266 ASSERT(result);
267 ASSERT(!Dart_CurrentIsolate());
268
269 Dart_EnterIsolate(m_isolate);
270 Dart_EnterScope();
271 DartService::SendIsolateStartupMessage();
272 Dart_ExitScope();
273 }
274
275 } 264 }
276 265
277 void DartController::shutdownIsolate(Dart_Isolate isolate) 266 void DartController::shutdownIsolate(Dart_Isolate isolate)
278 { 267 {
279 DartDOMData* domData = DartDOMData::current(); 268 DartDOMData* domData = DartDOMData::current();
280 ASSERT(domData->isDOMEnabled()); 269 ASSERT(domData->isDOMEnabled());
281 // If the following assert triggers, we have hit dartbug.com/14183 270 // If the following assert triggers, we have hit dartbug.com/14183
282 // FIXME: keep the isolate alive until the recursion level is 0. 271 // FIXME: keep the isolate alive until the recursion level is 0.
283 ASSERT(!*(domData->recursion())); 272 ASSERT(!*(domData->recursion()));
284 DartDebugServer::shared().unregisterIsolate(isolate); 273 DartDebugServer::shared().unregisterIsolate(isolate);
285 DartIsolateDestructionObservers* observers = domData->isolateDestructionObse rvers(); 274 DartIsolateDestructionObservers* observers = domData->isolateDestructionObse rvers();
286 for (DartIsolateDestructionObservers::iterator it = observers->begin(); it ! = observers->end(); ++it) 275 for (DartIsolateDestructionObservers::iterator it = observers->begin(); it ! = observers->end(); ++it)
287 (*it)->isolateDestroyed(); 276 (*it)->isolateDestroyed();
288 Dart_ShutdownIsolate(); 277 Dart_ShutdownIsolate();
289 // Stop the service.
290 DartService::Stop();
291 delete domData; 278 delete domData;
292 } 279 }
293 280
294 DartController::DartController(Frame* frame) 281 DartController::DartController(Frame* frame)
295 : m_frame(frame) 282 : m_frame(frame)
296 , m_isolate(0) 283 , m_isolate(0)
297 , m_asyncLoader(0) 284 , m_asyncLoader(0)
298 , m_npObjectMap() 285 , m_npObjectMap()
299 { 286 {
300 // The DartController's constructor must be called in the Frame's 287 // The DartController's constructor must be called in the Frame's
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 390
404 applicationLoader->load(asyncLoader); 391 applicationLoader->load(asyncLoader);
405 Dart_IsolateMakeRunnable(m_isolate); 392 Dart_IsolateMakeRunnable(m_isolate);
406 } 393 }
407 394
408 private: 395 private:
409 Dart_Isolate m_isolate; 396 Dart_Isolate m_isolate;
410 String m_url; 397 String m_url;
411 }; 398 };
412 399
400
401 Dart_Isolate DartController::createServiceIsolateCallback(void* callbackData, ch ar** error)
402 {
403 Document* document = static_cast<Document*>(callbackData);
404 Dart_Isolate serviceIsolate = DartController::createIsolate("dart:vmservice_ dartium", "main", document, true, error);
405 Dart_ExitIsolate();
406 return serviceIsolate;
407 }
408
409
413 Dart_Isolate DartController::createPureIsolateCallback(const char* scriptURL, co nst char* entryPoint, void* data, char** errorMsg) 410 Dart_Isolate DartController::createPureIsolateCallback(const char* scriptURL, co nst char* entryPoint, void* data, char** errorMsg)
414 { 411 {
415 bool isSpawnUri = scriptURL ? true : false; 412 bool isSpawnUri = scriptURL ? true : false;
416 413
417 if (!isSpawnUri) { 414 if (!isSpawnUri) {
418 // Determine the parent Isolate's URL as we will be using the same for c reating 415 // Determine the parent Isolate's URL as we will be using the same for c reating
419 // the isolate being spawned using spawnFunction. 416 // the isolate being spawned using spawnFunction.
420 DartApiScope apiScope; 417 DartApiScope apiScope;
421 Dart_Handle parentIsolateRootLibrary = Dart_RootLibrary(); 418 Dart_Handle parentIsolateRootLibrary = Dart_RootLibrary();
422 if (Dart_IsError(parentIsolateRootLibrary)) { 419 if (Dart_IsError(parentIsolateRootLibrary)) {
(...skipping 21 matching lines...) Expand all
444 // spawnFunction is not allowed from a DOM enabled isolate. 441 // spawnFunction is not allowed from a DOM enabled isolate.
445 // This triggers an exception in the caller. 442 // This triggers an exception in the caller.
446 *errorMsg = strdup("spawnFunction is not supported from a dom-enabled is olate. Please use spawnUri instead."); 443 *errorMsg = strdup("spawnFunction is not supported from a dom-enabled is olate. Please use spawnUri instead.");
447 return 0; 444 return 0;
448 } 445 }
449 446
450 ASSERT(context->isDocument()); 447 ASSERT(context->isDocument());
451 Document* document = static_cast<Document*>(context); 448 Document* document = static_cast<Document*>(context);
452 449
453 Dart_Isolate isolate = createIsolate(scriptURL, entryPoint, document, false, errorMsg); 450 Dart_Isolate isolate = createIsolate(scriptURL, entryPoint, document, false, errorMsg);
454 {
455 Dart_EnterScope();
456 DartService::SendIsolateStartupMessage();
457 Dart_ExitScope();
458 }
459 451
460 if (!isolate) { 452 if (!isolate) {
461 // This triggers an exception in the caller. 453 // This triggers an exception in the caller.
462 *errorMsg = strdup("Isolate spawn failed."); 454 *errorMsg = strdup("Isolate spawn failed.");
463 return 0; 455 return 0;
464 } 456 }
465 457
466 // FIXME: If a spawnFunction, we should not need to request resources again. But, it's not clear 458 // FIXME: If a spawnFunction, we should not need to request resources again. But, it's not clear
467 // we need this callback in the first place for spawnFunction. 459 // we need this callback in the first place for spawnFunction.
468 460
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 587
596 char flagsProp[DartUtilities::PROP_VALUE_MAX_LEN]; 588 char flagsProp[DartUtilities::PROP_VALUE_MAX_LEN];
597 int propLen = DartUtilities::getProp( 589 int propLen = DartUtilities::getProp(
598 "DART_FLAGS", flagsProp, DartUtilities::PROP_VALUE_MAX_LEN); 590 "DART_FLAGS", flagsProp, DartUtilities::PROP_VALUE_MAX_LEN);
599 if (propLen > 0) { 591 if (propLen > 0) {
600 setDartFlags(flagsProp); 592 setDartFlags(flagsProp);
601 } else { 593 } else {
602 setDartFlags(0); 594 setDartFlags(0);
603 } 595 }
604 596
605 // FIXME(antonm): implement proper shutdown callback.
606 // FIXME(antonm): implement proper unhandled exception callback. 597 // FIXME(antonm): implement proper unhandled exception callback.
607 Dart_Initialize(&createPureIsolateCallback, 0, 0, DartService::VmServiceShut downCallback, openFileCallback, readFileCallback, writeFileCallback, closeFileCa llback, generateEntropy); 598 Dart_Initialize(&createPureIsolateCallback, 0, 0, 0, openFileCallback, readF ileCallback, writeFileCallback, closeFileCallback, generateEntropy, createServic eIsolateCallback);
608 hasBeenInitialized = true; 599 hasBeenInitialized = true;
609 } 600 }
610 601
611 static bool checkForExpiration() 602 static bool checkForExpiration()
612 { 603 {
613 const time_t ExpirationTimeSecsSinceEpoch = 604 const time_t ExpirationTimeSecsSinceEpoch =
614 #include "bindings/dart/ExpirationTimeSecsSinceEpoch.time_t" 605 #include "bindings/dart/ExpirationTimeSecsSinceEpoch.time_t"
615 ; 606 ;
616 const char* override = getenv("DARTIUM_EXPIRATION_TIME"); 607 const char* override = getenv("DARTIUM_EXPIRATION_TIME");
617 time_t expiration; 608 time_t expiration;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 Dart_Handle libraryIdHandle = Dart_ListGetAt(libraryIdList, i); 873 Dart_Handle libraryIdHandle = Dart_ListGetAt(libraryIdList, i);
883 Dart_Handle exception = 0; 874 Dart_Handle exception = 0;
884 intptr_t libraryId = DartUtilities::toInteger(libraryIdHandle, exception ); 875 intptr_t libraryId = DartUtilities::toInteger(libraryIdHandle, exception );
885 ASSERT(!exception); 876 ASSERT(!exception);
886 DartScriptState* scriptState = lookupScriptStateFromLibraryIdMap(isolate , v8Context, libraryIdMap, libraryId); 877 DartScriptState* scriptState = lookupScriptStateFromLibraryIdMap(isolate , v8Context, libraryIdMap, libraryId);
887 result.append(scriptState); 878 result.append(scriptState);
888 } 879 }
889 } 880 }
890 881
891 } 882 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698