| 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_CUSTOMIZATION_DOCUMENT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_CUSTOMIZATION_DOCUMENT_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_CUSTOMIZATION_DOCUMENT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_CUSTOMIZATION_DOCUMENT_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 20 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 class PrefRegistrySimple; | 23 class PrefRegistrySimple; |
| 24 class Profile; | 24 class Profile; |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 protected: | 62 protected: |
| 63 explicit CustomizationDocument(const std::string& accepted_version); | 63 explicit CustomizationDocument(const std::string& accepted_version); |
| 64 | 64 |
| 65 virtual bool LoadManifestFromFile(const base::FilePath& manifest_path); | 65 virtual bool LoadManifestFromFile(const base::FilePath& manifest_path); |
| 66 virtual bool LoadManifestFromString(const std::string& manifest); | 66 virtual bool LoadManifestFromString(const std::string& manifest); |
| 67 | 67 |
| 68 std::string GetLocaleSpecificString(const std::string& locale, | 68 std::string GetLocaleSpecificString(const std::string& locale, |
| 69 const std::string& dictionary_name, | 69 const std::string& dictionary_name, |
| 70 const std::string& entry_name) const; | 70 const std::string& entry_name) const; |
| 71 | 71 |
| 72 scoped_ptr<base::DictionaryValue> root_; | 72 std::unique_ptr<base::DictionaryValue> root_; |
| 73 | 73 |
| 74 // Value of the "version" attribute that is supported. | 74 // Value of the "version" attribute that is supported. |
| 75 // Otherwise config is not loaded. | 75 // Otherwise config is not loaded. |
| 76 std::string accepted_version_; | 76 std::string accepted_version_; |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); | 79 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // OEM startup customization document class. | 82 // OEM startup customization document class. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 // Apply customization and save in machine options that customization was | 168 // Apply customization and save in machine options that customization was |
| 169 // applied successfully. Return true if customization was applied. | 169 // applied successfully. Return true if customization was applied. |
| 170 bool ApplyOOBECustomization(); | 170 bool ApplyOOBECustomization(); |
| 171 | 171 |
| 172 // Returns true if default wallpaper URL attribute found in manifest. | 172 // Returns true if default wallpaper URL attribute found in manifest. |
| 173 // |out_url| is set to attribute value. | 173 // |out_url| is set to attribute value. |
| 174 bool GetDefaultWallpaperUrl(GURL* out_url) const; | 174 bool GetDefaultWallpaperUrl(GURL* out_url) const; |
| 175 | 175 |
| 176 // Returns list of default apps. | 176 // Returns list of default apps. |
| 177 scoped_ptr<base::DictionaryValue> GetDefaultApps() const; | 177 std::unique_ptr<base::DictionaryValue> GetDefaultApps() const; |
| 178 | 178 |
| 179 // Creates an extensions::ExternalLoader that will provide OEM default apps. | 179 // Creates an extensions::ExternalLoader that will provide OEM default apps. |
| 180 // Cache of OEM default apps stored in profile preferences. | 180 // Cache of OEM default apps stored in profile preferences. |
| 181 extensions::ExternalLoader* CreateExternalLoader(Profile* profile); | 181 extensions::ExternalLoader* CreateExternalLoader(Profile* profile); |
| 182 | 182 |
| 183 // Returns the name of the folder for OEM apps for given |locale|. | 183 // Returns the name of the folder for OEM apps for given |locale|. |
| 184 std::string GetOemAppsFolderName(const std::string& locale) const; | 184 std::string GetOemAppsFolderName(const std::string& locale) const; |
| 185 | 185 |
| 186 // Initialize instance of ServicesCustomizationDocument for tests that will | 186 // Initialize instance of ServicesCustomizationDocument for tests that will |
| 187 // override singleton until ShutdownForTesting is called. | 187 // override singleton until ShutdownForTesting is called. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 base::WeakPtr<ServicesCustomizationDocument> self, | 241 base::WeakPtr<ServicesCustomizationDocument> self, |
| 242 const base::FilePath& file); | 242 const base::FilePath& file); |
| 243 | 243 |
| 244 // Called on UI thread with results of ReadFileInBackground. | 244 // Called on UI thread with results of ReadFileInBackground. |
| 245 void OnManifesteRead(const std::string& manifest); | 245 void OnManifesteRead(const std::string& manifest); |
| 246 | 246 |
| 247 // Method called when manifest was successfully loaded. | 247 // Method called when manifest was successfully loaded. |
| 248 void OnManifestLoaded(); | 248 void OnManifestLoaded(); |
| 249 | 249 |
| 250 // Returns list of default apps in ExternalProvider format. | 250 // Returns list of default apps in ExternalProvider format. |
| 251 static scoped_ptr<base::DictionaryValue> GetDefaultAppsInProviderFormat( | 251 static std::unique_ptr<base::DictionaryValue> GetDefaultAppsInProviderFormat( |
| 252 const base::DictionaryValue& root); | 252 const base::DictionaryValue& root); |
| 253 | 253 |
| 254 // Update cached manifest for |profile|. | 254 // Update cached manifest for |profile|. |
| 255 void UpdateCachedManifest(Profile* profile); | 255 void UpdateCachedManifest(Profile* profile); |
| 256 | 256 |
| 257 // Customization document not found for give ID. | 257 // Customization document not found for give ID. |
| 258 void OnCustomizationNotFound(); | 258 void OnCustomizationNotFound(); |
| 259 | 259 |
| 260 // Set OEM apps folder name for AppListSyncableService for |profile|. | 260 // Set OEM apps folder name for AppListSyncableService for |profile|. |
| 261 void SetOemFolderName(Profile* profile, const base::DictionaryValue& root); | 261 void SetOemFolderName(Profile* profile, const base::DictionaryValue& root); |
| 262 | 262 |
| 263 // Returns the name of the folder for OEM apps for given |locale|. | 263 // Returns the name of the folder for OEM apps for given |locale|. |
| 264 std::string GetOemAppsFolderNameImpl( | 264 std::string GetOemAppsFolderNameImpl( |
| 265 const std::string& locale, | 265 const std::string& locale, |
| 266 const base::DictionaryValue& root) const; | 266 const base::DictionaryValue& root) const; |
| 267 | 267 |
| 268 // Start download of wallpaper image if needed. | 268 // Start download of wallpaper image if needed. |
| 269 void StartOEMWallpaperDownload(const GURL& wallpaper_url, | 269 void StartOEMWallpaperDownload(const GURL& wallpaper_url, |
| 270 scoped_ptr<ApplyingTask> applying); | 270 std::unique_ptr<ApplyingTask> applying); |
| 271 | 271 |
| 272 // Check that current customized wallpaper cache exists. Once wallpaper is | 272 // Check that current customized wallpaper cache exists. Once wallpaper is |
| 273 // downloaded, it's never updated (even if manifest is re-fetched). | 273 // downloaded, it's never updated (even if manifest is re-fetched). |
| 274 // Start wallpaper download if needed. | 274 // Start wallpaper download if needed. |
| 275 void CheckAndApplyWallpaper(); | 275 void CheckAndApplyWallpaper(); |
| 276 | 276 |
| 277 // Intermediate function to pass the result of PathExists to ApplyWallpaper. | 277 // Intermediate function to pass the result of PathExists to ApplyWallpaper. |
| 278 void OnCheckedWallpaperCacheExists(scoped_ptr<bool> exists, | 278 void OnCheckedWallpaperCacheExists(std::unique_ptr<bool> exists, |
| 279 scoped_ptr<ApplyingTask> applying); | 279 std::unique_ptr<ApplyingTask> applying); |
| 280 | 280 |
| 281 // Called after downloaded wallpaper has been checked. | 281 // Called after downloaded wallpaper has been checked. |
| 282 void ApplyWallpaper(bool default_wallpaper_file_exists, | 282 void ApplyWallpaper(bool default_wallpaper_file_exists, |
| 283 scoped_ptr<ApplyingTask> applying); | 283 std::unique_ptr<ApplyingTask> applying); |
| 284 | 284 |
| 285 // Set Shell default wallpaper to customized. | 285 // Set Shell default wallpaper to customized. |
| 286 // It's wrapped as a callback and passed as a parameter to | 286 // It's wrapped as a callback and passed as a parameter to |
| 287 // CustomizationWallpaperDownloader. | 287 // CustomizationWallpaperDownloader. |
| 288 void OnOEMWallpaperDownloaded(scoped_ptr<ApplyingTask> applying, | 288 void OnOEMWallpaperDownloaded(std::unique_ptr<ApplyingTask> applying, |
| 289 bool success, | 289 bool success, |
| 290 const GURL& wallpaper_url); | 290 const GURL& wallpaper_url); |
| 291 | 291 |
| 292 // Register one of Customization applying tasks. | 292 // Register one of Customization applying tasks. |
| 293 void ApplyingTaskStarted(); | 293 void ApplyingTaskStarted(); |
| 294 | 294 |
| 295 // Mark task finished and check for "all customization applied". | 295 // Mark task finished and check for "all customization applied". |
| 296 void ApplyingTaskFinished(bool success); | 296 void ApplyingTaskFinished(bool success); |
| 297 | 297 |
| 298 // Services customization manifest URL. | 298 // Services customization manifest URL. |
| 299 GURL url_; | 299 GURL url_; |
| 300 | 300 |
| 301 // URLFetcher instance. | 301 // URLFetcher instance. |
| 302 scoped_ptr<net::URLFetcher> url_fetcher_; | 302 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 303 | 303 |
| 304 // How many times we already tried to fetch customization manifest file. | 304 // How many times we already tried to fetch customization manifest file. |
| 305 int num_retries_; | 305 int num_retries_; |
| 306 | 306 |
| 307 // Manifest fetch is already in progress. | 307 // Manifest fetch is already in progress. |
| 308 bool fetch_started_; | 308 bool fetch_started_; |
| 309 | 309 |
| 310 // Delay between checks for network online state. | 310 // Delay between checks for network online state. |
| 311 base::TimeDelta network_delay_; | 311 base::TimeDelta network_delay_; |
| 312 | 312 |
| 313 // Known external loaders. | 313 // Known external loaders. |
| 314 ExternalLoaders external_loaders_; | 314 ExternalLoaders external_loaders_; |
| 315 | 315 |
| 316 scoped_ptr<CustomizationWallpaperDownloader> wallpaper_downloader_; | 316 std::unique_ptr<CustomizationWallpaperDownloader> wallpaper_downloader_; |
| 317 | 317 |
| 318 // This is barrier until customization is applied. | 318 // This is barrier until customization is applied. |
| 319 // When number of finished tasks match number of started - customization is | 319 // When number of finished tasks match number of started - customization is |
| 320 // applied. | 320 // applied. |
| 321 size_t apply_tasks_started_; | 321 size_t apply_tasks_started_; |
| 322 size_t apply_tasks_finished_; | 322 size_t apply_tasks_finished_; |
| 323 | 323 |
| 324 // This is the number of successfully finished customization tasks. | 324 // This is the number of successfully finished customization tasks. |
| 325 // If it matches number of tasks finished - customization is applied | 325 // If it matches number of tasks finished - customization is applied |
| 326 // successfully. | 326 // successfully. |
| 327 size_t apply_tasks_success_; | 327 size_t apply_tasks_success_; |
| 328 | 328 |
| 329 // Weak factory for callbacks. | 329 // Weak factory for callbacks. |
| 330 base::WeakPtrFactory<ServicesCustomizationDocument> weak_ptr_factory_; | 330 base::WeakPtrFactory<ServicesCustomizationDocument> weak_ptr_factory_; |
| 331 | 331 |
| 332 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); | 332 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); |
| 333 }; | 333 }; |
| 334 | 334 |
| 335 } // namespace chromeos | 335 } // namespace chromeos |
| 336 | 336 |
| 337 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_CUSTOMIZATION_DOCUMENT_H_ | 337 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_CUSTOMIZATION_DOCUMENT_H_ |
| OLD | NEW |