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_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 namespace user_prefs { | 36 namespace user_prefs { |
37 class PrefRegistrySyncable; | 37 class PrefRegistrySyncable; |
38 } | 38 } |
39 | 39 |
40 // This test is in global namespace so it must be declared here. | 40 // This test is in global namespace so it must be declared here. |
41 void Test__InitStartupCustomizationDocument(const std::string& manifest); | 41 void Test__InitStartupCustomizationDocument(const std::string& manifest); |
42 | 42 |
43 namespace chromeos { | 43 namespace chromeos { |
44 | 44 |
45 class CustomizationWallpaperDownloader; | |
45 class ServicesCustomizationExternalLoader; | 46 class ServicesCustomizationExternalLoader; |
46 | 47 |
47 namespace system { | 48 namespace system { |
48 class StatisticsProvider; | 49 class StatisticsProvider; |
49 } // system | 50 } // system |
50 | 51 |
51 // Base class for OEM customization document classes. | 52 // Base class for OEM customization document classes. |
52 class CustomizationDocument { | 53 class CustomizationDocument { |
53 public: | 54 public: |
54 virtual ~CustomizationDocument(); | 55 virtual ~CustomizationDocument(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 std::vector<std::string> configured_locales_; | 129 std::vector<std::string> configured_locales_; |
129 std::string initial_timezone_; | 130 std::string initial_timezone_; |
130 std::string keyboard_layout_; | 131 std::string keyboard_layout_; |
131 | 132 |
132 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument); | 133 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument); |
133 }; | 134 }; |
134 | 135 |
135 // OEM services customization document class. | 136 // OEM services customization document class. |
136 // ServicesCustomizationDocument is fetched from network therefore it is not | 137 // ServicesCustomizationDocument is fetched from network therefore it is not |
137 // ready just after creation. Fetching of the manifest should be initiated | 138 // ready just after creation. Fetching of the manifest should be initiated |
138 // outside this class by calling StartFetching() method. | 139 // outside this class by calling StartFetching() or EnsureCustomizationApplied() |
140 // methods. | |
139 // User of the file should check IsReady before use it. | 141 // User of the file should check IsReady before use it. |
140 class ServicesCustomizationDocument : public CustomizationDocument, | 142 class ServicesCustomizationDocument : public CustomizationDocument, |
141 private net::URLFetcherDelegate { | 143 private net::URLFetcherDelegate { |
142 public: | 144 public: |
143 static ServicesCustomizationDocument* GetInstance(); | 145 static ServicesCustomizationDocument* GetInstance(); |
144 | 146 |
145 // Registers preferences. | 147 // Registers preferences. |
146 static void RegisterPrefs(PrefRegistrySimple* registry); | 148 static void RegisterPrefs(PrefRegistrySimple* registry); |
147 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 149 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
148 | 150 |
149 static const char kManifestUrl[]; | 151 static const char kManifestUrl[]; |
150 | 152 |
151 // Return true if the customization was applied. Customization is applied only | 153 // Return true if the customization was applied. Customization is applied only |
152 // once per machine. | 154 // once per machine. |
153 static bool WasOOBECustomizationApplied(); | 155 static bool WasOOBECustomizationApplied(); |
154 | 156 |
157 // If customization has not been applied, start fetching and applying. | |
158 void EnsureCustomizationApplied(); | |
159 | |
160 // Returns Closure with the EnsureCustomizationApplied() method. | |
161 base::Closure EnsureCustomizationAppliedClosure(); | |
162 | |
155 // Start fetching customization document. | 163 // Start fetching customization document. |
156 void StartFetching(); | 164 void StartFetching(); |
157 | 165 |
158 // Apply customization and save in machine options that customization was | 166 // Apply customization and save in machine options that customization was |
159 // applied successfully. Return true if customization was applied. | 167 // applied successfully. Return true if customization was applied. |
160 bool ApplyOOBECustomization(); | 168 bool ApplyOOBECustomization(); |
161 | 169 |
162 // Returns default wallpaper URL. | 170 // Returns true if default wallpaper URL attribute found in manifest. |
163 GURL GetDefaultWallpaperUrl() const; | 171 // "out_url" is set to attribute value. |
Daniel Erat
2014/04/19 14:24:08
nit: s/"out_url"/|out_url|/
Alexander Alekseev
2014/04/21 16:49:41
Done.
| |
172 bool GetDefaultWallpaperUrl(GURL* out_url) const; | |
164 | 173 |
165 // Returns list of default apps. | 174 // Returns list of default apps. |
166 bool GetDefaultApps(std::vector<std::string>* ids) const; | 175 bool GetDefaultApps(std::vector<std::string>* ids) const; |
167 | 176 |
168 // Creates an extensions::ExternalLoader that will provide OEM default apps. | 177 // Creates an extensions::ExternalLoader that will provide OEM default apps. |
169 // Cache of OEM default apps stored in profile preferences. | 178 // Cache of OEM default apps stored in profile preferences. |
170 extensions::ExternalLoader* CreateExternalLoader(Profile* profile); | 179 extensions::ExternalLoader* CreateExternalLoader(Profile* profile); |
171 | 180 |
172 // Returns the name of the folder for OEM apps for given |locale|. | 181 // Returns the name of the folder for OEM apps for given |locale|. |
173 std::string GetOemAppsFolderName(const std::string& locale) const; | 182 std::string GetOemAppsFolderName(const std::string& locale) const; |
174 | 183 |
175 // Initialize instance of ServicesCustomizationDocument for tests that will | 184 // Initialize instance of ServicesCustomizationDocument for tests that will |
176 // override singleton until ShutdownForTesting is called. | 185 // override singleton until ShutdownForTesting is called. |
177 static void InitializeForTesting(); | 186 static void InitializeForTesting(); |
178 | 187 |
179 // Remove instance of ServicesCustomizationDocument for tests. | 188 // Remove instance of ServicesCustomizationDocument for tests. |
180 static void ShutdownForTesting(); | 189 static void ShutdownForTesting(); |
181 | 190 |
191 // These methods are also called by WallpaperManager to get "global default" | |
192 // customized wallpaper path (and to init default wallpaper path from it) | |
193 // before first wallpaper is shown. | |
194 static base::FilePath GetCustomizedWallpaperCacheDir(); | |
195 static base::FilePath GetCustomizedWallpaperDownloadedFileName(); | |
196 | |
182 private: | 197 private: |
183 friend struct DefaultSingletonTraits<ServicesCustomizationDocument>; | 198 friend struct DefaultSingletonTraits<ServicesCustomizationDocument>; |
184 | 199 |
185 typedef std::vector<base::WeakPtr<ServicesCustomizationExternalLoader> > | 200 typedef std::vector<base::WeakPtr<ServicesCustomizationExternalLoader> > |
186 ExternalLoaders; | 201 ExternalLoaders; |
187 | 202 |
203 // Guard for a single application task (wallpaper downloading, for example). | |
204 class ApplyingTask; | |
205 | |
188 // C-tor for singleton construction. | 206 // C-tor for singleton construction. |
189 ServicesCustomizationDocument(); | 207 ServicesCustomizationDocument(); |
190 | 208 |
191 // C-tor for test construction. | 209 // C-tor for test construction. |
192 explicit ServicesCustomizationDocument(const std::string& manifest); | 210 explicit ServicesCustomizationDocument(const std::string& manifest); |
193 | 211 |
194 virtual ~ServicesCustomizationDocument(); | 212 virtual ~ServicesCustomizationDocument(); |
195 | 213 |
196 // Save applied state in machine settings. | 214 // Save applied state in machine settings. |
197 static void SetApplied(bool val); | 215 static void SetApplied(bool val); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 void OnCustomizationNotFound(); | 248 void OnCustomizationNotFound(); |
231 | 249 |
232 // Set OEM apps folder name for AppListSyncableService for |profile|. | 250 // Set OEM apps folder name for AppListSyncableService for |profile|. |
233 void SetOemFolderName(Profile* profile, const base::DictionaryValue& root); | 251 void SetOemFolderName(Profile* profile, const base::DictionaryValue& root); |
234 | 252 |
235 // Returns the name of the folder for OEM apps for given |locale|. | 253 // Returns the name of the folder for OEM apps for given |locale|. |
236 std::string GetOemAppsFolderNameImpl( | 254 std::string GetOemAppsFolderNameImpl( |
237 const std::string& locale, | 255 const std::string& locale, |
238 const base::DictionaryValue& root) const; | 256 const base::DictionaryValue& root) const; |
239 | 257 |
258 // Start download of wallpaper image if needed. | |
259 void StartOEMWallpaperDownload(const GURL& wallpaper_url, | |
260 scoped_ptr<ApplyingTask> applying); | |
261 | |
262 // Check that current customized wallpaper cache exists. Once wallpaper is | |
263 // downloaded, it's never updated (even if manifest is re-fetched). | |
264 // Start wallpaper download if needed. | |
265 void CheckAndApplyWallpaper(); | |
266 | |
267 // Intermediate function to pass the result of PathExists to ApplyWallpaper. | |
268 void OnCheckedWallpaperCacheExists(scoped_ptr<bool> exists, | |
269 scoped_ptr<ApplyingTask> applying); | |
270 | |
271 // Called after downloaded wallpaper has been checked. | |
272 void ApplyWallpaper(bool default_wallpaper_file_exists, | |
273 scoped_ptr<ApplyingTask> applying); | |
274 | |
275 // Set Shell default wallpaper to customized. | |
276 // It's wrapped as a callback and passed as a parameter to | |
277 // CustomizationWallpaperDownloader. | |
278 void OnOEMWallpaperDownloaded(scoped_ptr<ApplyingTask> applying, | |
279 bool success, | |
280 const GURL& wallpaper_url); | |
281 | |
282 // Register one of Customization applying tasks. | |
283 void ApplyingTaskStarted(); | |
284 | |
285 // Mark task finished and check for "all customization applied". | |
286 void ApplyingTaskFinished(bool success); | |
287 | |
240 // Services customization manifest URL. | 288 // Services customization manifest URL. |
241 GURL url_; | 289 GURL url_; |
242 | 290 |
243 // URLFetcher instance. | 291 // URLFetcher instance. |
244 scoped_ptr<net::URLFetcher> url_fetcher_; | 292 scoped_ptr<net::URLFetcher> url_fetcher_; |
245 | 293 |
246 // How many times we already tried to fetch customization manifest file. | 294 // How many times we already tried to fetch customization manifest file. |
247 int num_retries_; | 295 int num_retries_; |
248 | 296 |
249 // Manifest fetch is already in progress. | 297 // Manifest fetch is already in progress. |
250 bool fetch_started_; | 298 bool fetch_started_; |
251 | 299 |
252 // Delay between checks for network online state. | 300 // Delay between checks for network online state. |
253 base::TimeDelta network_delay_; | 301 base::TimeDelta network_delay_; |
254 | 302 |
255 // Known external loaders. | 303 // Known external loaders. |
256 ExternalLoaders external_loaders_; | 304 ExternalLoaders external_loaders_; |
257 | 305 |
306 scoped_ptr<CustomizationWallpaperDownloader> wallpaper_downloader_; | |
307 | |
308 // This is barrier until customization is applied. | |
309 // When number of finished tasks match number of started - customization is | |
310 // applied. | |
311 size_t apply_tasks_started_; | |
312 size_t apply_tasks_finished_; | |
313 | |
314 // This is the number of successfully finished customization tasks. | |
315 // If it matches number of tasks finished - customization is applied | |
316 // successfully. | |
317 size_t apply_tasks_success_; | |
318 | |
258 // Weak factory for callbacks. | 319 // Weak factory for callbacks. |
259 base::WeakPtrFactory<ServicesCustomizationDocument> weak_ptr_factory_; | 320 base::WeakPtrFactory<ServicesCustomizationDocument> weak_ptr_factory_; |
260 | 321 |
261 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); | 322 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); |
262 }; | 323 }; |
263 | 324 |
264 } // namespace chromeos | 325 } // namespace chromeos |
265 | 326 |
266 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ | 327 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ |
OLD | NEW |