Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: chrome/browser/extensions/extension_garbage_collector.h

Issue 303693011: Add garbage collection for shared extensions on Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
40 // Manually trigger GarbageCollectExtensions() for testing. 34 // Manually trigger GarbageCollectExtensions() for testing.
41 void GarbageCollectExtensionsForTest(); 35 void GarbageCollectExtensionsForTest();
42 36
43 // Overriddes for KeyedService: 37 // Overriddes for KeyedService:
44 virtual void Shutdown() OVERRIDE; 38 virtual void Shutdown() OVERRIDE;
45 39
46 // Overriddes for InstallObserver 40 // Overriddes for InstallObserver
47 virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE; 41 virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE;
48 virtual void OnFinishCrxInstall(const std::string& extension_id, 42 virtual void OnFinishCrxInstall(const std::string& extension_id,
49 bool success) OVERRIDE; 43 bool success) OVERRIDE;
50 44
51 private: 45 protected:
52 // Cleans up the extension install directory. It can end up with garbage in it 46 // Cleans up the extension install directory. It can end up with garbage in it
53 // if extensions can't initially be removed when they are uninstalled (eg if a 47 // if extensions can't initially be removed when they are uninstalled (eg if a
54 // file is in use). 48 // file is in use).
55 // Obsolete version directories are removed, as are directories that aren't 49 // Obsolete version directories are removed, as are directories that aren't
56 // found in the ExtensionPrefs. 50 // found in the ExtensionPrefs.
57 // The "Temp" directory that is used during extension installation will get 51 // The "Temp" directory that is used during extension installation will get
58 // removed iff there are no pending installations. 52 // removed iff there are no pending installations.
59 void GarbageCollectExtensions(); 53 virtual void GarbageCollectExtensions();
60 54
61 // Garbage collects apps/extensions isolated storage if it is uninstalled. 55 // Garbage collects apps/extensions isolated storage if it is uninstalled.
62 // There is an exception for ephemeral apps because they can outlive their 56 // There is an exception for ephemeral apps because they can outlive their
63 // cache lifetimes. 57 // cache lifetimes.
64 void GarbageCollectIsolatedStorageIfNeeded(); 58 void GarbageCollectIsolatedStorageIfNeeded();
65 59
60 static void GarbageCollectExtensionsOnFileThread(
61 const base::FilePath& install_directory,
62 const std::multimap<std::string, base::FilePath>& extension_paths);
63
66 // The BrowserContext associated with the GarbageCollector. 64 // The BrowserContext associated with the GarbageCollector.
67 content::BrowserContext* context_; 65 content::BrowserContext* context_;
68 66
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
77 // The number of currently ongoing CRX installations. This is used to prevent 67 // The number of currently ongoing CRX installations. This is used to prevent
78 // garbage collection from running while a CRX is being installed. 68 // garbage collection from running while a CRX is being installed.
79 int crx_installs_in_progress_; 69 int crx_installs_in_progress_;
80 70
81 // Generate weak pointers for safely posting to the file thread for garbage 71 // Generate weak pointers for safely posting to the file thread for garbage
82 // collection. 72 // collection.
83 base::WeakPtrFactory<ExtensionGarbageCollector> weak_factory_; 73 base::WeakPtrFactory<ExtensionGarbageCollector> weak_factory_;
84 74
85 DISALLOW_COPY_AND_ASSIGN(ExtensionGarbageCollector); 75 DISALLOW_COPY_AND_ASSIGN(ExtensionGarbageCollector);
86 }; 76 };
87 77
88 } // namespace extensions 78 } // namespace extensions
89 79
90 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_ 80 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698