OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/webkitclient_impl.h" | 5 #include "webkit/glue/webkitclient_impl.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <malloc.h> | 8 #include <malloc.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 using WebKit::WebURL; | 54 using WebKit::WebURL; |
55 using WebKit::WebURLLoader; | 55 using WebKit::WebURLLoader; |
56 using WebKit::WebVector; | 56 using WebKit::WebVector; |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
60 // A simple class to cache the memory usage for a given amount of time. | 60 // A simple class to cache the memory usage for a given amount of time. |
61 class MemoryUsageCache { | 61 class MemoryUsageCache { |
62 public: | 62 public: |
63 // Retrieves the Singleton. | 63 // Retrieves the Singleton. |
64 static MemoryUsageCache* Get() { | 64 static MemoryUsageCache* GetInstance() { |
65 return Singleton<MemoryUsageCache>::get(); | 65 return Singleton<MemoryUsageCache>::get(); |
66 } | 66 } |
67 | 67 |
68 MemoryUsageCache() : memory_value_(0) { Init(); } | 68 MemoryUsageCache() : memory_value_(0) { Init(); } |
69 ~MemoryUsageCache() {} | 69 ~MemoryUsageCache() {} |
70 | 70 |
71 void Init() { | 71 void Init() { |
72 const unsigned int kCacheSeconds = 1; | 72 const unsigned int kCacheSeconds = 1; |
73 cache_valid_time_ = base::TimeDelta::FromSeconds(kCacheSeconds); | 73 cache_valid_time_ = base::TimeDelta::FromSeconds(kCacheSeconds); |
74 } | 74 } |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 using base::ProcessMetrics; | 492 using base::ProcessMetrics; |
493 static ProcessMetrics* process_metrics = | 493 static ProcessMetrics* process_metrics = |
494 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()); | 494 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()); |
495 DCHECK(process_metrics); | 495 DCHECK(process_metrics); |
496 return process_metrics->GetPagefileUsage() >> 20; | 496 return process_metrics->GetPagefileUsage() >> 20; |
497 } | 497 } |
498 #endif | 498 #endif |
499 | 499 |
500 static size_t getMemoryUsageMB(bool bypass_cache) { | 500 static size_t getMemoryUsageMB(bool bypass_cache) { |
501 size_t current_mem_usage = 0; | 501 size_t current_mem_usage = 0; |
502 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::Get(); | 502 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); |
503 if (!bypass_cache && | 503 if (!bypass_cache && |
504 mem_usage_cache_singleton->IsCachedValueValid(¤t_mem_usage)) | 504 mem_usage_cache_singleton->IsCachedValueValid(¤t_mem_usage)) |
505 return current_mem_usage; | 505 return current_mem_usage; |
506 | 506 |
507 current_mem_usage = | 507 current_mem_usage = |
508 #if defined(OS_LINUX) | 508 #if defined(OS_LINUX) |
509 memoryUsageMBLinux(); | 509 memoryUsageMBLinux(); |
510 #elif defined(OS_MACOSX) | 510 #elif defined(OS_MACOSX) |
511 memoryUsageMBMac(); | 511 memoryUsageMBMac(); |
512 #else | 512 #else |
(...skipping 15 matching lines...) Expand all Loading... |
528 ++shared_timer_suspended_; | 528 ++shared_timer_suspended_; |
529 } | 529 } |
530 | 530 |
531 void WebKitClientImpl::ResumeSharedTimer() { | 531 void WebKitClientImpl::ResumeSharedTimer() { |
532 // The shared timer may have fired or been adjusted while we were suspended. | 532 // The shared timer may have fired or been adjusted while we were suspended. |
533 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) | 533 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) |
534 setSharedTimerFireTime(shared_timer_fire_time_); | 534 setSharedTimerFireTime(shared_timer_fire_time_); |
535 } | 535 } |
536 | 536 |
537 } // namespace webkit_glue | 537 } // namespace webkit_glue |
OLD | NEW |