blob: b06e9c921e1f541e780d55e53eb863c08d4cf573 [file] [log] [blame]
[email protected]ed7bbb52012-05-02 11:07:291// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8e4560b62011-01-14 10:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5df038b2012-07-16 19:03:275#ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_
[email protected]8e4560b62011-01-14 10:09:147
dchengc963c7142016-04-08 03:55:228#include <memory>
[email protected]8e4560b62011-01-14 10:09:149#include <string>
10
[email protected]17902752011-08-31 22:52:5411#include "base/compiler_specific.h"
avia2f4804a2015-12-24 23:11:1312#include "base/macros.h"
[email protected]8e4560b62011-01-14 10:09:1413#include "base/values.h"
dpolukhina772ed62014-10-28 11:54:5414#include "chrome/browser/extensions/external_loader.h"
dpolukhina772ed62014-10-28 11:54:5415
dpolukhina772ed62014-10-28 11:54:5416class Profile;
[email protected]8e4560b62011-01-14 10:09:1417
[email protected]5df038b2012-07-16 19:03:2718namespace extensions {
19
20// A specialization of the ExternalLoader that uses a json file to
[email protected]8e4560b62011-01-14 10:09:1421// look up which external extensions are registered.
22// Instances of this class are expected to be created and destroyed on the UI
23// thread and they are expecting public method calls from the UI thread.
Istiaque Ahmedef99c8ea2017-09-06 21:19:5724class ExternalPrefLoader : public ExternalLoader {
[email protected]8e4560b62011-01-14 10:09:1425 public:
[email protected]73e4c362011-09-22 14:47:1826 enum Options {
27 NONE = 0,
28
29 // Ensure that only root can force an external install by checking
30 // that all components of the path to external extensions files are
31 // owned by root and not writable by any non-root user.
dpolukhina772ed62014-10-28 11:54:5432 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0,
33
34 // Delay external preference load. It delays default apps installation
35 // to not overload the system on first time user login.
36 DELAY_LOAD_UNTIL_PRIORITY_SYNC = 1 << 1,
[email protected]98820ac72019-01-24 19:47:1637
38 // Use profile user type filter to load extensions.
39 USE_USER_TYPE_PROFILE_FILTER = 1 << 2,
[email protected]73e4c362011-09-22 14:47:1840 };
41
[email protected]ed7bbb52012-05-02 11:07:2942 // |base_path_id| is the directory containing the external_extensions.json
43 // file or the standalone extension manifest files. Relative file paths to
dpolukhina772ed62014-10-28 11:54:5444 // extension files are resolved relative to this path. |profile| is used to
45 // wait priority sync if DELAY_LOAD_UNTIL_PRIORITY_SYNC set.
[email protected]98820ac72019-01-24 19:47:1646 // |options| is combination of |Options|.
47 ExternalPrefLoader(int base_path_id, int options, Profile* profile);
[email protected]f0841cd2011-01-19 15:07:2448
dchengae36a4a2014-10-21 12:36:3649 const base::FilePath GetBaseCrxFilePath() override;
[email protected]8e4560b62011-01-14 10:09:1450
51 protected:
dpolukhina772ed62014-10-28 11:54:5452 ~ExternalPrefLoader() override;
[email protected]a4567732013-07-25 21:01:2053
dchengae36a4a2014-10-21 12:36:3654 void StartLoading() override;
[email protected]73e4c362011-09-22 14:47:1855 bool IsOptionSet(Options option) {
56 return (options_ & option) != 0;
57 }
[email protected]8e4560b62011-01-14 10:09:1458
[email protected]ebb489f2013-09-19 22:08:5259 // The resource id of the base path with the information about the json
60 // file containing which extensions to load.
61 const int base_path_id_;
62
[email protected]98820ac72019-01-24 19:47:1663 const int options_;
[email protected]ebb489f2013-09-19 22:08:5264
[email protected]8e4560b62011-01-14 10:09:1465 private:
[email protected]5df038b2012-07-16 19:03:2766 friend class base::RefCountedThreadSafe<ExternalLoader>;
Istiaque Ahmed2a59ae02017-08-24 04:43:2667 friend class ExternalTestingLoader;
Istiaque Ahmedef99c8ea2017-09-06 21:19:5768 friend class TestExternalPrefLoader;
69
70 class PrioritySyncReadyWaiter;
Istiaque Ahmed2a59ae02017-08-24 04:43:2671
72 // Extracts extension information from a json file serialized by |serializer|.
73 // |path| is only used for informational purposes (outputted when an error
74 // occurs). An empty dictionary is returned in case of failure (e.g. invalid
75 // path or json content).
76 static std::unique_ptr<base::DictionaryValue> ExtractExtensionPrefs(
77 base::ValueDeserializer* deserializer,
78 const base::FilePath& path);
[email protected]8e4560b62011-01-14 10:09:1479
dpolukhina772ed62014-10-28 11:54:5480 // If priority sync ready posts LoadOnFileThread and return true.
81 bool PostLoadIfPrioritySyncReady();
82
ginkagef66fae522015-03-03 16:38:1683 // Post LoadOnFileThread and stop observing for sync service states.
84 void PostLoadAndRemoveObservers();
85
[email protected]ed7bbb52012-05-02 11:07:2986 // 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.
Istiaque Ahmedef99c8ea2017-09-06 21:19:5789 // Note: Overridden in tests.
90 virtual void LoadOnFileThread();
[email protected]8e4560b62011-01-14 10:09:1491
[email protected]ed7bbb52012-05-02 11:07:2992 // Extracts the information contained in an external_extension.json file
93 // regarding which extensions to install. |prefs| will be modified to
94 // receive the extracted extension information.
95 // Must be called from the File thread.
[email protected]cb1078de2013-12-23 20:04:2296 void ReadExternalExtensionPrefFile(base::DictionaryValue* prefs);
[email protected]ed7bbb52012-05-02 11:07:2997
98 // Extracts the information contained in standalone external extension
99 // json files (<extension id>.json) regarding what external extensions
100 // to install. |prefs| will be modified to receive the extracted extension
101 // information.
102 // Must be called from the File thread.
[email protected]cb1078de2013-12-23 20:04:22103 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs);
[email protected]ed7bbb52012-05-02 11:07:29104
Istiaque Ahmedef99c8ea2017-09-06 21:19:57105 void OnPrioritySyncReady(PrioritySyncReadyWaiter* waiter);
106
[email protected]ed7bbb52012-05-02 11:07:29107 // The path (coresponding to |base_path_id_| containing the json files
108 // describing which extensions to load.
[email protected]650b2d52013-02-10 03:41:45109 base::FilePath base_path_;
[email protected]f0841cd2011-01-19 15:07:24110
dpolukhina772ed62014-10-28 11:54:54111 // Profile that loads these external prefs.
112 // Needed for waiting for waiting priority sync.
113 Profile* profile_;
114
[email protected]07072a5d2019-02-12 02:39:03115 // User type determined by |profile_|. Used to filter extensions. In some unit
116 // tests may not be set.
117 const std::string user_type_;
118
Istiaque Ahmedef99c8ea2017-09-06 21:19:57119 std::vector<std::unique_ptr<PrioritySyncReadyWaiter>> pending_waiter_list_;
dpolukhina772ed62014-10-28 11:54:54120
[email protected]5df038b2012-07-16 19:03:27121 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader);
[email protected]8e4560b62011-01-14 10:09:14122};
123
[email protected]5df038b2012-07-16 19:03:27124} // namespace extensions
125
126#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_