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