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

Side by Side Diff: chrome/browser/chromeos/customization_document.cc

Issue 236013002: Apply default wallpaper from customization manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved call to EnsureCustomizationAppliedClosure() to a better place. Created 6 years, 8 months 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
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 #include "chrome/browser/chromeos/customization_document.h" 5 #include "chrome/browser/chromeos/customization_document.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/path_service.h"
17 #include "base/prefs/pref_registry_simple.h" 18 #include "base/prefs/pref_registry_simple.h"
18 #include "base/prefs/pref_service.h" 19 #include "base/prefs/pref_service.h"
19 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chromeos/customization_wallpaper_downloader.h"
25 #include "chrome/browser/chromeos/extensions/default_app_order.h" 27 #include "chrome/browser/chromeos/extensions/default_app_order.h"
28 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
26 #include "chrome/browser/chromeos/login/wizard_controller.h" 29 #include "chrome/browser/chromeos/login/wizard_controller.h"
27 #include "chrome/browser/chromeos/net/delay_network_call.h" 30 #include "chrome/browser/chromeos/net/delay_network_call.h"
28 #include "chrome/browser/extensions/external_loader.h" 31 #include "chrome/browser/extensions/external_loader.h"
29 #include "chrome/browser/extensions/external_provider_impl.h" 32 #include "chrome/browser/extensions/external_provider_impl.h"
30 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" 34 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
32 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" 35 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
36 #include "chrome/common/chrome_paths.h"
33 #include "chrome/common/extensions/extension_constants.h" 37 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/common/pref_names.h"
34 #include "chromeos/network/network_state.h" 39 #include "chromeos/network/network_state.h"
35 #include "chromeos/network/network_state_handler.h" 40 #include "chromeos/network/network_state_handler.h"
36 #include "chromeos/system/statistics_provider.h" 41 #include "chromeos/system/statistics_provider.h"
37 #include "components/user_prefs/pref_registry_syncable.h" 42 #include "components/user_prefs/pref_registry_syncable.h"
38 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
39 #include "net/base/load_flags.h" 44 #include "net/base/load_flags.h"
40 #include "net/http/http_response_headers.h" 45 #include "net/http/http_response_headers.h"
41 #include "net/http/http_status_code.h" 46 #include "net/http/http_status_code.h"
42 #include "net/url_request/url_fetcher.h" 47 #include "net/url_request/url_fetcher.h"
43 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
(...skipping 17 matching lines...) Expand all
61 const char kDefaultAppsAttr[] = "default_apps"; 66 const char kDefaultAppsAttr[] = "default_apps";
62 const char kLocalizedContent[] = "localized_content"; 67 const char kLocalizedContent[] = "localized_content";
63 const char kDefaultAppsFolderName[] = "default_apps_folder_name"; 68 const char kDefaultAppsFolderName[] = "default_apps_folder_name";
64 69
65 const char kAcceptedManifestVersion[] = "1.0"; 70 const char kAcceptedManifestVersion[] = "1.0";
66 71
67 // Path to OEM partner startup customization manifest. 72 // Path to OEM partner startup customization manifest.
68 const char kStartupCustomizationManifestPath[] = 73 const char kStartupCustomizationManifestPath[] =
69 "/opt/oem/etc/startup_manifest.json"; 74 "/opt/oem/etc/startup_manifest.json";
70 75
76 // This is subdirectory relative to PathService(DIR_CHROMEOS_CUSTOM_WALLPAPERS),
77 // where downloaded (and resized) wallpaper is stored.
78 const char kCustomizationDefaultWallpaperDir[] = "customization";
79
80 // The original downloaded image file is stored under this name.
81 const char kCustomizationDefaultWallpaperDownloadedFile[] =
82 "default_downloaded_wallpaper.bin";
83
71 // Name of local state option that tracks if services customization has been 84 // Name of local state option that tracks if services customization has been
72 // applied. 85 // applied.
73 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied"; 86 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied";
74 87
75 // Maximum number of retries to fetch file if network is not available. 88 // Maximum number of retries to fetch file if network is not available.
76 const int kMaxFetchRetries = 3; 89 const int kMaxFetchRetries = 3;
77 90
78 // Delay between file fetch retries if network is not available. 91 // Delay between file fetch retries if network is not available.
79 const int kRetriesDelayInSec = 2; 92 const int kRetriesDelayInSec = 2;
80 93
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 const base::DictionaryValue* default_dictionary = NULL; 136 const base::DictionaryValue* default_dictionary = NULL;
124 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { 137 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) {
125 std::string result; 138 std::string result;
126 if (default_dictionary->GetString(entry_name, &result)) 139 if (default_dictionary->GetString(entry_name, &result))
127 return result; 140 return result;
128 } 141 }
129 142
130 return std::string(); 143 return std::string();
131 } 144 }
132 145
146 void CheckWallpaperCacheExists(const base::FilePath& path, bool* exists) {
147 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
148 DCHECK(exists);
149 *exists = base::PathExists(path);
150 }
151
133 } // anonymous namespace 152 } // anonymous namespace
134 153
135 // Template URL where to fetch OEM services customization manifest from. 154 // Template URL where to fetch OEM services customization manifest from.
136 const char ServicesCustomizationDocument::kManifestUrl[] = 155 const char ServicesCustomizationDocument::kManifestUrl[] =
137 "https://ssl.gstatic.com/chrome/chromeos-customization/%s.json"; 156 "https://ssl.gstatic.com/chrome/chromeos-customization/%s.json";
138 157
139 // A custom extensions::ExternalLoader that the ServicesCustomizationDocument 158 // A custom extensions::ExternalLoader that the ServicesCustomizationDocument
140 // creates and uses to publish OEM default apps to the extensions system. 159 // creates and uses to publish OEM default apps to the extensions system.
141 class ServicesCustomizationExternalLoader 160 class ServicesCustomizationExternalLoader
142 : public extensions::ExternalLoader, 161 : public extensions::ExternalLoader,
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 return configured_locales_.front(); 349 return configured_locales_.front();
331 } 350 }
332 351
333 std::string StartupCustomizationDocument::GetEULAPage( 352 std::string StartupCustomizationDocument::GetEULAPage(
334 const std::string& locale) const { 353 const std::string& locale) const {
335 return GetLocaleSpecificString(locale, kSetupContentAttr, kEulaPageAttr); 354 return GetLocaleSpecificString(locale, kSetupContentAttr, kEulaPageAttr);
336 } 355 }
337 356
338 // ServicesCustomizationDocument implementation. ------------------------------- 357 // ServicesCustomizationDocument implementation. -------------------------------
339 358
359 class ServicesCustomizationDocument::ApplyingTask {
360 public:
361 // Registers in ServicesCustomizationDocument;
362 ApplyingTask(ServicesCustomizationDocument* document);
Daniel Erat 2014/04/17 16:24:22 add explicit here
Alexander Alekseev 2014/04/17 20:02:56 Done.
363
364 // Do not automatically deregister as we might be called on invalid thread.
365 ~ApplyingTask();
366
367 // Mark task finished and check for customization applied.
368 void Finished(bool success);
369
370 private:
371 ServicesCustomizationDocument* document_;
372
373 // This is error-checking flag to prevent destroying unfinished task
374 // or double finish.
375 bool engaged_;
376 };
377
378 ServicesCustomizationDocument::ApplyingTask::ApplyingTask(
379 ServicesCustomizationDocument* document)
380 : document_(document), engaged_(true) {
381 document->ApplyingTaskStarted();
382 }
383
384 ServicesCustomizationDocument::ApplyingTask::~ApplyingTask() {
385 DCHECK(!engaged_);
386 }
387
388 void ServicesCustomizationDocument::ApplyingTask::Finished(bool success) {
389 DCHECK(engaged_);
390 if (engaged_) {
391 engaged_ = false;
392 document_->ApplyingTaskFinished(success);
393 }
394 }
395
340 ServicesCustomizationDocument::ServicesCustomizationDocument() 396 ServicesCustomizationDocument::ServicesCustomizationDocument()
341 : CustomizationDocument(kAcceptedManifestVersion), 397 : CustomizationDocument(kAcceptedManifestVersion),
342 num_retries_(0), 398 num_retries_(0),
343 fetch_started_(false), 399 fetch_started_(false),
344 network_delay_(base::TimeDelta::FromMilliseconds( 400 network_delay_(
345 kDefaultNetworkRetryDelayMS)), 401 base::TimeDelta::FromMilliseconds(kDefaultNetworkRetryDelayMS)),
402 apply_tasks_started_(0),
403 apply_tasks_finished_(0),
404 apply_tasks_success_(0),
346 weak_ptr_factory_(this) { 405 weak_ptr_factory_(this) {
347 } 406 }
348 407
349 ServicesCustomizationDocument::ServicesCustomizationDocument( 408 ServicesCustomizationDocument::ServicesCustomizationDocument(
350 const std::string& manifest) 409 const std::string& manifest)
351 : CustomizationDocument(kAcceptedManifestVersion), 410 : CustomizationDocument(kAcceptedManifestVersion),
352 network_delay_(base::TimeDelta::FromMilliseconds( 411 network_delay_(
353 kDefaultNetworkRetryDelayMS)), 412 base::TimeDelta::FromMilliseconds(kDefaultNetworkRetryDelayMS)),
413 apply_tasks_started_(0),
414 apply_tasks_finished_(0),
415 apply_tasks_success_(0),
354 weak_ptr_factory_(this) { 416 weak_ptr_factory_(this) {
355 LoadManifestFromString(manifest); 417 LoadManifestFromString(manifest);
356 } 418 }
357 419
358 ServicesCustomizationDocument::~ServicesCustomizationDocument() {} 420 ServicesCustomizationDocument::~ServicesCustomizationDocument() {}
359 421
360 // static 422 // static
361 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() { 423 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() {
362 if (g_test_services_customization_document) 424 if (g_test_services_customization_document)
363 return g_test_services_customization_document; 425 return g_test_services_customization_document;
364 426
365 return Singleton<ServicesCustomizationDocument, 427 return Singleton<ServicesCustomizationDocument,
366 DefaultSingletonTraits<ServicesCustomizationDocument> >::get(); 428 DefaultSingletonTraits<ServicesCustomizationDocument> >::get();
367 } 429 }
368 430
369 // static 431 // static
370 void ServicesCustomizationDocument::RegisterPrefs( 432 void ServicesCustomizationDocument::RegisterPrefs(
371 PrefRegistrySimple* registry) { 433 PrefRegistrySimple* registry) {
372 registry->RegisterBooleanPref(kServicesCustomizationAppliedPref, false); 434 registry->RegisterBooleanPref(kServicesCustomizationAppliedPref, false);
435 registry->RegisterStringPref(prefs::kCustomizationDefaultWallpaperURL,
436 std::string());
373 } 437 }
374 438
375 // static 439 // static
376 void ServicesCustomizationDocument::RegisterProfilePrefs( 440 void ServicesCustomizationDocument::RegisterProfilePrefs(
377 user_prefs::PrefRegistrySyncable* registry) { 441 user_prefs::PrefRegistrySyncable* registry) {
378 registry->RegisterDictionaryPref( 442 registry->RegisterDictionaryPref(
379 kServicesCustomizationKey, 443 kServicesCustomizationKey,
380 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 444 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
381 } 445 }
382 446
383 // static 447 // static
384 bool ServicesCustomizationDocument::WasOOBECustomizationApplied() { 448 bool ServicesCustomizationDocument::WasOOBECustomizationApplied() {
385 PrefService* prefs = g_browser_process->local_state(); 449 PrefService* prefs = g_browser_process->local_state();
386 return prefs->GetBoolean(kServicesCustomizationAppliedPref); 450 return prefs->GetBoolean(kServicesCustomizationAppliedPref);
387 } 451 }
388 452
389 // static 453 // static
390 void ServicesCustomizationDocument::SetApplied(bool val) { 454 void ServicesCustomizationDocument::SetApplied(bool val) {
391 PrefService* prefs = g_browser_process->local_state(); 455 PrefService* prefs = g_browser_process->local_state();
392 prefs->SetBoolean(kServicesCustomizationAppliedPref, val); 456 prefs->SetBoolean(kServicesCustomizationAppliedPref, val);
393 } 457 }
394 458
459 // static
460 base::FilePath ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir() {
461 base::FilePath custom_wallpaper_dir;
462 if (!PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS,
463 &custom_wallpaper_dir)) {
464 LOG(DFATAL) << "Unable to get custom wallpaper dir.";
465 return base::FilePath();
466 }
467 return custom_wallpaper_dir.Append(kCustomizationDefaultWallpaperDir);
468 }
469
470 // static
471 base::FilePath
472 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName() {
473 const base::FilePath dir = GetCustomizedWallpaperCacheDir();
474 if (dir.empty()) {
475 NOTREACHED();
476 return dir;
477 }
478 return dir.Append(kCustomizationDefaultWallpaperDownloadedFile);
479 }
480
481 void ServicesCustomizationDocument::EnsureCustomizationApplied() {
482 if (WasOOBECustomizationApplied())
483 return;
484
485 // When customization manifest is fetched, applying will start automatically.
486 if (IsReady())
487 return;
488
489 StartFetching();
490 }
491
492 base::Closure
493 ServicesCustomizationDocument::EnsureCustomizationAppliedClosure() {
494 return base::Bind(&ServicesCustomizationDocument::EnsureCustomizationApplied,
495 weak_ptr_factory_.GetWeakPtr());
496 }
497
395 void ServicesCustomizationDocument::StartFetching() { 498 void ServicesCustomizationDocument::StartFetching() {
396 if (IsReady() || fetch_started_) 499 if (IsReady() || fetch_started_)
397 return; 500 return;
398 501
399 if (!url_.is_valid()) { 502 if (!url_.is_valid()) {
400 std::string customization_id; 503 std::string customization_id;
401 chromeos::system::StatisticsProvider* provider = 504 chromeos::system::StatisticsProvider* provider =
402 chromeos::system::StatisticsProvider::GetInstance(); 505 chromeos::system::StatisticsProvider::GetInstance();
403 if (provider->GetMachineStatistic(system::kCustomizationIdKey, 506 if (provider->GetMachineStatistic(system::kCustomizationIdKey,
404 &customization_id) && 507 &customization_id) &&
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_SUCCESS); 575 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_SUCCESS);
473 OnManifestLoaded(); 576 OnManifestLoaded();
474 return true; 577 return true;
475 } 578 }
476 579
477 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_PARSING_ERROR); 580 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_PARSING_ERROR);
478 return false; 581 return false;
479 } 582 }
480 583
481 void ServicesCustomizationDocument::OnManifestLoaded() { 584 void ServicesCustomizationDocument::OnManifestLoaded() {
482 if (!ServicesCustomizationDocument::WasOOBECustomizationApplied()) 585 if (!WasOOBECustomizationApplied())
483 ApplyOOBECustomization(); 586 ApplyOOBECustomization();
484 587
485 scoped_ptr<base::DictionaryValue> prefs = 588 scoped_ptr<base::DictionaryValue> prefs =
486 GetDefaultAppsInProviderFormat(*root_); 589 GetDefaultAppsInProviderFormat(*root_);
487 for (ExternalLoaders::iterator it = external_loaders_.begin(); 590 for (ExternalLoaders::iterator it = external_loaders_.begin();
488 it != external_loaders_.end(); ++it) { 591 it != external_loaders_.end(); ++it) {
489 if (*it) { 592 if (*it) {
490 UpdateCachedManifest((*it)->profile()); 593 UpdateCachedManifest((*it)->profile());
491 (*it)->SetCurrentApps( 594 (*it)->SetCurrentApps(
492 scoped_ptr<base::DictionaryValue>(prefs->DeepCopy())); 595 scoped_ptr<base::DictionaryValue>(prefs->DeepCopy()));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 LOG(ERROR) << "URL fetch for services customization failed:" 627 LOG(ERROR) << "URL fetch for services customization failed:"
525 << " response code = " << source->GetResponseCode() 628 << " response code = " << source->GetResponseCode()
526 << " URL = " << source->GetURL().spec(); 629 << " URL = " << source->GetURL().spec();
527 630
528 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_RETRIES_FAIL); 631 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_RETRIES_FAIL);
529 } 632 }
530 fetch_started_ = false; 633 fetch_started_ = false;
531 } 634 }
532 635
533 bool ServicesCustomizationDocument::ApplyOOBECustomization() { 636 bool ServicesCustomizationDocument::ApplyOOBECustomization() {
534 // TODO(dpolukhin): apply default wallpaper, crbug.com/348136. 637 if (apply_tasks_started_)
535 SetApplied(true); 638 return false;
536 return true; 639
640 CheckAndApplyWallpaper();
641 return false;
537 } 642 }
538 643
539 GURL ServicesCustomizationDocument::GetDefaultWallpaperUrl() const { 644 GURL ServicesCustomizationDocument::GetDefaultWallpaperUrl() const {
540 if (!IsReady()) 645 if (!IsReady())
541 return GURL(); 646 return GURL();
542 647
543 std::string url; 648 std::string url;
544 root_->GetString(kDefaultWallpaperAttr, &url); 649 root_->GetString(kDefaultWallpaperAttr, &url);
545 return GURL(url); 650 return GURL(url);
546 } 651 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 g_test_services_customization_document = new ServicesCustomizationDocument; 773 g_test_services_customization_document = new ServicesCustomizationDocument;
669 g_test_services_customization_document->network_delay_ = base::TimeDelta(); 774 g_test_services_customization_document->network_delay_ = base::TimeDelta();
670 } 775 }
671 776
672 // static 777 // static
673 void ServicesCustomizationDocument::ShutdownForTesting() { 778 void ServicesCustomizationDocument::ShutdownForTesting() {
674 delete g_test_services_customization_document; 779 delete g_test_services_customization_document;
675 g_test_services_customization_document = NULL; 780 g_test_services_customization_document = NULL;
676 } 781 }
677 782
783 void ServicesCustomizationDocument::StartOEMWallpaperDownload(
784 const GURL& wallpaper_url,
785 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying) {
786 DCHECK(wallpaper_url.is_valid());
787
788 const base::FilePath dir = GetCustomizedWallpaperCacheDir();
789 const base::FilePath file = GetCustomizedWallpaperDownloadedFileName();
790 if (dir.empty() || file.empty()) {
791 NOTREACHED();
792 applying->Finished(false);
793 return;
794 }
795
796 wallpaper_downloader_.reset(new CustomizationWallpaperDownloader(
797 g_browser_process->system_request_context(),
798 wallpaper_url,
799 dir,
800 file,
801 base::Bind(&ServicesCustomizationDocument::OnOEMWallpaperDownloaded,
802 weak_ptr_factory_.GetWeakPtr(),
803 base::Passed(applying.Pass()))));
804
805 wallpaper_downloader_->Start();
806 }
807
808 void ServicesCustomizationDocument::CheckAndApplyWallpaper() {
809 if (wallpaper_downloader_.get()) {
810 VLOG(1) << "CheckAndApplyWallpaper(): download has already started.";
811 return;
812 }
813 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying(
814 new ServicesCustomizationDocument::ApplyingTask(this));
815
816 GURL wallpaper_url = GetDefaultWallpaperUrl();
817
818 // Should fail if this ever happens in tests.
819 DCHECK(wallpaper_url.is_valid());
820 if (!wallpaper_url.is_valid()) {
821 if (!wallpaper_url.is_empty()) {
822 LOG(WARNING) << "Invalid Customized Wallpaper URL '"
823 << wallpaper_url.spec() << "'.";
824 }
825 applying->Finished(false);
826 return;
827 }
828
829 scoped_ptr<bool> exists(new bool(false));
830
831 base::Closure check_file_exists =
832 base::Bind(&CheckWallpaperCacheExists,
833 GetCustomizedWallpaperDownloadedFileName(),
834 base::Unretained(exists.get()));
835 base::Closure on_checked_closure =
836 base::Bind(&ServicesCustomizationDocument::OnCheckedWallpaperCacheExists,
837 weak_ptr_factory_.GetWeakPtr(),
838 base::Passed(exists.Pass()),
839 base::Passed(applying.Pass()));
840 if (!content::BrowserThread::PostBlockingPoolTaskAndReply(
841 FROM_HERE, check_file_exists, on_checked_closure)) {
842 LOG(WARNING) << "Failed to start check Wallpaper cache exists.";
843 }
844 }
845
846 void ServicesCustomizationDocument::OnCheckedWallpaperCacheExists(
847 scoped_ptr<bool> exists,
848 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying) {
849 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
850 DCHECK(exists);
851 DCHECK(applying);
852
853 ApplyWallpaper(*exists, applying.Pass());
854 }
855
856 void ServicesCustomizationDocument::ApplyWallpaper(
857 bool default_wallpaper_file_exists,
858 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying) {
859 GURL wallpaper_url = GetDefaultWallpaperUrl();
860 DCHECK(wallpaper_url.is_valid());
861
862 PrefService* pref_service = g_browser_process->local_state();
863
864 std::string current_url =
865 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL);
866 if (current_url != wallpaper_url.spec()) {
867 VLOG(1) << "ServicesCustomizationDocument::ApplyWallpaper() : "
868 << "Wallpaper URL in customization document '"
869 << wallpaper_url.spec() << "' differs from current '" << current_url
870 << "'."
871 << (GURL(current_url).is_valid() && default_wallpaper_file_exists
872 ? " Ignored."
873 : " Will refetch.");
874 }
875 // Never update system-wide wallpaper (i.e. do not check
876 // current_url == wallpaper_url.spec() )
877 if (GURL(current_url).is_valid() && default_wallpaper_file_exists) {
878 VLOG(1)
879 << "ServicesCustomizationDocument::ApplyWallpaper() : reuse existing";
880 OnOEMWallpaperDownloaded(applying.Pass(), true, GURL(current_url));
881 } else {
882 VLOG(1)
883 << "ServicesCustomizationDocument::ApplyWallpaper() : start download";
884 StartOEMWallpaperDownload(wallpaper_url, applying.Pass());
885 }
886 }
887
888 void ServicesCustomizationDocument::OnOEMWallpaperDownloaded(
889 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying,
890 bool success,
891 const GURL& wallpaper_url) {
892 if (success) {
893 DCHECK(wallpaper_url.is_valid());
894
895 VLOG(1) << "Setting default wallpaper to '"
896 << GetCustomizedWallpaperDownloadedFileName().value() << "' ('"
897 << wallpaper_url.spec() << "')";
898 WallpaperManager::Get()->SetCustomizedDefaultWallpaper(
899 wallpaper_url,
900 GetCustomizedWallpaperDownloadedFileName(),
901 GetCustomizedWallpaperCacheDir());
902 }
903 wallpaper_downloader_.reset();
904 applying->Finished(success);
905 }
906
907 void ServicesCustomizationDocument::ApplyingTaskStarted() {
908 ++apply_tasks_started_;
909 }
910
911 void ServicesCustomizationDocument::ApplyingTaskFinished(bool success) {
912 DCHECK(apply_tasks_started_ > apply_tasks_finished_);
Daniel Erat 2014/04/17 16:24:22 nit: use DCHECK_GT instead so both values will be
Alexander Alekseev 2014/04/17 20:02:56 Done.
913 ++apply_tasks_finished_;
914
915 apply_tasks_success_ += success;
916
917 if (apply_tasks_started_ != apply_tasks_finished_)
918 return;
919
920 if (apply_tasks_success_ == apply_tasks_finished_)
921 SetApplied(true);
922 }
923
678 } // namespace chromeos 924 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698