| 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/chromeos/memory/low_memory_observer.h" | 5 #include "chrome/browser/chromeos/memory/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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 void StartWatchingDescriptor(); | 73 void StartWatchingDescriptor(); |
| 74 | 74 |
| 75 // Delegate to receive events from WatchFileDescriptor. | 75 // Delegate to receive events from WatchFileDescriptor. |
| 76 class FileWatcherDelegate : public base::MessageLoopForIO::Watcher { | 76 class FileWatcherDelegate : public base::MessageLoopForIO::Watcher { |
| 77 public: | 77 public: |
| 78 explicit FileWatcherDelegate(LowMemoryObserverImpl* owner) | 78 explicit FileWatcherDelegate(LowMemoryObserverImpl* owner) |
| 79 : owner_(owner) {} | 79 : owner_(owner) {} |
| 80 virtual ~FileWatcherDelegate() {} | 80 virtual ~FileWatcherDelegate() {} |
| 81 | 81 |
| 82 // Overrides for base::MessageLoopForIO::Watcher | 82 // Overrides for base::MessageLoopForIO::Watcher |
| 83 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {} | 83 virtual void OnFileCanWriteWithoutBlocking(int fd) override {} |
| 84 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { | 84 virtual void OnFileCanReadWithoutBlocking(int fd) override { |
| 85 LOG(WARNING) << "Low memory condition detected. Discarding a tab."; | 85 LOG(WARNING) << "Low memory condition detected. Discarding a tab."; |
| 86 // We can only discard tabs on the UI thread. | 86 // We can only discard tabs on the UI thread. |
| 87 base::Callback<void(void)> callback = base::Bind(&DiscardTab); | 87 base::Callback<void(void)> callback = base::Bind(&DiscardTab); |
| 88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| 89 owner_->ScheduleNextObservation(); | 89 owner_->ScheduleNextObservation(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Sends off a discard request to the OomPriorityManager. Must be run on | 92 // Sends off a discard request to the OomPriorityManager. Must be run on |
| 93 // the UI thread. | 93 // the UI thread. |
| 94 static void DiscardTab() { | 94 static void DiscardTab() { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 void LowMemoryObserver::Stop() { | 183 void LowMemoryObserver::Stop() { |
| 184 BrowserThread::PostTask( | 184 BrowserThread::PostTask( |
| 185 BrowserThread::FILE, | 185 BrowserThread::FILE, |
| 186 FROM_HERE, | 186 FROM_HERE, |
| 187 base::Bind(&LowMemoryObserverImpl::StopObservingOnFileThread, | 187 base::Bind(&LowMemoryObserverImpl::StopObservingOnFileThread, |
| 188 observer_.get())); | 188 observer_.get())); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace chromeos | 191 } // namespace chromeos |
| OLD | NEW |