Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: content/child/blink_platform_impl.cc

Issue 1671383003: [Onion Soup] Remove dead memory usage code in BlinkPlatformImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/child/blink_platform_impl.h ('k') | third_party/WebKit/public/platform/Platform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/blink_platform_impl.h" 5 #include "content/child/blink_platform_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 base::WaitableEvent* impl() { 103 base::WaitableEvent* impl() {
104 return impl_.get(); 104 return impl_.get();
105 } 105 }
106 106
107 private: 107 private:
108 scoped_ptr<base::WaitableEvent> impl_; 108 scoped_ptr<base::WaitableEvent> impl_;
109 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); 109 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl);
110 }; 110 };
111 111
112 // A simple class to cache the memory usage for a given amount of time.
113 class MemoryUsageCache {
114 public:
115 // Retrieves the Singleton.
116 static MemoryUsageCache* GetInstance() {
117 return base::Singleton<MemoryUsageCache>::get();
118 }
119
120 MemoryUsageCache() : memory_value_(0) { Init(); }
121 ~MemoryUsageCache() {}
122
123 void Init() {
124 const unsigned int kCacheSeconds = 1;
125 cache_valid_time_ = base::TimeDelta::FromSeconds(kCacheSeconds);
126 }
127
128 // Returns true if the cached value is fresh.
129 // Returns false if the cached value is stale, or if |cached_value| is NULL.
130 bool IsCachedValueValid(size_t* cached_value) {
131 base::AutoLock scoped_lock(lock_);
132 if (!cached_value)
133 return false;
134 if (base::Time::Now() - last_updated_time_ > cache_valid_time_)
135 return false;
136 *cached_value = memory_value_;
137 return true;
138 };
139
140 // Setter for |memory_value_|, refreshes |last_updated_time_|.
141 void SetMemoryValue(const size_t value) {
142 base::AutoLock scoped_lock(lock_);
143 memory_value_ = value;
144 last_updated_time_ = base::Time::Now();
145 }
146
147 private:
148 // The cached memory value.
149 size_t memory_value_;
150
151 // How long the cached value should remain valid.
152 base::TimeDelta cache_valid_time_;
153
154 // The last time the cached value was updated.
155 base::Time last_updated_time_;
156
157 base::Lock lock_;
158 };
159
160 } // namespace 112 } // namespace
161 113
162 static int ToMessageID(WebLocalizedString::Name name) { 114 static int ToMessageID(WebLocalizedString::Name name) {
163 switch (name) { 115 switch (name) {
164 case WebLocalizedString::AXAMPMFieldText: 116 case WebLocalizedString::AXAMPMFieldText:
165 return IDS_AX_AM_PM_FIELD_TEXT; 117 return IDS_AX_AM_PM_FIELD_TEXT;
166 case WebLocalizedString::AXButtonActionVerb: 118 case WebLocalizedString::AXButtonActionVerb:
167 return IDS_AX_BUTTON_ACTION_VERB; 119 return IDS_AX_BUTTON_ACTION_VERB;
168 case WebLocalizedString::AXCalendarShowMonthSelector: 120 case WebLocalizedString::AXCalendarShowMonthSelector:
169 return IDS_AX_CALENDAR_SHOW_MONTH_SELECTOR; 121 return IDS_AX_CALENDAR_SHOW_MONTH_SELECTOR;
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 } 1050 }
1099 1051
1100 blink::WebString BlinkPlatformImpl::signedPublicKeyAndChallengeString( 1052 blink::WebString BlinkPlatformImpl::signedPublicKeyAndChallengeString(
1101 unsigned key_size_index, 1053 unsigned key_size_index,
1102 const blink::WebString& challenge, 1054 const blink::WebString& challenge,
1103 const blink::WebURL& url, 1055 const blink::WebURL& url,
1104 const blink::WebURL& top_origin) { 1056 const blink::WebURL& top_origin) {
1105 return blink::WebString(""); 1057 return blink::WebString("");
1106 } 1058 }
1107 1059
1108 static size_t getMemoryUsageMB(bool bypass_cache) {
1109 size_t current_mem_usage = 0;
1110 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance();
1111 if (!bypass_cache &&
1112 mem_usage_cache_singleton->IsCachedValueValid(&current_mem_usage))
1113 return current_mem_usage;
1114
1115 current_mem_usage = GetMemoryUsageKB() >> 10;
1116 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage);
1117 return current_mem_usage;
1118 }
1119
1120 size_t BlinkPlatformImpl::memoryUsageMB() {
1121 return getMemoryUsageMB(false);
1122 }
1123
1124 size_t BlinkPlatformImpl::actualMemoryUsageMB() { 1060 size_t BlinkPlatformImpl::actualMemoryUsageMB() {
1125 return getMemoryUsageMB(true); 1061 return GetMemoryUsageKB() >> 10;
1126 }
1127
1128 size_t BlinkPlatformImpl::physicalMemoryMB() {
1129 return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB());
1130 }
1131
1132 size_t BlinkPlatformImpl::virtualMemoryLimitMB() {
1133 return static_cast<size_t>(base::SysInfo::AmountOfVirtualMemoryMB());
1134 } 1062 }
1135 1063
1136 size_t BlinkPlatformImpl::numberOfProcessors() { 1064 size_t BlinkPlatformImpl::numberOfProcessors() {
1137 return static_cast<size_t>(base::SysInfo::NumberOfProcessors()); 1065 return static_cast<size_t>(base::SysInfo::NumberOfProcessors());
1138 } 1066 }
1139 1067
1140 blink::WebDiscardableMemory* 1068 blink::WebDiscardableMemory*
1141 BlinkPlatformImpl::allocateAndLockDiscardableMemory(size_t bytes) { 1069 BlinkPlatformImpl::allocateAndLockDiscardableMemory(size_t bytes) {
1142 return content::WebDiscardableMemoryImpl::CreateLockedMemory(bytes).release(); 1070 return content::WebDiscardableMemoryImpl::CreateLockedMemory(bytes).release();
1143 } 1071 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 return WebString::fromUTF8(ui::KeycodeConverter::DomKeyToKeyString( 1115 return WebString::fromUTF8(ui::KeycodeConverter::DomKeyToKeyString(
1188 static_cast<ui::DomKey>(dom_key))); 1116 static_cast<ui::DomKey>(dom_key)));
1189 } 1117 }
1190 1118
1191 int BlinkPlatformImpl::domKeyEnumFromString(const WebString& key_string) { 1119 int BlinkPlatformImpl::domKeyEnumFromString(const WebString& key_string) {
1192 return static_cast<int>( 1120 return static_cast<int>(
1193 ui::KeycodeConverter::KeyStringToDomKey(key_string.utf8())); 1121 ui::KeycodeConverter::KeyStringToDomKey(key_string.utf8()));
1194 } 1122 }
1195 1123
1196 } // namespace content 1124 } // namespace content
OLDNEW
« no previous file with comments | « content/child/blink_platform_impl.h ('k') | third_party/WebKit/public/platform/Platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698