Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: chrome/browser/chromeos/low_memory_observer.cc

Issue 10386206: RefCounted types should not have public destructors, chromeos edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to r143931 Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/low_memory_observer.h" 5 #include "chrome/browser/chromeos/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/chromeos/chromeos_version.h"
(...skipping 30 matching lines...) Expand all
41 // kLowMemoryCheckTimeoutMs milliseconds and then start watching again to see 41 // kLowMemoryCheckTimeoutMs milliseconds and then start watching again to see
42 // if we're still in a low memory state. This is to keep from discarding all 42 // if we're still in a low memory state. This is to keep from discarding all
43 // tabs the first time we enter the state, because it takes time for the 43 // tabs the first time we enter the state, because it takes time for the
44 // tabs to deallocate their memory. A timer isn't the perfect solution, but 44 // tabs to deallocate their memory. A timer isn't the perfect solution, but
45 // without any reliable indicator that a tab has had all its parts deallocated, 45 // without any reliable indicator that a tab has had all its parts deallocated,
46 // it's the next best thing. 46 // it's the next best thing.
47 class LowMemoryObserverImpl 47 class LowMemoryObserverImpl
48 : public base::RefCountedThreadSafe<LowMemoryObserverImpl> { 48 : public base::RefCountedThreadSafe<LowMemoryObserverImpl> {
49 public: 49 public:
50 LowMemoryObserverImpl() : watcher_delegate_(this), file_descriptor_(-1) {} 50 LowMemoryObserverImpl() : watcher_delegate_(this), file_descriptor_(-1) {}
51 ~LowMemoryObserverImpl() {
52 StopObservingOnFileThread();
53 }
54 51
55 // Start watching the low memory file for readability. 52 // Start watching the low memory file for readability.
56 // Calls to StartObserving should always be matched with calls to 53 // Calls to StartObserving should always be matched with calls to
57 // StopObserving. This method should only be called from the FILE thread. 54 // StopObserving. This method should only be called from the FILE thread.
58 void StartObservingOnFileThread(); 55 void StartObservingOnFileThread();
59 56
60 // Stop watching the low memory file for readability. 57 // Stop watching the low memory file for readability.
61 // May be safely called if StartObserving has not been called. 58 // May be safely called if StartObserving has not been called.
62 // This method should only be called from the FILE thread. 59 // This method should only be called from the FILE thread.
63 void StopObservingOnFileThread(); 60 void StopObservingOnFileThread();
64 61
65 private: 62 private:
63 friend class base::RefCountedThreadSafe<LowMemoryObserverImpl>;
64
65 ~LowMemoryObserverImpl() {
66 StopObservingOnFileThread();
67 }
68
66 // Start a timer to resume watching the low memory file descriptor. 69 // Start a timer to resume watching the low memory file descriptor.
67 void ScheduleNextObservation(); 70 void ScheduleNextObservation();
68 71
69 // Actually start watching the file descriptor. 72 // Actually start watching the file descriptor.
70 void StartWatchingDescriptor(); 73 void StartWatchingDescriptor();
71 74
72 // Delegate to receive events from WatchFileDescriptor. 75 // Delegate to receive events from WatchFileDescriptor.
73 class FileWatcherDelegate : public MessageLoopForIO::Watcher { 76 class FileWatcherDelegate : public MessageLoopForIO::Watcher {
74 public: 77 public:
75 explicit FileWatcherDelegate(LowMemoryObserverImpl* owner) 78 explicit FileWatcherDelegate(LowMemoryObserverImpl* owner)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 base::Bind(&LowMemoryObserverImpl::StopObservingOnFileThread, 184 base::Bind(&LowMemoryObserverImpl::StopObservingOnFileThread,
182 observer_.get())); 185 observer_.get()));
183 } 186 }
184 187
185 // static 188 // static
186 void LowMemoryObserver::SetLowMemoryMargin(int64 margin_mb) { 189 void LowMemoryObserver::SetLowMemoryMargin(int64 margin_mb) {
187 content::ZygoteHost::GetInstance()->AdjustLowMemoryMargin(margin_mb); 190 content::ZygoteHost::GetInstance()->AdjustLowMemoryMargin(margin_mb);
188 } 191 }
189 192
190 } // namespace chromeos 193 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/signed_settings.cc ('k') | chrome/browser/chromeos/media/media_player_extension_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698