org.chromium.sdk/src/org/chromium/sdk/internal/JavascriptVmImpl.java
author Eugene Ostroukhov <eostroukhov@gmail.com>
Thu, 28 Jan 2010 11:27:14 -0800
changeset 56 22f918ed49f7
parent 2 e4420d2515f1
child 276 f2f4a1259de8
permissions -rw-r--r--
Java5 is now supported

// 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();
}