Chromium Code Reviews| 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 #include "chrome/browser/chromeos/customization_document.h" | 5 #include "chrome/browser/chromeos/customization_document.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | |
| 15 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
| 16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/chromeos/customization_wallpaper_downloader.h" | |
| 25 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | |
| 23 #include "chrome/browser/chromeos/login/wizard_controller.h" | 26 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 24 #include "chrome/browser/chromeos/net/delay_network_call.h" | 27 #include "chrome/browser/chromeos/net/delay_network_call.h" |
| 25 #include "chrome/browser/extensions/external_loader.h" | 28 #include "chrome/browser/extensions/external_loader.h" |
| 26 #include "chrome/browser/extensions/external_provider_impl.h" | 29 #include "chrome/browser/extensions/external_provider_impl.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 31 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 29 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 32 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 33 #include "chrome/common/chrome_paths.h" | |
| 30 #include "chrome/common/extensions/extension_constants.h" | 34 #include "chrome/common/extensions/extension_constants.h" |
| 35 #include "chrome/common/pref_names.h" | |
| 31 #include "chromeos/network/network_state.h" | 36 #include "chromeos/network/network_state.h" |
| 32 #include "chromeos/network/network_state_handler.h" | 37 #include "chromeos/network/network_state_handler.h" |
| 33 #include "chromeos/system/statistics_provider.h" | 38 #include "chromeos/system/statistics_provider.h" |
| 34 #include "components/user_prefs/pref_registry_syncable.h" | 39 #include "components/user_prefs/pref_registry_syncable.h" |
| 35 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 36 #include "net/base/load_flags.h" | 41 #include "net/base/load_flags.h" |
| 37 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
| 38 #include "net/http/http_status_code.h" | 43 #include "net/http/http_status_code.h" |
| 39 #include "net/url_request/url_fetcher.h" | 44 #include "net/url_request/url_fetcher.h" |
| 40 | 45 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 57 const char kDefaultAppsAttr[] = "default_apps"; | 62 const char kDefaultAppsAttr[] = "default_apps"; |
| 58 const char kLocalizedContent[] = "localized_content"; | 63 const char kLocalizedContent[] = "localized_content"; |
| 59 const char kDefaultAppsFolderName[] = "default_apps_folder_name"; | 64 const char kDefaultAppsFolderName[] = "default_apps_folder_name"; |
| 60 | 65 |
| 61 const char kAcceptedManifestVersion[] = "1.0"; | 66 const char kAcceptedManifestVersion[] = "1.0"; |
| 62 | 67 |
| 63 // Path to OEM partner startup customization manifest. | 68 // Path to OEM partner startup customization manifest. |
| 64 const char kStartupCustomizationManifestPath[] = | 69 const char kStartupCustomizationManifestPath[] = |
| 65 "/opt/oem/etc/startup_manifest.json"; | 70 "/opt/oem/etc/startup_manifest.json"; |
| 66 | 71 |
| 72 static const char kCustomizationDefaultWallpaperDir[] = "customization/"; | |
|
bshe
2014/03/24 21:30:49
nit: remove static keyword to keep it consistent w
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
| 73 | |
| 74 // The original downloaded image file is stored under this name. | |
| 75 static const char kCustomizationDefaultWallpaperDownloadedFile[] = | |
| 76 "default.downloaded"; | |
|
bshe
2014/03/24 21:30:49
ditto
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
| 77 | |
| 67 // Name of local state option that tracks if services customization has been | 78 // Name of local state option that tracks if services customization has been |
| 68 // applied. | 79 // applied. |
| 69 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied"; | 80 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied"; |
| 70 | 81 |
| 71 // Maximum number of retries to fetch file if network is not available. | 82 // Maximum number of retries to fetch file if network is not available. |
| 72 const int kMaxFetchRetries = 3; | 83 const int kMaxFetchRetries = 3; |
| 73 | 84 |
| 74 // Delay between file fetch retries if network is not available. | 85 // Delay between file fetch retries if network is not available. |
| 75 const int kRetriesDelayInSec = 2; | 86 const int kRetriesDelayInSec = 2; |
| 76 | 87 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 const base::DictionaryValue* default_dictionary = NULL; | 127 const base::DictionaryValue* default_dictionary = NULL; |
| 117 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { | 128 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { |
| 118 std::string result; | 129 std::string result; |
| 119 if (default_dictionary->GetString(entry_name, &result)) | 130 if (default_dictionary->GetString(entry_name, &result)) |
| 120 return result; | 131 return result; |
| 121 } | 132 } |
| 122 | 133 |
| 123 return std::string(); | 134 return std::string(); |
| 124 } | 135 } |
| 125 | 136 |
| 137 void CheckWallpaperCacheExists(const base::FilePath& path, bool* exists) { | |
| 138 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
|
bshe
2014/03/24 21:30:49
It looks like this is called on worker pool thread
Alexander Alekseev
2014/03/25 14:38:29
Yes, but there is no direct way to check that we'r
| |
| 139 DCHECK(exists); | |
| 140 *exists = base::PathExists(path); | |
| 141 } | |
| 142 | |
| 126 } // anonymous namespace | 143 } // anonymous namespace |
| 127 | 144 |
| 128 namespace chromeos { | 145 namespace chromeos { |
| 129 | 146 |
| 130 // Template URL where to fetch OEM services customization manifest from. | 147 // Template URL where to fetch OEM services customization manifest from. |
| 131 const char ServicesCustomizationDocument::kManifestUrl[] = | 148 const char ServicesCustomizationDocument::kManifestUrl[] = |
| 132 "https://ssl.gstatic.com/chrome/chromeos-customization/%s.json"; | 149 "https://ssl.gstatic.com/chrome/chromeos-customization/%s.json"; |
| 133 | 150 |
| 134 // A custom extensions::ExternalLoader that the ServicesCustomizationDocument | 151 // A custom extensions::ExternalLoader that the ServicesCustomizationDocument |
| 135 // creates and uses to publish OEM default apps to the extensions system. | 152 // creates and uses to publish OEM default apps to the extensions system. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 // static | 366 // static |
| 350 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() { | 367 ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() { |
| 351 return Singleton<ServicesCustomizationDocument, | 368 return Singleton<ServicesCustomizationDocument, |
| 352 DefaultSingletonTraits<ServicesCustomizationDocument> >::get(); | 369 DefaultSingletonTraits<ServicesCustomizationDocument> >::get(); |
| 353 } | 370 } |
| 354 | 371 |
| 355 // static | 372 // static |
| 356 void ServicesCustomizationDocument::RegisterPrefs( | 373 void ServicesCustomizationDocument::RegisterPrefs( |
| 357 PrefRegistrySimple* registry) { | 374 PrefRegistrySimple* registry) { |
| 358 registry->RegisterBooleanPref(kServicesCustomizationAppliedPref, false); | 375 registry->RegisterBooleanPref(kServicesCustomizationAppliedPref, false); |
| 376 registry->RegisterStringPref(prefs::kCustomizationDefaultWallpaperURL, ""); | |
| 359 } | 377 } |
| 360 | 378 |
| 361 // static | 379 // static |
| 362 void ServicesCustomizationDocument::RegisterProfilePrefs( | 380 void ServicesCustomizationDocument::RegisterProfilePrefs( |
| 363 user_prefs::PrefRegistrySyncable* registry) { | 381 user_prefs::PrefRegistrySyncable* registry) { |
| 364 registry->RegisterDictionaryPref( | 382 registry->RegisterDictionaryPref( |
| 365 kServicesCustomizationKey, | 383 kServicesCustomizationKey, |
| 366 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 384 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 367 } | 385 } |
| 368 | 386 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 // This doesn't stop fetching manifest on next restart. | 527 // This doesn't stop fetching manifest on next restart. |
| 510 LOG(ERROR) << "URL fetch for services customization failed:" | 528 LOG(ERROR) << "URL fetch for services customization failed:" |
| 511 << " response code = " << source->GetResponseCode() | 529 << " response code = " << source->GetResponseCode() |
| 512 << " URL = " << source->GetURL().spec(); | 530 << " URL = " << source->GetURL().spec(); |
| 513 | 531 |
| 514 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_RETRIES_FAIL); | 532 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_RETRIES_FAIL); |
| 515 } | 533 } |
| 516 fetch_started_ = false; | 534 fetch_started_ = false; |
| 517 } | 535 } |
| 518 | 536 |
| 537 void ServicesCustomizationDocument::StartOEMWallpaperDownload( | |
| 538 const GURL& wallpaper_url) { | |
| 539 DCHECK(wallpaper_url.is_valid()); | |
| 540 | |
| 541 const base::FilePath dir = GetCustomizedWallpaperCacheDir(); | |
| 542 const base::FilePath file = GetCustomizedWallpaperDownloadedFileName(); | |
| 543 if (!dir.empty() && !file.empty()) { | |
| 544 wallpaper_downloader_.reset(new CustomizationWallpaperDownloader( | |
| 545 g_browser_process->system_request_context(), wallpaper_url, dir, file)); | |
| 546 | |
| 547 wallpaper_downloader_->Start(); | |
| 548 } | |
| 549 } | |
| 550 | |
| 551 // static | |
| 552 base::FilePath ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir() { | |
| 553 base::FilePath custom_wallpaper_dir; | |
| 554 const bool success = PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS, | |
| 555 &custom_wallpaper_dir); | |
| 556 DCHECK(success); | |
|
bshe
2014/03/24 21:30:49
why do you DCHECK here and have a if statement bel
Alexander Alekseev
2014/03/25 14:38:29
The idea is that we should fail in tests here, but
| |
| 557 | |
| 558 if (success) | |
| 559 return custom_wallpaper_dir.Append(kCustomizationDefaultWallpaperDir); | |
| 560 | |
| 561 return custom_wallpaper_dir; | |
| 562 } | |
| 563 | |
| 564 // static | |
| 565 base::FilePath | |
| 566 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName() { | |
|
bshe
2014/03/24 21:30:49
nit: 4 spaces indent
Alexander Alekseev
2014/03/25 14:38:29
Done. (Strange, but clang-format doesn't agree wit
| |
| 567 const base::FilePath dir = GetCustomizedWallpaperCacheDir(); | |
| 568 if (dir.empty()) | |
| 569 return dir; | |
| 570 return dir.Append(kCustomizationDefaultWallpaperDownloadedFile); | |
| 571 } | |
| 572 | |
| 573 // static | |
| 574 void ServicesCustomizationDocument::SetDefaultWallpaperPath( | |
| 575 const GURL& wallpaper_url) { | |
| 576 DCHECK(wallpaper_url.is_valid()); | |
| 577 | |
| 578 VLOG(1) << "Setting default wallpaper to '" | |
| 579 << GetCustomizedWallpaperDownloadedFileName().value() << "' ('" | |
| 580 << wallpaper_url.spec() << "')"; | |
| 581 WallpaperManager::Get()->SetCustomizedDefaultWallpaper( | |
| 582 wallpaper_url, | |
| 583 GetCustomizedWallpaperDownloadedFileName(), | |
| 584 GetCustomizedWallpaperCacheDir()); | |
| 585 } | |
| 586 | |
| 587 // static | |
| 588 void ServicesCustomizationDocument::DestroyWallpaperDownloader() { | |
| 589 ServicesCustomizationDocument* self = | |
| 590 ServicesCustomizationDocument::GetInstance(); | |
| 591 DCHECK(self); | |
| 592 self->wallpaper_downloader_.reset(); | |
| 593 } | |
| 594 | |
| 595 void ServicesCustomizationDocument::ApplyWallpaper( | |
| 596 bool default_wallpaper_file_exists) { | |
| 597 GURL wallpaper_url = GetDefaultWallpaperUrl(); | |
| 598 DCHECK(wallpaper_url.is_valid()); | |
| 599 | |
| 600 PrefService* prefService = g_browser_process->local_state(); | |
| 601 DCHECK(prefService); | |
|
Mattias Nissler (ping if slow)
2014/03/24 20:38:54
Remove, you'll get a crash report anyways below in
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
| 602 | |
| 603 std::string current_url = | |
| 604 prefService->GetString(prefs::kCustomizationDefaultWallpaperURL); | |
| 605 if (current_url != wallpaper_url.spec()) { | |
| 606 VLOG(1) << "ServicesCustomizationDocument::ApplyWallpaper() : " | |
|
Mattias Nissler (ping if slow)
2014/03/24 20:38:54
This VLOG is misleading, because the code below on
Alexander Alekseev
2014/03/25 14:38:29
If "current_url" is empty, "GURL(current_url).is_v
| |
| 607 << "Wallpaper URL in customization document '" | |
| 608 << wallpaper_url.spec() << "' differs from current '" << current_url | |
| 609 << "'. Ignored."; | |
| 610 } | |
| 611 // Never update system-wide wallpaper (i.e. do not check | |
| 612 // current_url == wallpaper_url.spec() ) | |
|
bshe
2014/03/24 21:30:49
I am not sure I understand this. What is we want t
Alexander Alekseev
2014/03/25 14:38:29
This is mentioned in design document: customizatio
| |
| 613 if (GURL(current_url).is_valid() && default_wallpaper_file_exists) { | |
| 614 VLOG(1) | |
| 615 << "ServicesCustomizationDocument::ApplyWallpaper() : reuse existing"; | |
| 616 SetDefaultWallpaperPath(GURL(current_url)); | |
|
bshe
2014/03/24 21:30:49
could we call:
WallpaperManager::Get()->SetCustomi
Alexander Alekseev
2014/03/25 14:38:29
SetDefaultWallpaperPath() is called both from here
| |
| 617 } else { | |
| 618 VLOG(1) | |
| 619 << "ServicesCustomizationDocument::ApplyWallpaper() : start download"; | |
| 620 StartOEMWallpaperDownload(wallpaper_url); | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 void ServicesCustomizationDocument::OnCheckedWallpaperCacheExists( | |
| 625 scoped_ptr<bool> exists) { | |
| 626 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 627 DCHECK(exists.get()); | |
| 628 | |
| 629 ApplyWallpaper(*exists); | |
| 630 } | |
| 631 | |
| 632 void ServicesCustomizationDocument::CheckAndApplyWallpaper() { | |
| 633 GURL wallpaper_url = GetDefaultWallpaperUrl(); | |
| 634 // Should fail if this ever happens in tests. | |
| 635 DCHECK(wallpaper_url.is_valid() || wallpaper_url.is_empty()); | |
| 636 if (!wallpaper_url.is_valid()) { | |
| 637 if (!wallpaper_url.is_empty()) { | |
| 638 LOG(WARNING) << "Invalid Customized Wallpaper URL."; | |
| 639 } | |
| 640 return; | |
| 641 } | |
| 642 scoped_ptr<bool> exists(new bool(false)); | |
| 643 | |
| 644 base::Closure check_file_exists = | |
| 645 base::Bind(&CheckWallpaperCacheExists, | |
| 646 GetCustomizedWallpaperDownloadedFileName(), | |
| 647 base::Unretained(exists.get())); | |
| 648 base::Closure on_checked_closure = | |
| 649 base::Bind(&ServicesCustomizationDocument::OnCheckedWallpaperCacheExists, | |
| 650 weak_ptr_factory_.GetWeakPtr(), | |
| 651 base::Passed(exists.Pass())); | |
| 652 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | |
| 653 FROM_HERE, check_file_exists, on_checked_closure)) { | |
| 654 LOG(WARNING) << "Failed to start check Wallpaper cache exists."; | |
| 655 } | |
| 656 } | |
| 657 | |
| 519 bool ServicesCustomizationDocument::ApplyOOBECustomization() { | 658 bool ServicesCustomizationDocument::ApplyOOBECustomization() { |
| 520 // TODO(dpolukhin): apply default wallpaper, crbug.com/348136. | 659 CheckAndApplyWallpaper(); |
| 521 SetApplied(true); | 660 SetApplied(true); |
| 522 return true; | 661 return true; |
| 523 } | 662 } |
| 524 | 663 |
| 525 GURL ServicesCustomizationDocument::GetDefaultWallpaperUrl() const { | 664 GURL ServicesCustomizationDocument::GetDefaultWallpaperUrl() const { |
| 526 if (!IsReady()) | 665 if (!IsReady()) |
| 527 return GURL(); | 666 return GURL(); |
| 528 | 667 |
| 529 std::string url; | 668 std::string url; |
| 530 root_->GetString(kDefaultWallpaperAttr, &url); | 669 root_->GetString(kDefaultWallpaperAttr, &url); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 } | 780 } |
| 642 | 781 |
| 643 std::string ServicesCustomizationDocument::GetOemAppsFolderNameImpl( | 782 std::string ServicesCustomizationDocument::GetOemAppsFolderNameImpl( |
| 644 const std::string& locale, | 783 const std::string& locale, |
| 645 const base::DictionaryValue& root) const { | 784 const base::DictionaryValue& root) const { |
| 646 return GetLocaleSpecificStringImpl( | 785 return GetLocaleSpecificStringImpl( |
| 647 &root, locale, kLocalizedContent, kDefaultAppsFolderName); | 786 &root, locale, kLocalizedContent, kDefaultAppsFolderName); |
| 648 } | 787 } |
| 649 | 788 |
| 650 } // namespace chromeos | 789 } // namespace chromeos |
| OLD | NEW |