Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / extensions / updater / extension_cache_impl.h
blob58b07328188221f2b98680be617b2da7798a29ed
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_UPDATER_EXTENSION_CACHE_IMPL_H_
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_IMPL_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/callback_forward.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/browser/updater/extension_cache.h"
20 namespace base {
21 template <typename T> struct DefaultSingletonTraits;
24 namespace extensions {
26 class ExtensionCacheDelegate;
27 class LocalExtensionCache;
29 // Singleton call that caches extensions .crx files to share them between
30 // multiple users and profiles on the machine.
31 class ExtensionCacheImpl : public ExtensionCache,
32 public content::NotificationObserver {
33 public:
34 explicit ExtensionCacheImpl(scoped_ptr<ExtensionCacheDelegate> delegate);
35 ~ExtensionCacheImpl() override;
37 // Implementation of ExtensionCache.
38 void Start(const base::Closure& callback) override;
39 void Shutdown(const base::Closure& callback) override;
40 void AllowCaching(const std::string& id) override;
41 bool GetExtension(const std::string& id,
42 const std::string& expected_hash,
43 base::FilePath* file_path,
44 std::string* version) override;
45 void PutExtension(const std::string& id,
46 const std::string& expected_hash,
47 const base::FilePath& file_path,
48 const std::string& version,
49 const PutExtensionCallback& callback) override;
51 // Implementation of content::NotificationObserver:
52 void Observe(int type,
53 const content::NotificationSource& source,
54 const content::NotificationDetails& details) override;
56 private:
57 // Callback that is called when local cache is ready.
58 void OnCacheInitialized();
60 // Check if this extension is allowed to be cached.
61 bool CachingAllowed(const std::string& id);
63 // Cache implementation that uses local cache dir.
64 scoped_ptr<LocalExtensionCache> cache_;
66 // Set of extensions that can be cached.
67 std::set<std::string> allowed_extensions_;
69 // List of callbacks that should be called when the cache is ready.
70 std::vector<base::Closure> init_callbacks_;
72 // Observes failures to install CRX files.
73 content::NotificationRegistrar notification_registrar_;
75 // Weak factory for callbacks.
76 base::WeakPtrFactory<ExtensionCacheImpl> weak_ptr_factory_;
78 DISALLOW_COPY_AND_ASSIGN(ExtensionCacheImpl);
81 } // namespace extensions
83 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_IMPL_H_