| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/external_loader.h" | 15 #include "chrome/browser/extensions/external_loader.h" |
| 16 #include "components/browser_sync/profile_sync_service.h" | 16 #include "components/browser_sync/profile_sync_service.h" |
| 17 #include "components/sync/driver/sync_service_observer.h" | 17 #include "components/sync/driver/sync_service_observer.h" |
| 18 #include "components/syncable_prefs/pref_service_syncable_observer.h" | 18 #include "components/sync_preferences/pref_service_syncable_observer.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace syncable_prefs { | 22 namespace sync_preferences { |
| 23 class PrefServiceSyncable; | 23 class PrefServiceSyncable; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 // A specialization of the ExternalLoader that uses a json file to | 28 // A specialization of the ExternalLoader that uses a json file to |
| 29 // look up which external extensions are registered. | 29 // look up which external extensions are registered. |
| 30 // Instances of this class are expected to be created and destroyed on the UI | 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. | 31 // thread and they are expecting public method calls from the UI thread. |
| 32 class ExternalPrefLoader : public ExternalLoader, | 32 class ExternalPrefLoader : public ExternalLoader, |
| 33 public syncable_prefs::PrefServiceSyncableObserver, | 33 public sync_preferences::PrefServiceSyncableObserver, |
| 34 public syncer::SyncServiceObserver { | 34 public syncer::SyncServiceObserver { |
| 35 public: | 35 public: |
| 36 enum Options { | 36 enum Options { |
| 37 NONE = 0, | 37 NONE = 0, |
| 38 | 38 |
| 39 // Ensure that only root can force an external install by checking | 39 // Ensure that only root can force an external install by checking |
| 40 // that all components of the path to external extensions files are | 40 // that all components of the path to external extensions files are |
| 41 // owned by root and not writable by any non-root user. | 41 // owned by root and not writable by any non-root user. |
| 42 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0, | 42 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0, |
| 43 | 43 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 64 | 64 |
| 65 // The resource id of the base path with the information about the json | 65 // The resource id of the base path with the information about the json |
| 66 // file containing which extensions to load. | 66 // file containing which extensions to load. |
| 67 const int base_path_id_; | 67 const int base_path_id_; |
| 68 | 68 |
| 69 const Options options_; | 69 const Options options_; |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 friend class base::RefCountedThreadSafe<ExternalLoader>; | 72 friend class base::RefCountedThreadSafe<ExternalLoader>; |
| 73 | 73 |
| 74 // syncable_prefs::PrefServiceSyncableObserver: | 74 // sync_preferences::PrefServiceSyncableObserver: |
| 75 void OnIsSyncingChanged() override; | 75 void OnIsSyncingChanged() override; |
| 76 | 76 |
| 77 // syncer::SyncServiceObserver | 77 // syncer::SyncServiceObserver |
| 78 void OnStateChanged() override; | 78 void OnStateChanged() override; |
| 79 | 79 |
| 80 // If priority sync ready posts LoadOnFileThread and return true. | 80 // If priority sync ready posts LoadOnFileThread and return true. |
| 81 bool PostLoadIfPrioritySyncReady(); | 81 bool PostLoadIfPrioritySyncReady(); |
| 82 | 82 |
| 83 // Post LoadOnFileThread and stop observing for sync service states. | 83 // Post LoadOnFileThread and stop observing for sync service states. |
| 84 void PostLoadAndRemoveObservers(); | 84 void PostLoadAndRemoveObservers(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 102 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs); | 102 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs); |
| 103 | 103 |
| 104 // The path (coresponding to |base_path_id_| containing the json files | 104 // The path (coresponding to |base_path_id_| containing the json files |
| 105 // describing which extensions to load. | 105 // describing which extensions to load. |
| 106 base::FilePath base_path_; | 106 base::FilePath base_path_; |
| 107 | 107 |
| 108 // Profile that loads these external prefs. | 108 // Profile that loads these external prefs. |
| 109 // Needed for waiting for waiting priority sync. | 109 // Needed for waiting for waiting priority sync. |
| 110 Profile* profile_; | 110 Profile* profile_; |
| 111 | 111 |
| 112 // Used for registering observer for syncable_prefs::PrefServiceSyncable. | 112 // Used for registering observer for sync_preferences::PrefServiceSyncable. |
| 113 ScopedObserver<syncable_prefs::PrefServiceSyncable, | 113 ScopedObserver<sync_preferences::PrefServiceSyncable, |
| 114 syncable_prefs::PrefServiceSyncableObserver> | 114 sync_preferences::PrefServiceSyncableObserver> |
| 115 syncable_pref_observer_; | 115 syncable_pref_observer_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader); | 117 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 // A simplified version of ExternalPrefLoader that loads the dictionary | 120 // A simplified version of ExternalPrefLoader that loads the dictionary |
| 121 // from json data specified in a string. | 121 // from json data specified in a string. |
| 122 class ExternalTestingLoader : public ExternalLoader { | 122 class ExternalTestingLoader : public ExternalLoader { |
| 123 public: | 123 public: |
| 124 ExternalTestingLoader(const std::string& json_data, | 124 ExternalTestingLoader(const std::string& json_data, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 | 136 |
| 137 base::FilePath fake_base_path_; | 137 base::FilePath fake_base_path_; |
| 138 std::unique_ptr<base::DictionaryValue> testing_prefs_; | 138 std::unique_ptr<base::DictionaryValue> testing_prefs_; |
| 139 | 139 |
| 140 DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader); | 140 DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader); |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 } // namespace extensions | 143 } // namespace extensions |
| 144 | 144 |
| 145 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ | 145 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ |
| OLD | NEW |