From 61e775c0554b4289d7a6529ab17737076354e813 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 12 May 2016 13:48:01 -0700 Subject: [PATCH 01/12] Write native_mate converters for WebCache::ResourceTypeStat and friends --- .../native_mate_converters/blink_converter.cc | 30 +++++++++++++++++++ .../native_mate_converters/blink_converter.h | 13 ++++++++ 2 files changed, 43 insertions(+) diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 0ae73e9825c8..915e766ea7ee 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -12,6 +12,7 @@ #include "base/strings/utf_string_conversions.h" #include "content/public/browser/native_web_keyboard_event.h" #include "native_mate/dictionary.h" +#include "third_party/WebKit/public/web/WebCache.h" #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" #include "third_party/WebKit/public/web/WebFindOptions.h" #include "third_party/WebKit/public/web/WebInputEvent.h" @@ -384,4 +385,33 @@ v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) { return mate::ConvertToV8(isolate, dict); } +v8::Local Converter::ToV8( + v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStat& stat) { + mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + + dict.Set("count", (uint32_t)stat.count); + dict.Set("size", (uint32_t)(stat.size >> 10)); + dict.Set("liveSize", (uint32_t)(stat.liveSize >> 10)); + dict.Set("decodedSize", (uint32_t)(stat.decodedSize >> 10)); + dict.Set("purgedSize", (uint32_t)(stat.purgedSize >> 10)); + dict.Set("purgeableSize", (uint32_t)(stat.purgeableSize >> 10)); + + return dict.GetHandle(); +} + +v8::Local Converter::ToV8( + v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStats& stats) { + mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + + dict.Set("images", mate::ConvertToV8(isolate, stats.images)); + dict.Set("cssStyleSheets", mate::ConvertToV8(isolate, stats.cssStyleSheets)); + dict.Set("xslStyleSheets", mate::ConvertToV8(isolate, stats.xslStyleSheets)); + dict.Set("fonts", mate::ConvertToV8(isolate, stats.fonts)); + dict.Set("other", mate::ConvertToV8(isolate, stats.other)); + + return dict.GetHandle(); +} + } // namespace mate diff --git a/atom/common/native_mate_converters/blink_converter.h b/atom/common/native_mate_converters/blink_converter.h index 514c6ab680c7..a48547e612bd 100644 --- a/atom/common/native_mate_converters/blink_converter.h +++ b/atom/common/native_mate_converters/blink_converter.h @@ -6,6 +6,7 @@ #define ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ #include "native_mate/converter.h" +#include "third_party/WebKit/public/web/WebCache.h" #include "third_party/WebKit/public/web/WebContextMenuData.h" namespace blink { @@ -104,6 +105,18 @@ v8::Local EditFlagsToV8(v8::Isolate* isolate, int editFlags); v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags); +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStat& stat); +}; + +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStats& stats); +}; + } // namespace mate #endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ From 22a37653943754e1c8bac3807f7a6f704bf17cfc Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 12 May 2016 13:56:46 -0700 Subject: [PATCH 02/12] Wire up a new method in web frame --- atom/renderer/api/atom_api_web_frame.cc | 12 +++++++++++- atom/renderer/api/atom_api_web_frame.h | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 0eebc94fc141..173236f59e53 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -5,6 +5,7 @@ #include "atom/renderer/api/atom_api_web_frame.h" #include "atom/common/api/event_emitter_caller.h" +#include "atom/common/native_mate_converters/blink_converter.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" @@ -13,6 +14,7 @@ #include "content/public/renderer/render_view.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" +#include "third_party/WebKit/public/web/WebCache.h" #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebScriptExecutionCallback.h" @@ -168,6 +170,13 @@ mate::Handle WebFrame::Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new WebFrame(isolate)); } +v8::Local WebFrame::GetResourceUsage(v8::Isolate* isolate) { + blink::WebCache::ResourceTypeStats stats; + + blink::WebCache::getResourceTypeStats(&stats); + return mate::Converter::ToV8(isolate, stats); +} + // static void WebFrame::BuildPrototype( v8::Isolate* isolate, v8::Local prototype) { @@ -191,7 +200,8 @@ void WebFrame::BuildPrototype( .SetMethod("registerURLSchemeAsPrivileged", &WebFrame::RegisterURLSchemeAsPrivileged) .SetMethod("insertText", &WebFrame::InsertText) - .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript); + .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript) + .SetMethod("getResourceUsage", &WebFrame::GetResourceUsage); } } // namespace api diff --git a/atom/renderer/api/atom_api_web_frame.h b/atom/renderer/api/atom_api_web_frame.h index e1eeb224930b..60c6159bf124 100644 --- a/atom/renderer/api/atom_api_web_frame.h +++ b/atom/renderer/api/atom_api_web_frame.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "native_mate/handle.h" #include "native_mate/wrappable.h" +#include "third_party/WebKit/public/web/WebCache.h" namespace blink { class WebLocalFrame; @@ -69,6 +70,9 @@ class WebFrame : public mate::Wrappable { // Excecuting scripts. void ExecuteJavaScript(const base::string16& code, mate::Arguments* args); + // Resource related methods + v8::Local GetResourceUsage(v8::Isolate* isolate); + scoped_ptr spell_check_client_; blink::WebLocalFrame* web_frame_; From d83c36e0fda799aded4506bde34e6772f08fe02b Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 12 May 2016 14:36:49 -0700 Subject: [PATCH 03/12] Add a way to drop all cached memory --- atom/renderer/api/atom_api_web_frame.cc | 12 +++++++++++- atom/renderer/api/atom_api_web_frame.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 173236f59e53..873f49d62838 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -10,6 +10,7 @@ #include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/renderer/api/atom_api_spell_check_client.h" +#include "base/memory/memory_pressure_listener.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_view.h" #include "native_mate/dictionary.h" @@ -177,6 +178,14 @@ v8::Local WebFrame::GetResourceUsage(v8::Isolate* isolate) { return mate::Converter::ToV8(isolate, stats); } +void WebFrame::PurgeCaches(v8::Isolate* isolate) { + isolate->IdleNotificationDeadline(0.5); + blink::WebCache::clear(); + + base::MemoryPressureListener::NotifyMemoryPressure( + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); +} + // static void WebFrame::BuildPrototype( v8::Isolate* isolate, v8::Local prototype) { @@ -201,7 +210,8 @@ void WebFrame::BuildPrototype( &WebFrame::RegisterURLSchemeAsPrivileged) .SetMethod("insertText", &WebFrame::InsertText) .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript) - .SetMethod("getResourceUsage", &WebFrame::GetResourceUsage); + .SetMethod("getResourceUsage", &WebFrame::GetResourceUsage) + .SetMethod("purgeCaches", &WebFrame::PurgeCaches); } } // namespace api diff --git a/atom/renderer/api/atom_api_web_frame.h b/atom/renderer/api/atom_api_web_frame.h index 60c6159bf124..fa45c5a6c56b 100644 --- a/atom/renderer/api/atom_api_web_frame.h +++ b/atom/renderer/api/atom_api_web_frame.h @@ -72,6 +72,7 @@ class WebFrame : public mate::Wrappable { // Resource related methods v8::Local GetResourceUsage(v8::Isolate* isolate); + void PurgeCaches(v8::Isolate* isolate); scoped_ptr spell_check_client_; From 908084c0fd00fd41a2fc3a81aae3ff5204cc0c74 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 12 May 2016 15:03:47 -0700 Subject: [PATCH 04/12] Document resource methods --- docs/api/web-frame.md | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index de5a21db3db9..f9da778d9578 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -106,4 +106,50 @@ In the browser window some HTML APIs like `requestFullScreen` can only be invoked by a gesture from the user. Setting `userGesture` to `true` will remove this limitation. + +### `webFrame.getResourceUsage()` + +Returns more detailed memory usage information in kilobytes of Blink's internal +memory caches. Returns an Object of the following shape: + +```js +{ + "images": { + "count": 22, + "size": 2549, // 2549kb + "liveSize": 2542, // 2542kb, etc... + "decodedSize": 478, + "purgedSize": 0, + "purgeableSize": 0 + }, + "cssStyleSheets": { + "count": 7, + /* ... */ + }, + "xslStyleSheets": { + "count": 0, + /* ... */ + }, + "fonts": { + "count": 18, + /* ... */ + }, + "other": { + "count": 0, + /* ... */ + } +} +``` + +### `webFrame.purgeCaches()` + +Attempts to free memory that is no longer being used (i.e. images from a +previous navigation, etc etc). + +Note that blindly calling this method probably makes Electron slower since it +will have to refill these emptied caches, you should only call it if an event +in your app has occured that makes you think your page is actually using less +memory (i.e. you have navigated from a super heavy page to a mostly empty one, +and intend to stay there) + [spellchecker]: https://github.com/atom/node-spellchecker From 6f0057532aa9846c29650d666a7043e77dd92184 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 12 May 2016 15:58:19 -0700 Subject: [PATCH 05/12] Forgot scripts --- atom/common/native_mate_converters/blink_converter.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 915e766ea7ee..4571298fbcb1 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -406,6 +406,7 @@ v8::Local Converter::ToV8( mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); dict.Set("images", mate::ConvertToV8(isolate, stats.images)); + dict.Set("scripts", mate::ConvertToV8(isolate, stats.scripts)); dict.Set("cssStyleSheets", mate::ConvertToV8(isolate, stats.cssStyleSheets)); dict.Set("xslStyleSheets", mate::ConvertToV8(isolate, stats.xslStyleSheets)); dict.Set("fonts", mate::ConvertToV8(isolate, stats.fonts)); From 19cba3ff859e59260d87c8f83c0725bfd1bb03a0 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 13 May 2016 10:33:56 -0700 Subject: [PATCH 06/12] Use doubles to represent memory size in bytes --- atom/common/native_mate_converters/blink_converter.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 4571298fbcb1..ddee3a1351bf 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -391,11 +391,11 @@ v8::Local Converter::ToV8( mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); dict.Set("count", (uint32_t)stat.count); - dict.Set("size", (uint32_t)(stat.size >> 10)); - dict.Set("liveSize", (uint32_t)(stat.liveSize >> 10)); - dict.Set("decodedSize", (uint32_t)(stat.decodedSize >> 10)); - dict.Set("purgedSize", (uint32_t)(stat.purgedSize >> 10)); - dict.Set("purgeableSize", (uint32_t)(stat.purgeableSize >> 10)); + dict.Set("size", (double)stat.size); + dict.Set("liveSize", (double)stat.liveSize); + dict.Set("decodedSize", (double)stat.decodedSize); + dict.Set("purgedSize", (double)stat.purgedSize); + dict.Set("purgeableSize", (double)stat.purgeableSize); return dict.GetHandle(); } From 652913f8d62e807ab5da8feb23645027098c6702 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 13 May 2016 10:43:08 -0700 Subject: [PATCH 07/12] Just return the type directly --- atom/renderer/api/atom_api_web_frame.cc | 4 ++-- atom/renderer/api/atom_api_web_frame.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 873f49d62838..e2fff3ca6b12 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -171,11 +171,11 @@ mate::Handle WebFrame::Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new WebFrame(isolate)); } -v8::Local WebFrame::GetResourceUsage(v8::Isolate* isolate) { +blink::WebCache::ResourceTypeStats WebFrame::GetResourceUsage(v8::Isolate* isolate) { blink::WebCache::ResourceTypeStats stats; blink::WebCache::getResourceTypeStats(&stats); - return mate::Converter::ToV8(isolate, stats); + return stats; } void WebFrame::PurgeCaches(v8::Isolate* isolate) { diff --git a/atom/renderer/api/atom_api_web_frame.h b/atom/renderer/api/atom_api_web_frame.h index fa45c5a6c56b..4543c99e13ff 100644 --- a/atom/renderer/api/atom_api_web_frame.h +++ b/atom/renderer/api/atom_api_web_frame.h @@ -71,7 +71,7 @@ class WebFrame : public mate::Wrappable { void ExecuteJavaScript(const base::string16& code, mate::Arguments* args); // Resource related methods - v8::Local GetResourceUsage(v8::Isolate* isolate); + blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate); void PurgeCaches(v8::Isolate* isolate); scoped_ptr spell_check_client_; From 2234307d413b06ba5c85bc5bed6ca78818bec7d6 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 13 May 2016 10:45:23 -0700 Subject: [PATCH 08/12] Whitespace issues From 7459581d1357514ad9d91518bc3517ba4105edbb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 14 May 2016 22:40:18 +0900 Subject: [PATCH 09/12] Fix cpplint warnings --- .../native_mate_converters/blink_converter.cc | 16 ++++++---------- .../native_mate_converters/blink_converter.h | 17 +++++++++-------- atom/renderer/api/atom_api_web_frame.cc | 4 ++-- docs/api/web-frame.md | 1 - 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index ddee3a1351bf..7e0d180f9603 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -389,14 +389,12 @@ v8::Local Converter::ToV8( v8::Isolate* isolate, const blink::WebCache::ResourceTypeStat& stat) { mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); - - dict.Set("count", (uint32_t)stat.count); - dict.Set("size", (double)stat.size); - dict.Set("liveSize", (double)stat.liveSize); - dict.Set("decodedSize", (double)stat.decodedSize); - dict.Set("purgedSize", (double)stat.purgedSize); - dict.Set("purgeableSize", (double)stat.purgeableSize); - + dict.Set("count", static_cast(stat.count)); + dict.Set("size", static_cast(stat.size)); + dict.Set("liveSize", static_cast(stat.liveSize)); + dict.Set("decodedSize", static_cast(stat.decodedSize)); + dict.Set("purgedSize", static_cast(stat.purgedSize)); + dict.Set("purgeableSize", static_cast(stat.purgeableSize)); return dict.GetHandle(); } @@ -404,14 +402,12 @@ v8::Local Converter::ToV8( v8::Isolate* isolate, const blink::WebCache::ResourceTypeStats& stats) { mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); - dict.Set("images", mate::ConvertToV8(isolate, stats.images)); dict.Set("scripts", mate::ConvertToV8(isolate, stats.scripts)); dict.Set("cssStyleSheets", mate::ConvertToV8(isolate, stats.cssStyleSheets)); dict.Set("xslStyleSheets", mate::ConvertToV8(isolate, stats.xslStyleSheets)); dict.Set("fonts", mate::ConvertToV8(isolate, stats.fonts)); dict.Set("other", mate::ConvertToV8(isolate, stats.other)); - return dict.GetHandle(); } diff --git a/atom/common/native_mate_converters/blink_converter.h b/atom/common/native_mate_converters/blink_converter.h index a48547e612bd..78275ab62ec9 100644 --- a/atom/common/native_mate_converters/blink_converter.h +++ b/atom/common/native_mate_converters/blink_converter.h @@ -101,22 +101,23 @@ struct Converter { const blink::WebContextMenuData::InputFieldType& in); }; -v8::Local EditFlagsToV8(v8::Isolate* isolate, int editFlags); - -v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags); - template<> struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const blink::WebCache::ResourceTypeStat& stat); + static v8::Local ToV8( + v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStat& stat); }; template<> struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const blink::WebCache::ResourceTypeStats& stats); + static v8::Local ToV8( + v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStats& stats); }; +v8::Local EditFlagsToV8(v8::Isolate* isolate, int editFlags); +v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags); + } // namespace mate #endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index e2fff3ca6b12..46e00ba3978c 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -171,9 +171,9 @@ mate::Handle WebFrame::Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new WebFrame(isolate)); } -blink::WebCache::ResourceTypeStats WebFrame::GetResourceUsage(v8::Isolate* isolate) { +blink::WebCache::ResourceTypeStats WebFrame::GetResourceUsage( + v8::Isolate* isolate) { blink::WebCache::ResourceTypeStats stats; - blink::WebCache::getResourceTypeStats(&stats); return stats; } diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index f9da778d9578..de28afe05789 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -106,7 +106,6 @@ In the browser window some HTML APIs like `requestFullScreen` can only be invoked by a gesture from the user. Setting `userGesture` to `true` will remove this limitation. - ### `webFrame.getResourceUsage()` Returns more detailed memory usage information in kilobytes of Blink's internal From c74043803245908fd0dd6b49d1bb1d0b433185f8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 14 May 2016 22:48:25 +0900 Subject: [PATCH 10/12] Rename webFrame.purgeCaches to webFrame.clearCache This matches the name of session.clearCache. --- atom/renderer/api/atom_api_web_frame.cc | 5 +-- atom/renderer/api/atom_api_web_frame.h | 2 +- docs/api/web-frame.md | 54 +++++++++++-------------- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 46e00ba3978c..d32b5f1c8c46 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -178,10 +178,9 @@ blink::WebCache::ResourceTypeStats WebFrame::GetResourceUsage( return stats; } -void WebFrame::PurgeCaches(v8::Isolate* isolate) { +void WebFrame::ClearCache(v8::Isolate* isolate) { isolate->IdleNotificationDeadline(0.5); blink::WebCache::clear(); - base::MemoryPressureListener::NotifyMemoryPressure( base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); } @@ -211,7 +210,7 @@ void WebFrame::BuildPrototype( .SetMethod("insertText", &WebFrame::InsertText) .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript) .SetMethod("getResourceUsage", &WebFrame::GetResourceUsage) - .SetMethod("purgeCaches", &WebFrame::PurgeCaches); + .SetMethod("clearCache", &WebFrame::ClearCache); } } // namespace api diff --git a/atom/renderer/api/atom_api_web_frame.h b/atom/renderer/api/atom_api_web_frame.h index 4543c99e13ff..2e120ecb6ae3 100644 --- a/atom/renderer/api/atom_api_web_frame.h +++ b/atom/renderer/api/atom_api_web_frame.h @@ -72,7 +72,7 @@ class WebFrame : public mate::Wrappable { // Resource related methods blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate); - void PurgeCaches(v8::Isolate* isolate); + void ClearCache(v8::Isolate* isolate); scoped_ptr spell_check_client_; diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index de28afe05789..a933b8b48138 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -108,47 +108,41 @@ this limitation. ### `webFrame.getResourceUsage()` -Returns more detailed memory usage information in kilobytes of Blink's internal -memory caches. Returns an Object of the following shape: +Returns an object describing usage information of Blink's internal memory +caches. -```js +```javascript +console.log(webFrame.getResourceUsage()) +``` + +This will generate: + +```javascript { - "images": { - "count": 22, - "size": 2549, // 2549kb - "liveSize": 2542, // 2542kb, etc... - "decodedSize": 478, - "purgedSize": 0, - "purgeableSize": 0 + images: { + count: 22, + size: 2549, + liveSize: 2542, + decodedSize: 478, + purgedSize: 0, + purgeableSize: 0 }, - "cssStyleSheets": { - "count": 7, - /* ... */ - }, - "xslStyleSheets": { - "count": 0, - /* ... */ - }, - "fonts": { - "count": 18, - /* ... */ - }, - "other": { - "count": 0, - /* ... */ - } + cssStyleSheets: { /* same with "images" */ }, + xslStyleSheets: { /* same with "images" */ }, + fonts: { /* same with "images" */ }, + other: { /* same with "images" */ }, } ``` -### `webFrame.purgeCaches()` +### `webFrame.clearCache()` -Attempts to free memory that is no longer being used (i.e. images from a -previous navigation, etc etc). +Attempts to free memory that is no longer being used (like images from a +previous navigation). Note that blindly calling this method probably makes Electron slower since it will have to refill these emptied caches, you should only call it if an event in your app has occured that makes you think your page is actually using less memory (i.e. you have navigated from a super heavy page to a mostly empty one, -and intend to stay there) +and intend to stay there). [spellchecker]: https://github.com/atom/node-spellchecker From d3e359ab2d0b4c439a8b6a378766dc41244926d6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 14 May 2016 22:50:05 +0900 Subject: [PATCH 11/12] No need for explicit type conversion --- .../common/native_mate_converters/blink_converter.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 7e0d180f9603..684b06a36329 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -402,12 +402,12 @@ v8::Local Converter::ToV8( v8::Isolate* isolate, const blink::WebCache::ResourceTypeStats& stats) { mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); - dict.Set("images", mate::ConvertToV8(isolate, stats.images)); - dict.Set("scripts", mate::ConvertToV8(isolate, stats.scripts)); - dict.Set("cssStyleSheets", mate::ConvertToV8(isolate, stats.cssStyleSheets)); - dict.Set("xslStyleSheets", mate::ConvertToV8(isolate, stats.xslStyleSheets)); - dict.Set("fonts", mate::ConvertToV8(isolate, stats.fonts)); - dict.Set("other", mate::ConvertToV8(isolate, stats.other)); + dict.Set("images", stats.images); + dict.Set("scripts", stats.scripts); + dict.Set("cssStyleSheets", stats.cssStyleSheets); + dict.Set("xslStyleSheets", stats.xslStyleSheets); + dict.Set("fonts", stats.fonts); + dict.Set("other", stats.other); return dict.GetHandle(); } From 3214fdd73f8dbc65e4d98be72bcbad91860bea3a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 14 May 2016 23:11:13 +0900 Subject: [PATCH 12/12] Fix failing CI on OS X --- script/bootstrap.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/script/bootstrap.py b/script/bootstrap.py index 816a6182b201..df1a5792070b 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -52,9 +52,6 @@ def main(): if PLATFORM != 'win32': # Download prebuilt clang binaries. update_clang() - if not args.disable_clang and args.clang_dir == '': - # Build with prebuilt clang. - set_clang_env(os.environ) setup_python_libs() update_node_modules('.') @@ -67,7 +64,7 @@ def main(): create_chrome_version_h() touch_config_gypi() - run_update(defines) + run_update(defines, args.disable_clang, args.clang_dir) update_electron_modules('spec', args.target_arch) @@ -250,9 +247,14 @@ def touch_config_gypi(): f.write(content) -def run_update(defines): +def run_update(defines, disable_clang, clang_dir): + env = os.environ.copy() + if not disable_clang and clang_dir == '': + # Build with prebuilt clang. + set_clang_env(env) + update = os.path.join(SOURCE_ROOT, 'script', 'update.py') - execute_stdout([sys.executable, update, '--defines', defines]) + execute_stdout([sys.executable, update, '--defines', defines], env) if __name__ == '__main__':