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