| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/low_memory_observer.h" | 5 #include "chrome/browser/low_memory_observer.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/chromeos/chromeos_version.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/time.h" | 13 #include "base/time.h" |
| 13 #include "base/timer.h" | 14 #include "base/timer.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/system/runtime_environment.h" | |
| 16 #include "chrome/browser/oom_priority_manager.h" | 16 #include "chrome/browser/oom_priority_manager.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 | 20 |
| 21 namespace browser { | 21 namespace browser { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 // This is the file that will exist if low memory notification is available | 24 // This is the file that will exist if low memory notification is available |
| 25 // on the device. Whenever it becomes readable, it signals a low memory | 25 // on the device. Whenever it becomes readable, it signals a low memory |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 void LowMemoryObserverImpl::StartObservingOnFileThread() { | 108 void LowMemoryObserverImpl::StartObservingOnFileThread() { |
| 109 DCHECK_LE(file_descriptor_, 0) | 109 DCHECK_LE(file_descriptor_, 0) |
| 110 << "Attempted to start observation when it was already started."; | 110 << "Attempted to start observation when it was already started."; |
| 111 DCHECK(watcher_.get() == NULL); | 111 DCHECK(watcher_.get() == NULL); |
| 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 113 DCHECK(MessageLoopForIO::current()); | 113 DCHECK(MessageLoopForIO::current()); |
| 114 | 114 |
| 115 file_descriptor_ = ::open(kLowMemFile, O_RDONLY); | 115 file_descriptor_ = ::open(kLowMemFile, O_RDONLY); |
| 116 // Don't report this error unless we're really running on ChromeOS | 116 // Don't report this error unless we're really running on ChromeOS |
| 117 // to avoid testing spam. | 117 // to avoid testing spam. |
| 118 if (file_descriptor_ < 0 && | 118 if (file_descriptor_ < 0 && base::chromeos::IsRunningOnChromeOS()) { |
| 119 chromeos::system::runtime_environment::IsRunningOnChromeOS()) { | |
| 120 PLOG(ERROR) << "Unable to open " << kLowMemFile; | 119 PLOG(ERROR) << "Unable to open " << kLowMemFile; |
| 121 return; | 120 return; |
| 122 } | 121 } |
| 123 watcher_.reset(new MessageLoopForIO::FileDescriptorWatcher); | 122 watcher_.reset(new MessageLoopForIO::FileDescriptorWatcher); |
| 124 StartWatchingDescriptor(); | 123 StartWatchingDescriptor(); |
| 125 } | 124 } |
| 126 | 125 |
| 127 void LowMemoryObserverImpl::StopObservingOnFileThread() { | 126 void LowMemoryObserverImpl::StopObservingOnFileThread() { |
| 128 // If StartObserving failed, StopObserving will still get called. | 127 // If StartObserving failed, StopObserving will still get called. |
| 129 timer_.Stop(); | 128 timer_.Stop(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 174 |
| 176 void LowMemoryObserver::Stop() { | 175 void LowMemoryObserver::Stop() { |
| 177 BrowserThread::PostTask( | 176 BrowserThread::PostTask( |
| 178 BrowserThread::FILE, | 177 BrowserThread::FILE, |
| 179 FROM_HERE, | 178 FROM_HERE, |
| 180 base::Bind(&LowMemoryObserverImpl::StopObservingOnFileThread, | 179 base::Bind(&LowMemoryObserverImpl::StopObservingOnFileThread, |
| 181 observer_.get())); | 180 observer_.get())); |
| 182 } | 181 } |
| 183 | 182 |
| 184 } // namespace browser | 183 } // namespace browser |
| OLD | NEW |