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