|
1 /* |
|
2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Classes for executing OOM actions (e.g. closing applications and running plugins). |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <apgtask.h> |
|
20 |
|
21 #include "oomcloseapp.h" |
|
22 #include "OomTraces.h" |
|
23 #include "oomappclosetimer.h" |
|
24 #include "oomappclosewatcher.h" |
|
25 #include "oomactionref.h" |
|
26 #include "oommemorymonitor.h" |
|
27 #include "oomconstants.hrh" |
|
28 #include "oompanic.h" |
|
29 |
|
30 COomCloseApp* COomCloseApp::NewL(MOomActionObserver& aStateChangeObserver, RWsSession& aWs) |
|
31 { |
|
32 FUNC_LOG; |
|
33 |
|
34 COomCloseApp* self = new (ELeave) COomCloseApp(aStateChangeObserver, aWs); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // Close the application in order to free memory |
|
42 // Call the COomAction::MemoryFreed when it is done |
|
43 void COomCloseApp::FreeMemory(TInt, TBool aIsDataPaged) |
|
44 { |
|
45 FUNC_LOG; |
|
46 |
|
47 iAppCloserRunning = ETrue; |
|
48 |
|
49 // Set the TApaTask to the app |
|
50 iCurrentTask.SetWgId(iWgId); |
|
51 |
|
52 __ASSERT_DEBUG(!iAppCloseTimer->IsActive(), OomMonitorPanic(KStartingActiveCloseAppTimer)); |
|
53 __ASSERT_DEBUG(!iAppCloseWatcher->IsActive(), OomMonitorPanic(KStartingActiveAppCloseWatcher)); |
|
54 // Start a timer and the thread watcher |
|
55 iAppCloseTimer->After(CMemoryMonitor::GlobalConfig().iMaxAppExitTime * KMicrosecondsInMillisecond); |
|
56 iAppCloseWatcher->Start(iCurrentTask); |
|
57 // Tell the app to close |
|
58 TRACES1("COomCloseApp::FreeMemory: Closing app with window group id %d",iWgId); |
|
59 |
|
60 RThread thread; |
|
61 TInt err=thread.Open(iCurrentTask.ThreadId()); |
|
62 if (!err) |
|
63 { |
|
64 RProcess process; |
|
65 thread.Process(process); |
|
66 TBool isDataPaged = process.DefaultDataPaged(); |
|
67 if((aIsDataPaged && isDataPaged) || (!aIsDataPaged && !isDataPaged )) |
|
68 { |
|
69 iCurrentTask.EndTask(); |
|
70 } |
|
71 } |
|
72 } |
|
73 |
|
74 COomCloseApp::~COomCloseApp() |
|
75 { |
|
76 FUNC_LOG; |
|
77 |
|
78 if (iAppCloseTimer) |
|
79 iAppCloseTimer->Cancel(); |
|
80 |
|
81 if (iAppCloseWatcher) |
|
82 iAppCloseWatcher->Cancel(); |
|
83 |
|
84 delete iAppCloseTimer; |
|
85 delete iAppCloseWatcher; |
|
86 } |
|
87 |
|
88 // Callback from COomAppCloseWatcher and COomAppCloseTimer |
|
89 void COomCloseApp::CloseAppEvent() |
|
90 { |
|
91 FUNC_LOG; |
|
92 |
|
93 // The application has closed (or we have a timeout) |
|
94 iAppCloserRunning = EFalse; |
|
95 |
|
96 if (iAppCloseTimer) |
|
97 iAppCloseTimer->Cancel(); |
|
98 if (iAppCloseWatcher) |
|
99 iAppCloseWatcher->Cancel(); |
|
100 |
|
101 MemoryFreed(KErrNone); |
|
102 } |
|
103 |
|
104 void COomCloseApp::Reconfigure(const TActionRef& aRef) |
|
105 { |
|
106 FUNC_LOG; |
|
107 |
|
108 iWgId = aRef.WgId(); |
|
109 } |
|
110 |
|
111 void COomCloseApp::ConstructL() |
|
112 { |
|
113 FUNC_LOG; |
|
114 |
|
115 iAppCloseTimer = COomAppCloseTimer::NewL(*this); |
|
116 iAppCloseWatcher = new(ELeave) COomAppCloseWatcher(*this); |
|
117 } |
|
118 |
|
119 COomCloseApp::COomCloseApp(MOomActionObserver& aStateChangeObserver, RWsSession& aWs) |
|
120 : COomAction(aStateChangeObserver), iCurrentTask(aWs) |
|
121 { |
|
122 FUNC_LOG; |
|
123 } |