[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_ |
6 | #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_ | ||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 7 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 8 | #include <memory> |
9 | |||||
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 13 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 14 | namespace base { |
15 | class DictionaryValue; | ||||
16 | } | ||||
17 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 18 | namespace extensions { |
19 | class ExternalProviderImpl; | ||||
20 | |||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 21 | // Base class for gathering a list of external extensions. Subclasses |
22 | // implement loading from registry, JSON file, policy. | ||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 23 | // Instances are owned by ExternalProviderImpl objects. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 24 | // Instances are created on the UI thread and expect public method calls from |
25 | // the UI thread. Some subclasses introduce new methods that are executed on the | ||||
26 | // FILE thread. | ||||
27 | // The sequence of loading the extension list: | ||||
28 | // 1.) StartLoading() - checks if a loading task is already running | ||||
29 | // 2.) Load() - implemented in subclasses | ||||
[email protected] | 23b0097 | 2011-10-04 17:17:26 | [diff] [blame] | 30 | // 3.) LoadFinished() |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 31 | // 4.) owner_->SetPrefs() |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 32 | class ExternalLoader : public base::RefCountedThreadSafe<ExternalLoader> { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 33 | public: |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 34 | ExternalLoader(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 35 | |
36 | // Specifies the provider that owns this object. | ||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 37 | void Init(ExternalProviderImpl* owner); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 38 | |
39 | // Called by the owner before it gets deleted. | ||||
40 | void OwnerShutdown(); | ||||
41 | |||||
42 | // Initiates the possibly asynchronous loading of extension list. | ||||
Istiaque Ahmed | ef99c8ea | 2017-09-06 21:19:57 | [diff] [blame] | 43 | // Implementations of this method should call LoadFinished with results. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 44 | virtual void StartLoading() = 0; |
45 | |||||
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 46 | // Some external providers allow relative file paths to local CRX files. |
47 | // Subclasses that want this behavior should override this method to | ||||
48 | // return the absolute path from which relative paths should be resolved. | ||||
49 | // By default, return an empty path, which indicates that relative paths | ||||
50 | // are not allowed. | ||||
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 51 | virtual const base::FilePath GetBaseCrxFilePath(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 52 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 53 | protected: |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 54 | virtual ~ExternalLoader(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 55 | |
56 | // Notifies the provider that the list of extensions has been loaded. | ||||
Istiaque Ahmed | ef99c8ea | 2017-09-06 21:19:57 | [diff] [blame] | 57 | virtual void LoadFinished(std::unique_ptr<base::DictionaryValue> prefs); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 58 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 59 | // Notifies the provider that the list of extensions has been updated. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 60 | virtual void OnUpdated(std::unique_ptr<base::DictionaryValue> updated_prefs); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 61 | |
Istiaque Ahmed | ef99c8ea | 2017-09-06 21:19:57 | [diff] [blame] | 62 | // Returns true if this loader has an owner. |
63 | // This is useful to know if calling LoadFinished/OnUpdated will propagate | ||||
64 | // prefs to our owner. | ||||
65 | bool has_owner() const { return owner_ != nullptr; } | ||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 66 | |
67 | private: | ||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 68 | friend class base::RefCountedThreadSafe<ExternalLoader>; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 69 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 70 | ExternalProviderImpl* owner_; // weak |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 71 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 72 | DISALLOW_COPY_AND_ASSIGN(ExternalLoader); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 73 | }; |
74 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 75 | } // namespace extensions |
76 | |||||
77 | #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_ |