Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / extension_garbage_collector.h
blobbc3fb9da781f33abcfb99352bd32f5ef235b254f
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_
8 #include <map>
9 #include <string>
11 #include "base/files/file_path.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/extensions/install_observer.h"
14 #include "components/keyed_service/core/keyed_service.h"
16 namespace content {
17 class BrowserContext;
20 namespace extensions {
22 // The class responsible for cleaning up the cruft left behind on the file
23 // system by uninstalled (or failed install) extensions.
24 // The class is owned by ExtensionService, but is mostly independent. Tasks to
25 // garbage collect extensions and isolated storage are posted once the
26 // ExtensionSystem signals ready.
27 class ExtensionGarbageCollector : public KeyedService, public InstallObserver {
28 public:
29 explicit ExtensionGarbageCollector(content::BrowserContext* context);
30 ~ExtensionGarbageCollector() override;
32 static ExtensionGarbageCollector* Get(content::BrowserContext* context);
34 // Manually trigger GarbageCollectExtensions() for testing.
35 void GarbageCollectExtensionsForTest();
37 // Overriddes for KeyedService:
38 void Shutdown() override;
40 // Overriddes for InstallObserver
41 void OnBeginCrxInstall(const std::string& extension_id) override;
42 void OnFinishCrxInstall(const std::string& extension_id,
43 bool success) override;
45 protected:
46 // 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
48 // file is in use).
49 // Obsolete version directories are removed, as are directories that aren't
50 // found in the ExtensionPrefs.
51 // The "Temp" directory that is used during extension installation will get
52 // removed iff there are no pending installations.
53 virtual void GarbageCollectExtensions();
55 // Garbage collects apps/extensions isolated storage if it is uninstalled.
56 // There is an exception for ephemeral apps because they can outlive their
57 // cache lifetimes.
58 void GarbageCollectIsolatedStorageIfNeeded();
60 static void GarbageCollectExtensionsOnFileThread(
61 const base::FilePath& install_directory,
62 const std::multimap<std::string, base::FilePath>& extension_paths);
64 // The BrowserContext associated with the GarbageCollector.
65 content::BrowserContext* context_;
67 // The number of currently ongoing CRX installations. This is used to prevent
68 // garbage collection from running while a CRX is being installed.
69 int crx_installs_in_progress_;
71 // Generate weak pointers for safely posting to the file thread for garbage
72 // collection.
73 base::WeakPtrFactory<ExtensionGarbageCollector> weak_factory_;
75 DISALLOW_COPY_AND_ASSIGN(ExtensionGarbageCollector);
78 } // namespace extensions
80 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_