Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / shell / renderer / leak_detector.cc
blob0ad4e2245266ba36674eb5b98c874e75b8b4f57f
1 // Copyright 2014 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.
5 #include "content/shell/renderer/leak_detector.h"
7 #include "base/json/json_writer.h"
8 #include "base/logging.h"
9 #include "base/values.h"
10 #include "third_party/WebKit/public/web/WebLeakDetector.h"
12 using blink::WebLeakDetector;
14 namespace content {
16 // The initial states of the DOM objects at about:blank. The four nodes are a
17 // Document, a HTML, a HEAD and a BODY.
19 // TODO(hajimehoshi): Now these are hard-corded. If we add target to count like
20 // RefCoutned objects whose initial state is diffcult to estimate, we stop using
21 // hard-coded values. Instead, we need to load about:blank ahead of the layout
22 // tests actually and initialize LeakDetector by the got values.
23 const int kInitialNumberOfLiveDocuments = 1;
24 const int kInitialNumberOfLiveNodes = 4;
26 LeakDetector::LeakDetector()
27 : previous_number_of_live_documents_(kInitialNumberOfLiveDocuments),
28 previous_number_of_live_nodes_(kInitialNumberOfLiveNodes) {
31 LeakDetectionResult LeakDetector::TryLeakDetection(blink::WebFrame* frame) {
32 LeakDetectionResult result;
33 unsigned number_of_live_documents = 0;
34 unsigned number_of_live_nodes = 0;
36 WebLeakDetector::collectGarbargeAndGetDOMCounts(
37 frame, &number_of_live_documents, &number_of_live_nodes);
39 result.leaked =
40 (previous_number_of_live_documents_ < number_of_live_documents ||
41 previous_number_of_live_nodes_ < number_of_live_nodes);
43 if (result.leaked) {
44 base::DictionaryValue detail;
45 base::ListValue* list = new base::ListValue();
46 list->AppendInteger(previous_number_of_live_documents_);
47 list->AppendInteger(number_of_live_documents);
48 detail.Set("numberOfLiveDocuments", list);
50 list = new base::ListValue();
51 list->AppendInteger(previous_number_of_live_nodes_);
52 list->AppendInteger(number_of_live_nodes);
53 detail.Set("numberOfLiveNodes", list);
55 std::string detail_str;
56 base::JSONWriter::Write(&detail, &detail_str);
57 result.detail = detail_str;
60 previous_number_of_live_documents_ = number_of_live_documents;
61 previous_number_of_live_nodes_ = number_of_live_nodes;
63 return result;
66 } // namespace content