Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_garbage_collector.h
blob499fda9692a5a6b968f1d804b1b40e33ade70d6e
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 class ExtensionService;
22 namespace extensions {
24 // The class responsible for cleaning up the cruft left behind on the file
25 // system by uninstalled (or failed install) extensions.
26 // The class is owned by ExtensionService, but is mostly independent. Tasks to
27 // garbage collect extensions and isolated storage are posted once the
28 // ExtensionSystem signals ready.
29 class ExtensionGarbageCollector : public KeyedService, public InstallObserver {
30 public:
31 explicit ExtensionGarbageCollector(content::BrowserContext* context);
32 virtual ~ExtensionGarbageCollector();
34 static ExtensionGarbageCollector* Get(content::BrowserContext* context);
36 #if defined(OS_CHROMEOS)
37 // Enable or disable garbage collection. See |disable_garbage_collection_|.
38 void disable_garbage_collection() { disable_garbage_collection_ = true; }
39 void enable_garbage_collection() { disable_garbage_collection_ = false; }
40 #endif
42 // Manually trigger GarbageCollectExtensions() for testing.
43 void GarbageCollectExtensionsForTest();
45 // Overriddes for KeyedService:
46 virtual void Shutdown() OVERRIDE;
48 // Overriddes for InstallObserver
49 virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE;
50 virtual void OnFinishCrxInstall(const std::string& extension_id,
51 bool success) OVERRIDE;
53 private:
54 // Cleans up the extension install directory. It can end up with garbage in it
55 // if extensions can't initially be removed when they are uninstalled (eg if a
56 // file is in use).
57 // Obsolete version directories are removed, as are directories that aren't
58 // found in the ExtensionPrefs.
59 // The "Temp" directory that is used during extension installation will get
60 // removed iff there are no pending installations.
61 void GarbageCollectExtensions();
63 // Garbage collects apps/extensions isolated storage if it is uninstalled.
64 // There is an exception for ephemeral apps because they can outlive their
65 // cache lifetimes.
66 void GarbageCollectIsolatedStorageIfNeeded();
68 // The BrowserContext associated with the GarbageCollector.
69 content::BrowserContext* context_;
71 #if defined(OS_CHROMEOS)
72 // TODO(rkc): HACK alert - this is only in place to allow the
73 // kiosk_mode_screensaver to prevent its extension from getting garbage
74 // collected. Remove this once KioskModeScreensaver is removed.
75 // See crbug.com/280363
76 bool disable_garbage_collection_;
77 #endif
79 // The number of currently ongoing CRX installations. This is used to prevent
80 // garbage collection from running while a CRX is being installed.
81 int crx_installs_in_progress_;
83 // Generate weak pointers for safely posting to the file thread for garbage
84 // collection.
85 base::WeakPtrFactory<ExtensionGarbageCollector> weak_factory_;
87 DISALLOW_COPY_AND_ASSIGN(ExtensionGarbageCollector);
90 } // namespace extensions
92 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GARBAGE_COLLECTOR_H_