|
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 "goomappclosewatcher.h" |
|
20 #include "goomcloseapp.h" |
|
21 #include "goomtraces.h" |
|
22 |
|
23 CGOomAppCloseWatcher::CGOomAppCloseWatcher(CGOomCloseApp& aMonitor) : CActive(CActive::EPriorityStandard), iMonitor(aMonitor) |
|
24 { |
|
25 FUNC_LOG; |
|
26 |
|
27 CActiveScheduler::Add(this); |
|
28 } |
|
29 |
|
30 CGOomAppCloseWatcher::~CGOomAppCloseWatcher() |
|
31 { |
|
32 FUNC_LOG; |
|
33 |
|
34 Cancel(); |
|
35 } |
|
36 |
|
37 void CGOomAppCloseWatcher::Start(const TApaTask& aTask) |
|
38 { |
|
39 FUNC_LOG; |
|
40 |
|
41 if (!IsActive()) |
|
42 { |
|
43 TInt err = iThread.Open(aTask.ThreadId()); |
|
44 if (err == KErrNone) |
|
45 { |
|
46 iOriginalProcessPriority = iThread.ProcessPriority(); |
|
47 iThread.SetProcessPriority(EPriorityForeground); |
|
48 iThread.Logon(iStatus); |
|
49 SetActive(); |
|
50 } |
|
51 else |
|
52 { |
|
53 TRequestStatus* s = &iStatus; |
|
54 User::RequestComplete(s, err); |
|
55 SetActive(); |
|
56 } |
|
57 } |
|
58 } |
|
59 |
|
60 void CGOomAppCloseWatcher::DoCancel() |
|
61 { |
|
62 FUNC_LOG; |
|
63 |
|
64 iThread.LogonCancel(iStatus); |
|
65 iThread.SetProcessPriority(iOriginalProcessPriority); |
|
66 iThread.Close(); |
|
67 } |
|
68 |
|
69 void CGOomAppCloseWatcher::RunL() |
|
70 { |
|
71 FUNC_LOG; |
|
72 |
|
73 if (iThread.Handle()) |
|
74 iThread.SetProcessPriority(iOriginalProcessPriority); |
|
75 iThread.Close(); |
|
76 // Experimentation shows that memory may take up to 40ms |
|
77 // to be released back to the system after app thread close. |
|
78 // Using this delay should minimise the number of apps that |
|
79 // need to be closed to recover the necessary memory. |
|
80 const TInt KAppTidyUpDelay = 40000; |
|
81 User::After(KAppTidyUpDelay); |
|
82 iMonitor.CloseAppEvent(); |
|
83 } |