OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 // The class is owned by ExtensionService, but is mostly independent. Tasks to | 24 // The class is owned by ExtensionService, but is mostly independent. Tasks to |
25 // garbage collect extensions and isolated storage are posted once the | 25 // garbage collect extensions and isolated storage are posted once the |
26 // ExtensionSystem signals ready. | 26 // ExtensionSystem signals ready. |
27 class ExtensionGarbageCollector : public KeyedService, public InstallObserver { | 27 class ExtensionGarbageCollector : public KeyedService, public InstallObserver { |
28 public: | 28 public: |
29 explicit ExtensionGarbageCollector(content::BrowserContext* context); | 29 explicit ExtensionGarbageCollector(content::BrowserContext* context); |
30 virtual ~ExtensionGarbageCollector(); | 30 virtual ~ExtensionGarbageCollector(); |
31 | 31 |
32 static ExtensionGarbageCollector* Get(content::BrowserContext* context); | 32 static ExtensionGarbageCollector* Get(content::BrowserContext* context); |
33 | 33 |
| 34 #if defined(OS_CHROMEOS) |
| 35 // Enable or disable garbage collection. See |disable_garbage_collection_|. |
| 36 void disable_garbage_collection() { disable_garbage_collection_ = true; } |
| 37 void enable_garbage_collection() { disable_garbage_collection_ = false; } |
| 38 #endif |
| 39 |
34 // Manually trigger GarbageCollectExtensions() for testing. | 40 // Manually trigger GarbageCollectExtensions() for testing. |
35 void GarbageCollectExtensionsForTest(); | 41 void GarbageCollectExtensionsForTest(); |
36 | 42 |
37 // Overriddes for KeyedService: | 43 // Overriddes for KeyedService: |
38 virtual void Shutdown() OVERRIDE; | 44 virtual void Shutdown() OVERRIDE; |
39 | 45 |
40 // Overriddes for InstallObserver | 46 // Overriddes for InstallObserver |
41 virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE; | 47 virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE; |
42 virtual void OnFinishCrxInstall(const std::string& extension_id, | 48 virtual void OnFinishCrxInstall(const std::string& extension_id, |
43 bool success) OVERRIDE; | 49 bool success) OVERRIDE; |
44 | 50 |
45 protected: | 51 private: |
46 // Cleans up the extension install directory. It can end up with garbage in it | 52 // Cleans up the extension install directory. It can end up with garbage in it |
47 // if extensions can't initially be removed when they are uninstalled (eg if a | 53 // if extensions can't initially be removed when they are uninstalled (eg if a |
48 // file is in use). | 54 // file is in use). |
49 // Obsolete version directories are removed, as are directories that aren't | 55 // Obsolete version directories are removed, as are directories that aren't |
50 // found in the ExtensionPrefs. | 56 // found in the ExtensionPrefs. |
51 // The "Temp" directory that is used during extension installation will get | 57 // The "Temp" directory that is used during extension installation will get |
52 // removed iff there are no pending installations. | 58 // removed iff there are no pending installations. |
53 virtual void GarbageCollectExtensions(); | 59 void GarbageCollectExtensions(); |
54 | 60 |
55 // Garbage collects apps/extensions isolated storage if it is uninstalled. | 61 // Garbage collects apps/extensions isolated storage if it is uninstalled. |
56 // There is an exception for ephemeral apps because they can outlive their | 62 // There is an exception for ephemeral apps because they can outlive their |
57 // cache lifetimes. | 63 // cache lifetimes. |
58 void GarbageCollectIsolatedStorageIfNeeded(); | 64 void GarbageCollectIsolatedStorageIfNeeded(); |
59 | 65 |
60 static void GarbageCollectExtensionsOnFileThread( | |
61 const base::FilePath& install_directory, | |
62 const std::multimap<std::string, base::FilePath>& extension_paths); | |
63 | |
64 // The BrowserContext associated with the GarbageCollector. | 66 // The BrowserContext associated with the GarbageCollector. |
65 content::BrowserContext* context_; | 67 content::BrowserContext* context_; |
66 | 68 |
| 69 #if defined(OS_CHROMEOS) |
| 70 // TODO(rkc): HACK alert - this is only in place to allow the |
| 71 // kiosk_mode_screensaver to prevent its extension from getting garbage |
| 72 // collected. Remove this once KioskModeScreensaver is removed. |
| 73 // See crbug.com/280363 |
| 74 bool disable_garbage_collection_; |
| 75 #endif |
| 76 |
67 // The number of currently ongoing CRX installations. This is used to prevent | 77 // The number of currently ongoing CRX installations. This is used to prevent |
68 // garbage collection from running while a CRX is being installed. | 78 // garbage collection from running while a CRX is being installed. |
69 int crx_installs_in_progress_; | 79 int crx_installs_in_progress_; |
70 | 80 |
71 // Generate weak pointers for safely posting to the file thread for garbage | 81 // Generate weak pointers for safely posting to the file thread for garbage |
72 // collection. | 82 // collection. |
73 base::WeakPtrFactory<ExtensionGarbageCollector> weak_factory_; | 83 base::WeakPtrFactory<ExtensionGarbageCollector> weak_factory_; |
74 | 84 |
75 DISALLOW_COPY_AND_ASSIGN(ExtensionGarbageCollector); | 85 DISALLOW_COPY_AND_ASSIGN(ExtensionGarbageCollector); |
76 }; | 86 }; |
77 | 87 |
78 } // namespace extensions | 88 } // namespace extensions |
79 | 89 |
80 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_ | 90 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_ |
OLD | NEW |