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 #ifndef ATHENA_RESOURCE_MANAGER_PUBLIC_RESOURCE_MANAGER_H_ 6 #define ATHENA_RESOURCE_MANAGER_PUBLIC_RESOURCE_MANAGER_H_ 7 8 #include "athena/athena_export.h" 9 #include "athena/resource_manager/memory_pressure_notifier.h" 10 #include "base/basictypes.h" 11 12 namespace athena { 13 14 // The resource manager is monitoring activity changes, low memory conditions 15 // and other events to control the activity state (pre-/un-/re-/loading them) 16 // to keep enough memory free that no jank/lag will show when new applications 17 // are loaded and / or a navigation between applications takes place. 18 class ATHENA_EXPORT ResourceManager { 19 public: 20 // Creates the instance handling the resources. 21 static void Create(); 22 static ResourceManager* Get(); 23 static void Shutdown(); 24 25 ResourceManager(); 26 virtual ~ResourceManager(); 27 28 // Unit tests can simulate MemoryPressure changes with this call. 29 // Note: Even though the default unit test ResourceManagerDelegte 30 // implementation ensures that the MemoryPressure event will not go off, 31 // this call will also explicitly stop the MemoryPressureNotifier. 32 virtual void SetMemoryPressureAndStopMonitoring( 33 MemoryPressureObserver::MemoryPressure pressure) = 0; 34 35 // Resource management calls require time to show effect (until memory 36 // gets actually released). This function lets override the time limiter 37 // between two calls to allow for more/less aggressive timeouts. 38 // By calling this function, the next call to the Resource manager will be 39 // executed immediately. 40 virtual void SetWaitTimeBetweenResourceManageCalls(int time_in_ms) = 0; 41 42 // Suspend the resource manager temporarily if |pause| is set. This can be 43 // called before e.g. re-arranging the order of activities. Once called with 44 // |pause| == false any queued operations will be performed and the resource 45 // manager will continue its work. 46 virtual void Pause(bool pause) = 0; 47 48 private: 49 DISALLOW_COPY_AND_ASSIGN(ResourceManager); 50 }; 51 52 // Use this scoped object to pause/restart the resource manager. 53 class ScopedPauseResourceManager { 54 public: ScopedPauseResourceManager()55 ScopedPauseResourceManager() { 56 ResourceManager::Get()->Pause(true); 57 } ~ScopedPauseResourceManager()58 ~ScopedPauseResourceManager() { 59 ResourceManager::Get()->Pause(false); 60 } 61 private: 62 DISALLOW_COPY_AND_ASSIGN(ScopedPauseResourceManager); 63 }; 64 65 } // namespace athena 66 67 #endif // ATHENA_RESOURCE_MANAGER_PUBLIC_RESOURCE_MANAGER_H_ 68