[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [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_PREF_LOADER_H_ |
6 | #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ | ||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 7 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 8 | #include <string> |
9 | |||||
[email protected] | 1790275 | 2011-08-31 22:52:54 | [diff] [blame] | 10 | #include "base/compiler_specific.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/scoped_ptr.h" |
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 13 | #include "base/scoped_observer.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 14 | #include "base/values.h" |
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 15 | #include "chrome/browser/extensions/external_loader.h" |
blundell | 7282b51 | 2015-11-09 07:21:11 | [diff] [blame] | 16 | #include "components/browser_sync/browser/profile_sync_service.h" |
droger | 507e7e2f | 2015-04-03 18:56:23 | [diff] [blame] | 17 | #include "components/sync_driver/sync_service_observer.h" |
sdefresne | 875d078 | 2015-09-16 12:01:28 | [diff] [blame] | 18 | #include "components/syncable_prefs/pref_service_syncable_observer.h" |
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 19 | |
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 20 | class Profile; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 21 | |
sdefresne | 50c1e52 | 2015-09-18 09:47:51 | [diff] [blame] | 22 | namespace syncable_prefs { |
23 | class PrefServiceSyncable; | ||||
24 | } | ||||
25 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 26 | namespace extensions { |
27 | |||||
28 | // A specialization of the ExternalLoader that uses a json file to | ||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 29 | // look up which external extensions are registered. |
30 | // Instances of this class are expected to be created and destroyed on the UI | ||||
31 | // thread and they are expecting public method calls from the UI thread. | ||||
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 32 | class ExternalPrefLoader : public ExternalLoader, |
sdefresne | 50c1e52 | 2015-09-18 09:47:51 | [diff] [blame] | 33 | public syncable_prefs::PrefServiceSyncableObserver, |
droger | 507e7e2f | 2015-04-03 18:56:23 | [diff] [blame] | 34 | public sync_driver::SyncServiceObserver { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 35 | public: |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 36 | enum Options { |
37 | NONE = 0, | ||||
38 | |||||
39 | // Ensure that only root can force an external install by checking | ||||
40 | // that all components of the path to external extensions files are | ||||
41 | // owned by root and not writable by any non-root user. | ||||
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 42 | ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0, |
43 | |||||
44 | // Delay external preference load. It delays default apps installation | ||||
45 | // to not overload the system on first time user login. | ||||
46 | DELAY_LOAD_UNTIL_PRIORITY_SYNC = 1 << 1, | ||||
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 47 | }; |
48 | |||||
[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [diff] [blame] | 49 | // |base_path_id| is the directory containing the external_extensions.json |
50 | // file or the standalone extension manifest files. Relative file paths to | ||||
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 51 | // extension files are resolved relative to this path. |profile| is used to |
52 | // wait priority sync if DELAY_LOAD_UNTIL_PRIORITY_SYNC set. | ||||
53 | ExternalPrefLoader(int base_path_id, Options options, Profile* profile); | ||||
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 54 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 55 | const base::FilePath GetBaseCrxFilePath() override; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 56 | |
57 | protected: | ||||
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 58 | ~ExternalPrefLoader() override; |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 59 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 60 | void StartLoading() override; |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 61 | bool IsOptionSet(Options option) { |
62 | return (options_ & option) != 0; | ||||
63 | } | ||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 64 | |
[email protected] | ebb489f | 2013-09-19 22:08:52 | [diff] [blame] | 65 | // The resource id of the base path with the information about the json |
66 | // file containing which extensions to load. | ||||
67 | const int base_path_id_; | ||||
68 | |||||
69 | const Options options_; | ||||
70 | |||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 71 | private: |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 72 | friend class base::RefCountedThreadSafe<ExternalLoader>; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 73 | |
sdefresne | 50c1e52 | 2015-09-18 09:47:51 | [diff] [blame] | 74 | // syncable_prefs::PrefServiceSyncableObserver: |
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 75 | void OnIsSyncingChanged() override; |
76 | |||||
droger | 507e7e2f | 2015-04-03 18:56:23 | [diff] [blame] | 77 | // sync_driver::SyncServiceObserver |
ginkage | f66fae52 | 2015-03-03 16:38:16 | [diff] [blame] | 78 | void OnStateChanged() override; |
79 | |||||
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 80 | // If priority sync ready posts LoadOnFileThread and return true. |
81 | bool PostLoadIfPrioritySyncReady(); | ||||
82 | |||||
ginkage | f66fae52 | 2015-03-03 16:38:16 | [diff] [blame] | 83 | // Post LoadOnFileThread and stop observing for sync service states. |
84 | void PostLoadAndRemoveObservers(); | ||||
85 | |||||
[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [diff] [blame] | 86 | // Actually searches for and loads candidate standalone extension preference |
87 | // files in the path corresponding to |base_path_id|. | ||||
88 | // Must be called on the file thread. | ||||
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 89 | void LoadOnFileThread(); |
90 | |||||
[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [diff] [blame] | 91 | // Extracts the information contained in an external_extension.json file |
92 | // regarding which extensions to install. |prefs| will be modified to | ||||
93 | // receive the extracted extension information. | ||||
94 | // Must be called from the File thread. | ||||
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 95 | void ReadExternalExtensionPrefFile(base::DictionaryValue* prefs); |
[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [diff] [blame] | 96 | |
97 | // Extracts the information contained in standalone external extension | ||||
98 | // json files (<extension id>.json) regarding what external extensions | ||||
99 | // to install. |prefs| will be modified to receive the extracted extension | ||||
100 | // information. | ||||
101 | // Must be called from the File thread. | ||||
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 102 | void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs); |
[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [diff] [blame] | 103 | |
[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [diff] [blame] | 104 | // The path (coresponding to |base_path_id_| containing the json files |
105 | // describing which extensions to load. | ||||
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 106 | base::FilePath base_path_; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 107 | |
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 108 | // Profile that loads these external prefs. |
109 | // Needed for waiting for waiting priority sync. | ||||
110 | Profile* profile_; | ||||
111 | |||||
sdefresne | 50c1e52 | 2015-09-18 09:47:51 | [diff] [blame] | 112 | // Used for registering observer for syncable_prefs::PrefServiceSyncable. |
113 | ScopedObserver<syncable_prefs::PrefServiceSyncable, | ||||
114 | syncable_prefs::PrefServiceSyncableObserver> | ||||
dpolukhin | a772ed6 | 2014-10-28 11:54:54 | [diff] [blame] | 115 | syncable_pref_observer_; |
116 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 117 | DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 118 | }; |
119 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 120 | // A simplified version of ExternalPrefLoader that loads the dictionary |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 121 | // from json data specified in a string. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 122 | class ExternalTestingLoader : public ExternalLoader { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 123 | public: |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 124 | ExternalTestingLoader(const std::string& json_data, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 125 | const base::FilePath& fake_base_path); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 126 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 127 | const base::FilePath GetBaseCrxFilePath() override; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 128 | |
129 | protected: | ||||
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 130 | void StartLoading() override; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 131 | |
132 | private: | ||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 133 | friend class base::RefCountedThreadSafe<ExternalLoader>; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 134 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 135 | ~ExternalTestingLoader() override; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 136 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 137 | base::FilePath fake_base_path_; |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 138 | scoped_ptr<base::DictionaryValue> testing_prefs_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 139 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 140 | DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 141 | }; |
142 | |||||
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 143 | } // namespace extensions |
144 | |||||
145 | #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ |