Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: chrome/browser/extensions/external_pref_loader.h

Issue 650763003: Delay default apps installation on Chrome OS for first time sign-in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use ScopedObserver Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/external_pref_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
12 #include "base/scoped_observer.h"
14 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/external_loader.h"
15 #include "chrome/browser/prefs/pref_service_syncable_observer.h"
16
17 class PrefServiceSyncable;
18 class Profile;
15 19
16 namespace extensions { 20 namespace extensions {
17 21
18 // A specialization of the ExternalLoader that uses a json file to 22 // A specialization of the ExternalLoader that uses a json file to
19 // look up which external extensions are registered. 23 // look up which external extensions are registered.
20 // Instances of this class are expected to be created and destroyed on the UI 24 // 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. 25 // thread and they are expecting public method calls from the UI thread.
22 class ExternalPrefLoader : public ExternalLoader { 26 class ExternalPrefLoader : public ExternalLoader,
27 public PrefServiceSyncableObserver {
23 public: 28 public:
24 enum Options { 29 enum Options {
25 NONE = 0, 30 NONE = 0,
26 31
27 // Ensure that only root can force an external install by checking 32 // Ensure that only root can force an external install by checking
28 // that all components of the path to external extensions files are 33 // that all components of the path to external extensions files are
29 // owned by root and not writable by any non-root user. 34 // owned by root and not writable by any non-root user.
30 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0 35 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0,
36
37 // Delay external preference load. It delays default apps installation
38 // to not overload the system on first time user login.
39 DELAY_LOAD_UNTIL_PRIORITY_SYNC = 1 << 1,
31 }; 40 };
32 41
33 // |base_path_id| is the directory containing the external_extensions.json 42 // |base_path_id| is the directory containing the external_extensions.json
34 // file or the standalone extension manifest files. Relative file paths to 43 // file or the standalone extension manifest files. Relative file paths to
35 // extension files are resolved relative to this path. 44 // extension files are resolved relative to this path. |profile| is used to
36 ExternalPrefLoader(int base_path_id, Options options); 45 // wait priority sync if DELAY_LOAD_UNTIL_PRIORITY_SYNC set.
46 ExternalPrefLoader(int base_path_id, Options options, Profile* profile);
37 47
38 const base::FilePath GetBaseCrxFilePath() override; 48 const base::FilePath GetBaseCrxFilePath() override;
39 49
40 protected: 50 protected:
41 ~ExternalPrefLoader() override {} 51 ~ExternalPrefLoader() override;
42 52
43 void StartLoading() override; 53 void StartLoading() override;
44 bool IsOptionSet(Options option) { 54 bool IsOptionSet(Options option) {
45 return (options_ & option) != 0; 55 return (options_ & option) != 0;
46 } 56 }
47 57
48 // The resource id of the base path with the information about the json 58 // The resource id of the base path with the information about the json
49 // file containing which extensions to load. 59 // file containing which extensions to load.
50 const int base_path_id_; 60 const int base_path_id_;
51 61
52 const Options options_; 62 const Options options_;
53 63
54 private: 64 private:
55 friend class base::RefCountedThreadSafe<ExternalLoader>; 65 friend class base::RefCountedThreadSafe<ExternalLoader>;
56 66
67 // PrefServiceSyncableObserver:
68 void OnIsSyncingChanged() override;
69
70 // If priority sync ready posts LoadOnFileThread and return true.
71 bool PostLoadIfPrioritySyncReady();
72
57 // Actually searches for and loads candidate standalone extension preference 73 // Actually searches for and loads candidate standalone extension preference
58 // files in the path corresponding to |base_path_id|. 74 // files in the path corresponding to |base_path_id|.
59 // Must be called on the file thread. 75 // Must be called on the file thread.
60 void LoadOnFileThread(); 76 void LoadOnFileThread();
61 77
62 // Extracts the information contained in an external_extension.json file 78 // Extracts the information contained in an external_extension.json file
63 // regarding which extensions to install. |prefs| will be modified to 79 // regarding which extensions to install. |prefs| will be modified to
64 // receive the extracted extension information. 80 // receive the extracted extension information.
65 // Must be called from the File thread. 81 // Must be called from the File thread.
66 void ReadExternalExtensionPrefFile(base::DictionaryValue* prefs); 82 void ReadExternalExtensionPrefFile(base::DictionaryValue* prefs);
67 83
68 // Extracts the information contained in standalone external extension 84 // Extracts the information contained in standalone external extension
69 // json files (<extension id>.json) regarding what external extensions 85 // json files (<extension id>.json) regarding what external extensions
70 // to install. |prefs| will be modified to receive the extracted extension 86 // to install. |prefs| will be modified to receive the extracted extension
71 // information. 87 // information.
72 // Must be called from the File thread. 88 // Must be called from the File thread.
73 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs); 89 void ReadStandaloneExtensionPrefFiles(base::DictionaryValue* prefs);
74 90
75 // The path (coresponding to |base_path_id_| containing the json files 91 // The path (coresponding to |base_path_id_| containing the json files
76 // describing which extensions to load. 92 // describing which extensions to load.
77 base::FilePath base_path_; 93 base::FilePath base_path_;
78 94
95 // Profile that loads these external prefs.
96 // Needed for waiting for waiting priority sync.
97 Profile* profile_;
98
99 // Used for registering observer for PrefServiceSyncable.
100 ScopedObserver<PrefServiceSyncable, PrefServiceSyncableObserver>
101 syncable_pref_observer_;
102
79 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader); 103 DISALLOW_COPY_AND_ASSIGN(ExternalPrefLoader);
80 }; 104 };
81 105
82 // A simplified version of ExternalPrefLoader that loads the dictionary 106 // A simplified version of ExternalPrefLoader that loads the dictionary
83 // from json data specified in a string. 107 // from json data specified in a string.
84 class ExternalTestingLoader : public ExternalLoader { 108 class ExternalTestingLoader : public ExternalLoader {
85 public: 109 public:
86 ExternalTestingLoader(const std::string& json_data, 110 ExternalTestingLoader(const std::string& json_data,
87 const base::FilePath& fake_base_path); 111 const base::FilePath& fake_base_path);
88 112
89 const base::FilePath GetBaseCrxFilePath() override; 113 const base::FilePath GetBaseCrxFilePath() override;
90 114
91 protected: 115 protected:
92 void StartLoading() override; 116 void StartLoading() override;
93 117
94 private: 118 private:
95 friend class base::RefCountedThreadSafe<ExternalLoader>; 119 friend class base::RefCountedThreadSafe<ExternalLoader>;
96 120
97 ~ExternalTestingLoader() override; 121 ~ExternalTestingLoader() override;
98 122
99 base::FilePath fake_base_path_; 123 base::FilePath fake_base_path_;
100 scoped_ptr<base::DictionaryValue> testing_prefs_; 124 scoped_ptr<base::DictionaryValue> testing_prefs_;
101 125
102 DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader); 126 DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader);
103 }; 127 };
104 128
105 } // namespace extensions 129 } // namespace extensions
106 130
107 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_ 131 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/external_pref_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698