org.chromium.sdk/src/org/chromium/sdk/internal/JavascriptVmImpl.java
changeset 2 e4420d2515f1
child 276 f2f4a1259de8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.chromium.sdk/src/org/chromium/sdk/internal/JavascriptVmImpl.java	Wed Dec 23 17:13:18 2009 -0800
@@ -0,0 +1,42 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.sdk.internal;
+
+import org.chromium.sdk.Breakpoint;
+import org.chromium.sdk.CallbackSemaphore;
+import org.chromium.sdk.JavascriptVm;
+import org.chromium.sdk.internal.tools.v8.MethodIsBlockingException;
+
+/**
+ * Base implementation of JavascriptVm.
+ */
+public abstract class JavascriptVmImpl implements JavascriptVm {
+
+  protected JavascriptVmImpl() {
+  }
+
+  public void suspend(SuspendCallback callback) {
+    getDebugSession().suspend(callback);
+  }
+
+  public void getScripts(ScriptsCallback callback) throws MethodIsBlockingException {
+    CallbackSemaphore callbackSemaphore = new CallbackSemaphore();
+    getDebugSession().getScriptLoader().loadAllScripts(callback, callbackSemaphore);
+
+    boolean res = callbackSemaphore.tryAcquireDefault();
+    if (!res) {
+      callback.failure("Timeout");
+    }
+  }
+
+  public void setBreakpoint(Breakpoint.Type type, String target, int line,
+      int position, boolean enabled, String condition, int ignoreCount,
+      BreakpointCallback callback) {
+    getDebugSession().getBreakpointManager()
+        .setBreakpoint(type, target, line, position, enabled, condition, ignoreCount, callback);
+  }
+
+  protected abstract DebugSession getDebugSession();
+}