blob: e22656547f5744cc0382f7abc9bdff9f09a50588 [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
[email protected]8e4560b62011-01-14 10:09:148#include <string>
9
[email protected]17902752011-08-31 22:52:5410#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
dpolukhina772ed62014-10-28 11:54:5412#include "base/scoped_observer.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"
blundell7282b512015-11-09 07:21:1115#include "components/browser_sync/browser/profile_sync_service.h"
droger507e7e2f2015-04-03 18:56:2316#include "components/sync_driver/sync_service_observer.h"
sdefresne875d0782015-09-16 12:01:2817#include "components/syncable_prefs/pref_service_syncable_observer.h"
dpolukhina772ed62014-10-28 11:54:5418
dpolukhina772ed62014-10-28 11:54:5419class Profile;
[email protected]8e4560b62011-01-14 10:09:1420
sdefresne50c1e522015-09-18 09:47:5121namespace syncable_prefs {
22class PrefServiceSyncable;
23}
24
[email protected]5df038b2012-07-16 19:03:2725namespace extensions {
26
27// A specialization of the ExternalLoader that uses a json file to
[email protected]8e4560b62011-01-14 10:09:1428// 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.
dpolukhina772ed62014-10-28 11:54:5431class ExternalPrefLoader : public ExternalLoader,
sdefresne50c1e522015-09-18 09:47:5132 public syncable_prefs::PrefServiceSyncableObserver,
droger507e7e2f2015-04-03 18:56:2333 public sync_driver::SyncServiceObserver {
[email protected]8e4560b62011-01-14 10:09:1434 public:
[email protected]73e4c362011-09-22 14:47:1835 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.
dpolukhina772ed62014-10-28 11:54:5441 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]73e4c362011-09-22 14:47:1846 };
47
[email protected]ed7bbb52012-05-02 11:07:2948 // |base_path_id| is the directory containing the external_extensions.json
49 // file or the standalone extension manifest files. Relative file paths to
dpolukhina772ed62014-10-28 11:54:5450 // 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]f0841cd2011-01-19 15:07:2453
dchengae36a4a2014-10-21 12:36:3654 const base::FilePath GetBaseCrxFilePath() override;
[email protected]8e4560b62011-01-14 10:09:1455
56 protected:
dpolukhina772ed62014-10-28 11:54:5457 ~ExternalPrefLoader() override;
[email protected]a4567732013-07-25 21:01:2058
dchengae36a4a2014-10-21 12:36:3659 void StartLoading() override;
[email protected]73e4c362011-09-22 14:47:1860 bool IsOptionSet(Options option) {
61 return (options_ & option) != 0;
62 }
[email protected]8e4560b62011-01-14 10:09:1463
[email protected]ebb489f2013-09-19 22:08:5264 // 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]8e4560b62011-01-14 10:09:1470 private:
[email protected]5df038b2012-07-16 19:03:2771 friend class base::RefCountedThreadSafe<ExternalLoader>;
[email protected]8e4560b62011-01-14 10:09:1472
sdefresne50c1e522015-09-18 09:47:5173 // syncable_prefs::PrefServiceSyncableObserver:
dpolukhina772ed62014-10-28 11:54:5474 void OnIsSyncingChanged() override;
75
droger507e7e2f2015-04-03 18:56:2376 // sync_driver::SyncServiceObserver
ginkagef66fae522015-03-03 16:38:1677 void OnStateChanged() override;
78
dpolukhina772ed62014-10-28 11:54:5479 // If priority sync ready posts LoadOnFileThread and return true.
80 bool PostLoadIfPrioritySyncReady();
81
ginkagef66fae522015-03-03 16:38:1682 // Post LoadOnFileThread and stop observing for sync service states.
83 void PostLoadAndRemoveObservers();
84
[email protected]ed7bbb52012-05-02 11:07:2985 // 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]8e4560b62011-01-14 10:09:1488 void LoadOnFileThread();
89
[email protected]ed7bbb52012-05-02 11:07:2990 // 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]cb1078de2013-12-23 20:04:2294 void ReadExternalExtensionPrefFile(base::DictionaryValue* prefs);
[email protected]ed7bbb52012-05-02 11:07:2995
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]cb1078de2013-12-23 20:04:22101 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs);
[email protected]ed7bbb52012-05-02 11:07:29102
[email protected]ed7bbb52012-05-02 11:07:29103 // The path (coresponding to |base_path_id_| containing the json files
104 // describing which extensions to load.
[email protected]650b2d52013-02-10 03:41:45105 base::FilePath base_path_;
[email protected]f0841cd2011-01-19 15:07:24106
dpolukhina772ed62014-10-28 11:54:54107 // Profile that loads these external prefs.
108 // Needed for waiting for waiting priority sync.
109 Profile* profile_;
110
sdefresne50c1e522015-09-18 09:47:51111 // Used for registering observer for syncable_prefs::PrefServiceSyncable.
112 ScopedObserver<syncable_prefs::PrefServiceSyncable,
113 syncable_prefs::PrefServiceSyncableObserver>
dpolukhina772ed62014-10-28 11:54:54114 syncable_pref_observer_;
115
[email protected]5df038b2012-07-16 19:03:27116 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader);
[email protected]8e4560b62011-01-14 10:09:14117};
118
[email protected]5df038b2012-07-16 19:03:27119// A simplified version of ExternalPrefLoader that loads the dictionary
[email protected]8e4560b62011-01-14 10:09:14120// from json data specified in a string.
[email protected]5df038b2012-07-16 19:03:27121class ExternalTestingLoader : public ExternalLoader {
[email protected]8e4560b62011-01-14 10:09:14122 public:
[email protected]5df038b2012-07-16 19:03:27123 ExternalTestingLoader(const std::string& json_data,
[email protected]650b2d52013-02-10 03:41:45124 const base::FilePath& fake_base_path);
[email protected]f0841cd2011-01-19 15:07:24125
dchengae36a4a2014-10-21 12:36:36126 const base::FilePath GetBaseCrxFilePath() override;
[email protected]8e4560b62011-01-14 10:09:14127
128 protected:
dchengae36a4a2014-10-21 12:36:36129 void StartLoading() override;
[email protected]8e4560b62011-01-14 10:09:14130
131 private:
[email protected]5df038b2012-07-16 19:03:27132 friend class base::RefCountedThreadSafe<ExternalLoader>;
[email protected]8e4560b62011-01-14 10:09:14133
dchengae36a4a2014-10-21 12:36:36134 ~ExternalTestingLoader() override;
[email protected]8e4560b62011-01-14 10:09:14135
[email protected]650b2d52013-02-10 03:41:45136 base::FilePath fake_base_path_;
[email protected]cb1078de2013-12-23 20:04:22137 scoped_ptr<base::DictionaryValue> testing_prefs_;
[email protected]8e4560b62011-01-14 10:09:14138
[email protected]5df038b2012-07-16 19:03:27139 DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader);
[email protected]8e4560b62011-01-14 10:09:14140};
141
[email protected]5df038b2012-07-16 19:03:27142} // namespace extensions
143
144#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_