OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #import "ios/chrome/app/memory_monitor.h" |
| 6 |
| 7 #include <dispatch/dispatch.h> |
| 8 #import <Foundation/NSPathUtilities.h> |
| 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" |
| 12 #include "base/location.h" |
| 13 #include "base/logging.h" |
| 14 #import "base/mac/foundation_util.h" |
| 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/sys_info.h" |
| 17 #import "ios/chrome/browser/crash_report/breakpad_helper.h" |
| 18 #include "ios/web/public/web_thread.h" |
| 19 |
| 20 namespace ios_internal { |
| 21 |
| 22 void AsynchronousFreeMemoryMonitor() { |
| 23 UpdateBreakpadMemoryValues(); |
| 24 web::WebThread::PostDelayedTask( |
| 25 web::WebThread::FILE, FROM_HERE, |
| 26 base::Bind(&ios_internal::AsynchronousFreeMemoryMonitor), |
| 27 base::TimeDelta::FromSeconds(30)); |
| 28 } |
| 29 |
| 30 void UpdateBreakpadMemoryValues() { |
| 31 int freeMemory = |
| 32 static_cast<int>(base::SysInfo::AmountOfAvailablePhysicalMemory() / 1024); |
| 33 breakpad_helper::SetCurrentFreeMemoryInKB(freeMemory); |
| 34 NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, |
| 35 NSUserDomainMask, YES); |
| 36 NSString* value = base::mac::ObjCCastStrict<NSString>([paths lastObject]); |
| 37 base::FilePath filePath = base::FilePath(base::SysNSStringToUTF8(value)); |
| 38 int freeDiskSpace = |
| 39 static_cast<int>(base::SysInfo::AmountOfFreeDiskSpace(filePath) / 1024); |
| 40 breakpad_helper::SetCurrentFreeDiskInKB(freeDiskSpace); |
| 41 } |
| 42 } |
OLD | NEW |