Fix some lint errors in url_request_context_adapter
[chromium-blink-merge.git] / athena / resource_manager / public / resource_manager.h
blob98297534b50cf009916bf6b5e0f963ff73ca15af
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.
5 #ifndef ATHENA_RESOURCE_MANAGER_PUBLIC_RESOURCE_MANAGER_H_
6 #define ATHENA_RESOURCE_MANAGER_PUBLIC_RESOURCE_MANAGER_H_
8 #include "athena/athena_export.h"
9 #include "base/basictypes.h"
11 namespace athena {
13 // The resource manager is monitoring activity changes, low memory conditions
14 // and other events to control the activity state (pre-/un-/re-/loading them)
15 // to keep enough memory free that no jank/lag will show when new applications
16 // are loaded and / or a navigation between applications takes place.
17 class ATHENA_EXPORT ResourceManager {
18 public:
19 // The reported memory pressure. Note: The value is intentionally abstracted
20 // since the real amount of free memory is only estimated (due to e.g. zram).
21 // Note: The bigger the index of the pressure level, the more resources are
22 // in use.
23 enum MemoryPressure {
24 MEMORY_PRESSURE_UNKNOWN = 0, // The memory pressure cannot be determined.
25 MEMORY_PRESSURE_LOW, // Single call if fill level is below 50%.
26 MEMORY_PRESSURE_MODERATE, // Polled for fill level of ~50 .. 75%.
27 MEMORY_PRESSURE_HIGH, // Polled for fill level of ~75% .. 90%.
28 MEMORY_PRESSURE_CRITICAL, // Polled for fill level of above ~90%.
31 // Creates the instance handling the resources.
32 static void Create();
33 static ResourceManager* Get();
34 static void Shutdown();
36 ResourceManager();
37 virtual ~ResourceManager();
39 // Unit tests can simulate MemoryPressure changes with this call.
40 // Note: Even though the default unit test ResourceManagerDelegte
41 // implementation ensures that the MemoryPressure event will not go off,
42 // this call will also explicitly stop the MemoryPressureNotifier.
43 virtual void SetMemoryPressureAndStopMonitoring(
44 ResourceManager::MemoryPressure pressure) = 0;
46 // Resource management calls require time to show effect (until memory
47 // gets actually released). This function lets override the time limiter
48 // between two calls to allow for more/less aggressive timeouts.
49 // By calling this function, the next call to the Resource manager will be
50 // executed immediately.
51 virtual void SetWaitTimeBetweenResourceManageCalls(int time_in_ms) = 0;
53 // Suspend the resource manager temporarily if |pause| is set. This can be
54 // called before e.g. re-arranging the order of activities. Once called with
55 // |pause| == false any queued operations will be performed and the resource
56 // manager will continue its work.
57 virtual void Pause(bool pause) = 0;
59 private:
60 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
63 // Use this scoped object to pause/restart the resource manager.
64 class ScopedPauseResourceManager {
65 public:
66 ScopedPauseResourceManager() {
67 ResourceManager::Get()->Pause(true);
69 ~ScopedPauseResourceManager() {
70 ResourceManager::Get()->Pause(false);
72 private:
73 DISALLOW_COPY_AND_ASSIGN(ScopedPauseResourceManager);
76 } // namespace athena
78 #endif // ATHENA_RESOURCE_MANAGER_PUBLIC_RESOURCE_MANAGER_H_