|
1 /* |
|
2 * Copyright (c) 2008 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 GOOM actions (e.g. closing applications and running plugins). |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <apgtask.h> |
|
20 |
|
21 #include "goomcloseapp.h" |
|
22 #include "goomtraces.h" |
|
23 #include "goomappclosetimer.h" |
|
24 #include "goomappclosewatcher.h" |
|
25 #include "goomactionref.h" |
|
26 |
|
27 const TInt KGOomMaxAppExitTime = 1000000; |
|
28 const TInt KGOomMaxAppAfterKillWaitTime = 1000000; |
|
29 |
|
30 CGOomCloseApp* CGOomCloseApp::NewL(MGOomActionObserver& aStateChangeObserver, RWsSession& aWs) |
|
31 { |
|
32 FUNC_LOG; |
|
33 |
|
34 CGOomCloseApp* self = new (ELeave) CGOomCloseApp(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 CGOomAction::MemoryFreed when it is done |
|
43 void CGOomCloseApp::FreeMemory(TInt) |
|
44 { |
|
45 FUNC_LOG; |
|
46 |
|
47 iAppCloserRunning = ETrue; |
|
48 |
|
49 // Set the TApaTask to the app |
|
50 iCurrentTask.SetWgId(iWgId); |
|
51 |
|
52 // Start a timer and the thread watcher |
|
53 iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing); |
|
54 iAppCloseTimer->After(KGOomMaxAppExitTime); |
|
55 iAppCloseWatcher->Start(iCurrentTask); |
|
56 // Tell the app to close |
|
57 TRACES1("CGOomCloseApp::FreeMemory: Closing app with window group id %d",iWgId); |
|
58 iCurrentTask.EndTask(); |
|
59 } |
|
60 |
|
61 CGOomCloseApp::~CGOomCloseApp() |
|
62 { |
|
63 FUNC_LOG; |
|
64 |
|
65 if (iAppCloseTimer) |
|
66 iAppCloseTimer->Cancel(); |
|
67 |
|
68 if (iAppCloseWatcher) |
|
69 iAppCloseWatcher->Cancel(); |
|
70 |
|
71 delete iAppCloseTimer; |
|
72 delete iAppCloseWatcher; |
|
73 } |
|
74 |
|
75 // Callback from CGOomAppCloseWatcher and CGOomAppCloseTimer |
|
76 void CGOomCloseApp::CloseAppEvent() |
|
77 { |
|
78 FUNC_LOG; |
|
79 |
|
80 // The application has closed (or we have a timeout) |
|
81 iAppCloserRunning = EFalse; |
|
82 |
|
83 if (iAppCloseTimer) |
|
84 iAppCloseTimer->Cancel(); |
|
85 if (iAppCloseWatcher) |
|
86 iAppCloseWatcher->Cancel(); |
|
87 |
|
88 iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled); |
|
89 iAppCloseTimer->After(KGOomMaxAppAfterKillWaitTime); |
|
90 //MemoryFreed(KErrNone); |
|
91 } |
|
92 |
|
93 void CGOomCloseApp::Reconfigure(const TActionRef& aRef) |
|
94 { |
|
95 FUNC_LOG; |
|
96 |
|
97 iWgId = aRef.WgId(); |
|
98 } |
|
99 |
|
100 void CGOomCloseApp::ConstructL() |
|
101 { |
|
102 FUNC_LOG; |
|
103 |
|
104 iAppCloseTimer = CGOomAppCloseTimer::NewL(*this); |
|
105 iAppCloseWatcher = new(ELeave) CGOomAppCloseWatcher(*this); |
|
106 } |
|
107 |
|
108 CGOomCloseApp::CGOomCloseApp(MGOomActionObserver& aStateChangeObserver, RWsSession& aWs) |
|
109 : CGOomAction(aStateChangeObserver), iCurrentTask(aWs) |
|
110 { |
|
111 FUNC_LOG; |
|
112 } |
|
113 |
|
114 // ---------------------------------------------- |
|
115 // Callback from iAppCloseTimer |
|
116 // App refused to exit gracefully on given time |
|
117 // ---------------------------------------------- |
|
118 // |
|
119 void CGOomCloseApp::KillTask() |
|
120 { |
|
121 FUNC_LOG; |
|
122 if (iAppCloseWatcher) |
|
123 { |
|
124 iAppCloseWatcher->Cancel(); |
|
125 } |
|
126 |
|
127 iCurrentTask.KillTask(); |
|
128 iAppCloserRunning = EFalse; |
|
129 |
|
130 iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled); |
|
131 iAppCloseTimer->After(KGOomMaxAppAfterKillWaitTime); |
|
132 //MemoryFreed(KErrNone); |
|
133 } |
|
134 |
|
135 void CGOomCloseApp::KillTaskWaitDone() |
|
136 { |
|
137 FUNC_LOG; |
|
138 MemoryFreed(KErrNone); |
|
139 } |
|
140 |