1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_WEBUI_MEMORY_INTERNALS_MEMORY_INTERNALS_PROXY_H_
6 #define CHROME_BROWSER_UI_WEBUI_MEMORY_INTERNALS_MEMORY_INTERNALS_PROXY_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "base/values.h"
15 #include "chrome/browser/memory_details.h"
16 #include "content/public/browser/browser_thread.h"
18 class MemoryInternalsHandler
;
19 class RendererDetails
;
22 class DictionaryValue
;
31 class MemoryInternalsProxy
32 : public base::RefCountedThreadSafe
<
33 MemoryInternalsProxy
, content::BrowserThread::DeleteOnUIThread
> {
35 MemoryInternalsProxy();
37 // Registers a handler.
38 void Attach(MemoryInternalsHandler
* handler
);
40 // Unregisters a handler.
43 // Starts fetching memory usages of all processes.
44 void StartFetch(const base::ListValue
* list
);
48 content::BrowserThread::DeleteOnThread
<content::BrowserThread::UI
>;
49 friend class base::DeleteHelper
<MemoryInternalsProxy
>;
51 typedef ProcessMemoryInformationList::const_iterator PMIIterator
;
53 virtual ~MemoryInternalsProxy();
55 // Enumerates all processes information.
56 void OnProcessAvailable(const ProcessData
& browser
);
58 // Measures memory usage of V8.
59 void OnRendererAvailable(const base::ProcessId pid
,
60 const size_t v8_allocated
,
61 const size_t v8_used
);
63 // Converts information related to each WebContents, which represents contents
64 // in a tab, into Value format and appends it to information of the process
65 // which each tab belongs to.
66 void ConvertTabsInformation(
67 const std::set
<content::WebContents
*>& web_contents
,
68 base::ListValue
* processes
);
70 // Requests all renderer processes to get detailed memory information.
71 void RequestRendererDetails();
73 // Be called on finish of collection.
74 void FinishCollection();
76 // Calls a JavaScript function on a UI page.
77 void CallJavaScriptFunctionOnUIThread(const std::string
& function
,
78 const base::Value
& args
);
80 MemoryInternalsHandler
* handler_
;
81 base::DictionaryValue
* information_
;
82 scoped_ptr
<RendererDetails
> renderer_details_
;
84 DISALLOW_COPY_AND_ASSIGN(MemoryInternalsProxy
);
87 #endif // CHROME_BROWSER_UI_WEBUI_MEMORY_INTERNALS_MEMORY_INTERNALS_PROXY_H_