[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 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame^] | 9 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
11 | #include "base/memory/scoped_ptr.h" | ||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 12 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 13 | namespace base { |
14 | class DictionaryValue; | ||||
15 | } | ||||
16 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 17 | namespace extensions { |
18 | class ExternalProviderImpl; | ||||
19 | |||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 20 | // Base class for gathering a list of external extensions. Subclasses |
21 | // implement loading from registry, JSON file, policy. | ||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 22 | // Instances are owned by ExternalProviderImpl objects. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 23 | // Instances are created on the UI thread and expect public method calls from |
24 | // the UI thread. Some subclasses introduce new methods that are executed on the | ||||
25 | // FILE thread. | ||||
26 | // The sequence of loading the extension list: | ||||
27 | // 1.) StartLoading() - checks if a loading task is already running | ||||
28 | // 2.) Load() - implemented in subclasses | ||||
[email protected] | 23b0097 | 2011-10-04 17:17:26 | [diff] [blame] | 29 | // 3.) LoadFinished() |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 30 | // 4.) owner_->SetPrefs() |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 31 | class ExternalLoader : public base::RefCountedThreadSafe<ExternalLoader> { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 32 | public: |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 33 | ExternalLoader(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 34 | |
35 | // Specifies the provider that owns this object. | ||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 36 | void Init(ExternalProviderImpl* owner); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 37 | |
38 | // Called by the owner before it gets deleted. | ||||
39 | void OwnerShutdown(); | ||||
40 | |||||
41 | // Initiates the possibly asynchronous loading of extension list. | ||||
42 | // It is the responsibility of the caller to ensure that calls to | ||||
43 | // this method do not overlap with each other. | ||||
44 | // Implementations of this method should save the loaded results | ||||
45 | // in prefs_ and then call LoadFinished. | ||||
46 | virtual void StartLoading() = 0; | ||||
47 | |||||
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 48 | // Some external providers allow relative file paths to local CRX files. |
49 | // Subclasses that want this behavior should override this method to | ||||
50 | // return the absolute path from which relative paths should be resolved. | ||||
51 | // By default, return an empty path, which indicates that relative paths | ||||
52 | // are not allowed. | ||||
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 53 | virtual const base::FilePath GetBaseCrxFilePath(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 54 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 55 | protected: |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 56 | virtual ~ExternalLoader(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 57 | |
58 | // Notifies the provider that the list of extensions has been loaded. | ||||
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 59 | virtual void LoadFinished(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 60 | |
61 | // Used for passing the list of extensions from the method that loads them | ||||
62 | // to |LoadFinished|. To ensure thread safety, the rules are the following: | ||||
63 | // if this value is written on another thread than the UI, then it should | ||||
64 | // only be written in a task that was posted from |StartLoading|. After that, | ||||
65 | // this task should invoke |LoadFinished| with a PostTask. This scheme of | ||||
66 | // posting tasks will avoid concurrent access and imply the necessary memory | ||||
67 | // barriers. | ||||
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 68 | scoped_ptr<base::DictionaryValue> prefs_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 69 | |
70 | private: | ||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 71 | friend class base::RefCountedThreadSafe<ExternalLoader>; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 72 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 73 | ExternalProviderImpl* owner_; // weak |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 74 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(ExternalLoader); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 76 | }; |
77 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 78 | } // namespace extensions |
79 | |||||
80 | #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_ |