2
|
1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
2 |
// Use of this source code is governed by a BSD-style license that can be
|
|
3 |
// found in the LICENSE file.
|
|
4 |
|
|
5 |
package org.chromium.sdk.internal.tools.v8;
|
|
6 |
|
|
7 |
import org.chromium.sdk.Breakpoint;
|
|
8 |
import org.chromium.sdk.BrowserTab;
|
|
9 |
|
|
10 |
/**
|
|
11 |
* A generic implementation of the Breakpoint interface.
|
|
12 |
*/
|
|
13 |
public class BreakpointImpl implements Breakpoint {
|
|
14 |
|
|
15 |
/**
|
|
16 |
* The breakpoint type.
|
|
17 |
*/
|
|
18 |
private final Type type;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* The breakpoint id as reported by the JavaScript VM.
|
|
22 |
*/
|
|
23 |
private long id;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Whether the breakpoint is enabled.
|
|
27 |
*/
|
|
28 |
private boolean isEnabled;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* The number of times the breakpoint should be ignored
|
|
32 |
* by the JavaScript VM until it fires.
|
|
33 |
*/
|
|
34 |
private int ignoreCount;
|
|
35 |
|
|
36 |
/**
|
|
37 |
* The breakpoint condition (plain JavaScript) that should be {@code true}
|
|
38 |
* for the breakpoint to fire.
|
|
39 |
*/
|
|
40 |
private String condition;
|
|
41 |
|
|
42 |
/**
|
|
43 |
* The breakpoint manager that manages this breakpoint.
|
|
44 |
*/
|
|
45 |
private final BreakpointManager breakpointManager;
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Whether the breakpoint data have changed with respect
|
|
49 |
* to the JavaScript VM data.
|
|
50 |
*/
|
|
51 |
private volatile boolean isDirty = false;
|
|
52 |
|
|
53 |
public BreakpointImpl(Type type, long id, boolean enabled, int ignoreCount, String condition,
|
|
54 |
BreakpointManager breakpointManager) {
|
|
55 |
this.type = type;
|
|
56 |
this.id = id;
|
|
57 |
this.isEnabled = enabled;
|
|
58 |
this.ignoreCount = ignoreCount;
|
|
59 |
this.condition = condition;
|
|
60 |
this.breakpointManager = breakpointManager;
|
|
61 |
}
|
|
62 |
|
|
63 |
public boolean isEnabled() {
|
|
64 |
return isEnabled;
|
|
65 |
}
|
|
66 |
|
|
67 |
public Type getType() {
|
|
68 |
return type;
|
|
69 |
}
|
|
70 |
|
|
71 |
public long getId() {
|
|
72 |
return id;
|
|
73 |
}
|
|
74 |
|
|
75 |
public int getIgnoreCount() {
|
|
76 |
return ignoreCount;
|
|
77 |
}
|
|
78 |
|
|
79 |
public String getCondition() {
|
|
80 |
return condition;
|
|
81 |
}
|
|
82 |
|
|
83 |
public void setEnabled(boolean enabled) {
|
|
84 |
if (this.isEnabled != enabled) {
|
|
85 |
setDirty(true);
|
|
86 |
}
|
|
87 |
this.isEnabled = enabled;
|
|
88 |
}
|
|
89 |
|
|
90 |
public void setIgnoreCount(int ignoreCount) {
|
|
91 |
if (this.ignoreCount != ignoreCount) {
|
|
92 |
setDirty(true);
|
|
93 |
}
|
|
94 |
this.ignoreCount = ignoreCount;
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
public void setCondition(String condition) {
|
|
99 |
if (!eq(this.condition, condition)) {
|
|
100 |
setDirty(true);
|
|
101 |
}
|
|
102 |
this.condition = condition;
|
|
103 |
}
|
|
104 |
|
|
105 |
private boolean eq(Object left, Object right) {
|
|
106 |
return left == right || (left != null && left.equals(right));
|
|
107 |
}
|
|
108 |
|
|
109 |
public void clear(final BrowserTab.BreakpointCallback callback) {
|
|
110 |
breakpointManager.clearBreakpoint(this, callback);
|
|
111 |
// The order must be preserved, otherwise the breakpointProcessor will not be able
|
|
112 |
// to identify the original breakpoint ID.
|
|
113 |
this.id = INVALID_ID;
|
|
114 |
}
|
|
115 |
|
|
116 |
public void flush(final BrowserTab.BreakpointCallback callback) {
|
|
117 |
if (!isDirty()) {
|
|
118 |
if (callback != null) {
|
|
119 |
callback.success(this);
|
|
120 |
}
|
|
121 |
return;
|
|
122 |
}
|
|
123 |
breakpointManager.changeBreakpoint(this, callback);
|
|
124 |
setDirty(false);
|
|
125 |
}
|
|
126 |
|
|
127 |
private void setDirty(boolean isDirty) {
|
|
128 |
this.isDirty = isDirty;
|
|
129 |
}
|
|
130 |
|
|
131 |
private boolean isDirty() {
|
|
132 |
return isDirty;
|
|
133 |
}
|
|
134 |
|
|
135 |
} |