| 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 "chrome/browser/extensions/external_loader.h" | |
| 9 | |
| 10 #include <string> | 8 #include <string> |
| 11 | 9 |
| 12 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/external_loader.h" |
| 14 #include "chrome/browser/prefs/pref_service_syncable_observer.h" |
| 15 |
| 16 class Profile; |
| 15 | 17 |
| 16 namespace extensions { | 18 namespace extensions { |
| 17 | 19 |
| 18 // A specialization of the ExternalLoader that uses a json file to | 20 // A specialization of the ExternalLoader that uses a json file to |
| 19 // look up which external extensions are registered. | 21 // look up which external extensions are registered. |
| 20 // Instances of this class are expected to be created and destroyed on the UI | 22 // Instances of this class are expected to be created and destroyed on the UI |
| 21 // thread and they are expecting public method calls from the UI thread. | 23 // thread and they are expecting public method calls from the UI thread. |
| 22 class ExternalPrefLoader : public ExternalLoader { | 24 class ExternalPrefLoader : public ExternalLoader, |
| 25 public PrefServiceSyncableObserver { |
| 23 public: | 26 public: |
| 24 enum Options { | 27 enum Options { |
| 25 NONE = 0, | 28 NONE = 0, |
| 26 | 29 |
| 27 // Ensure that only root can force an external install by checking | 30 // Ensure that only root can force an external install by checking |
| 28 // that all components of the path to external extensions files are | 31 // that all components of the path to external extensions files are |
| 29 // owned by root and not writable by any non-root user. | 32 // owned by root and not writable by any non-root user. |
| 30 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0 | 33 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0, |
| 34 |
| 35 // Delay external preference load. It delays default apps installation |
| 36 // to not overload the system on first time user login. |
| 37 DELAY_LOAD_UNTIL_PRIORITY_SYNC = 1 << 1, |
| 31 }; | 38 }; |
| 32 | 39 |
| 33 // |base_path_id| is the directory containing the external_extensions.json | 40 // |base_path_id| is the directory containing the external_extensions.json |
| 34 // file or the standalone extension manifest files. Relative file paths to | 41 // file or the standalone extension manifest files. Relative file paths to |
| 35 // extension files are resolved relative to this path. | 42 // extension files are resolved relative to this path. |profile| is used to |
| 36 ExternalPrefLoader(int base_path_id, Options options); | 43 // wait priority sync if DELAY_LOAD_UNTIL_PRIORITY_SYNC set. |
| 44 ExternalPrefLoader(int base_path_id, Options options, Profile* profile); |
| 37 | 45 |
| 38 const base::FilePath GetBaseCrxFilePath() override; | 46 const base::FilePath GetBaseCrxFilePath() override; |
| 39 | 47 |
| 40 protected: | 48 protected: |
| 41 ~ExternalPrefLoader() override {} | 49 ~ExternalPrefLoader() override; |
| 42 | 50 |
| 43 void StartLoading() override; | 51 void StartLoading() override; |
| 44 bool IsOptionSet(Options option) { | 52 bool IsOptionSet(Options option) { |
| 45 return (options_ & option) != 0; | 53 return (options_ & option) != 0; |
| 46 } | 54 } |
| 47 | 55 |
| 48 // The resource id of the base path with the information about the json | 56 // The resource id of the base path with the information about the json |
| 49 // file containing which extensions to load. | 57 // file containing which extensions to load. |
| 50 const int base_path_id_; | 58 const int base_path_id_; |
| 51 | 59 |
| 52 const Options options_; | 60 const Options options_; |
| 53 | 61 |
| 54 private: | 62 private: |
| 55 friend class base::RefCountedThreadSafe<ExternalLoader>; | 63 friend class base::RefCountedThreadSafe<ExternalLoader>; |
| 56 | 64 |
| 65 // PrefServiceSyncableObserver: |
| 66 void OnIsSyncingChanged() override; |
| 67 |
| 68 // If priority sync ready posts LoadOnFileThread and return true. |
| 69 bool PostLoadIfPrioritySyncReady(); |
| 70 |
| 57 // Actually searches for and loads candidate standalone extension preference | 71 // Actually searches for and loads candidate standalone extension preference |
| 58 // files in the path corresponding to |base_path_id|. | 72 // files in the path corresponding to |base_path_id|. |
| 59 // Must be called on the file thread. | 73 // Must be called on the file thread. |
| 60 void LoadOnFileThread(); | 74 void LoadOnFileThread(); |
| 61 | 75 |
| 62 // Extracts the information contained in an external_extension.json file | 76 // Extracts the information contained in an external_extension.json file |
| 63 // regarding which extensions to install. |prefs| will be modified to | 77 // regarding which extensions to install. |prefs| will be modified to |
| 64 // receive the extracted extension information. | 78 // receive the extracted extension information. |
| 65 // Must be called from the File thread. | 79 // Must be called from the File thread. |
| 66 void ReadExternalExtensionPrefFile(base::DictionaryValue* prefs); | 80 void ReadExternalExtensionPrefFile(base::DictionaryValue* prefs); |
| 67 | 81 |
| 68 // Extracts the information contained in standalone external extension | 82 // Extracts the information contained in standalone external extension |
| 69 // json files (<extension id>.json) regarding what external extensions | 83 // json files (<extension id>.json) regarding what external extensions |
| 70 // to install. |prefs| will be modified to receive the extracted extension | 84 // to install. |prefs| will be modified to receive the extracted extension |
| 71 // information. | 85 // information. |
| 72 // Must be called from the File thread. | 86 // Must be called from the File thread. |
| 73 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs); | 87 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs); |
| 74 | 88 |
| 75 // The path (coresponding to |base_path_id_| containing the json files | 89 // The path (coresponding to |base_path_id_| containing the json files |
| 76 // describing which extensions to load. | 90 // describing which extensions to load. |
| 77 base::FilePath base_path_; | 91 base::FilePath base_path_; |
| 78 | 92 |
| 93 // Profile that loads these external prefs. |
| 94 // Needed for waiting for waiting priority sync. |
| 95 Profile* profile_; |
| 96 |
| 97 // True if this was added as observer for PrefServiceSyncable. |
| 98 bool pref_observer_added_; |
| 99 |
| 79 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader); | 100 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader); |
| 80 }; | 101 }; |
| 81 | 102 |
| 82 // A simplified version of ExternalPrefLoader that loads the dictionary | 103 // A simplified version of ExternalPrefLoader that loads the dictionary |
| 83 // from json data specified in a string. | 104 // from json data specified in a string. |
| 84 class ExternalTestingLoader : public ExternalLoader { | 105 class ExternalTestingLoader : public ExternalLoader { |
| 85 public: | 106 public: |
| 86 ExternalTestingLoader(const std::string& json_data, | 107 ExternalTestingLoader(const std::string& json_data, |
| 87 const base::FilePath& fake_base_path); | 108 const base::FilePath& fake_base_path); |
| 88 | 109 |
| 89 const base::FilePath GetBaseCrxFilePath() override; | 110 const base::FilePath GetBaseCrxFilePath() override; |
| 90 | 111 |
| 91 protected: | 112 protected: |
| 92 void StartLoading() override; | 113 void StartLoading() override; |
| 93 | 114 |
| 94 private: | 115 private: |
| 95 friend class base::RefCountedThreadSafe<ExternalLoader>; | 116 friend class base::RefCountedThreadSafe<ExternalLoader>; |
| 96 | 117 |
| 97 ~ExternalTestingLoader() override; | 118 ~ExternalTestingLoader() override; |
| 98 | 119 |
| 99 base::FilePath fake_base_path_; | 120 base::FilePath fake_base_path_; |
| 100 scoped_ptr<base::DictionaryValue> testing_prefs_; | 121 scoped_ptr<base::DictionaryValue> testing_prefs_; |
| 101 | 122 |
| 102 DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader); | 123 DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader); |
| 103 }; | 124 }; |
| 104 | 125 |
| 105 } // namespace extensions | 126 } // namespace extensions |
| 106 | 127 |
| 107 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ | 128 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ |
| OLD | NEW |