| 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/customization_document.h" | 5 #include "chrome/browser/chromeos/customization/customization_document.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 class ServicesCustomizationExternalLoader | 162 class ServicesCustomizationExternalLoader |
| 163 : public extensions::ExternalLoader, | 163 : public extensions::ExternalLoader, |
| 164 public base::SupportsWeakPtr<ServicesCustomizationExternalLoader> { | 164 public base::SupportsWeakPtr<ServicesCustomizationExternalLoader> { |
| 165 public: | 165 public: |
| 166 explicit ServicesCustomizationExternalLoader(Profile* profile) | 166 explicit ServicesCustomizationExternalLoader(Profile* profile) |
| 167 : is_apps_set_(false), profile_(profile) {} | 167 : is_apps_set_(false), profile_(profile) {} |
| 168 | 168 |
| 169 Profile* profile() { return profile_; } | 169 Profile* profile() { return profile_; } |
| 170 | 170 |
| 171 // Used by the ServicesCustomizationDocument to update the current apps. | 171 // Used by the ServicesCustomizationDocument to update the current apps. |
| 172 void SetCurrentApps(scoped_ptr<base::DictionaryValue> prefs) { | 172 void SetCurrentApps(std::unique_ptr<base::DictionaryValue> prefs) { |
| 173 apps_.Swap(prefs.get()); | 173 apps_.Swap(prefs.get()); |
| 174 is_apps_set_ = true; | 174 is_apps_set_ = true; |
| 175 StartLoading(); | 175 StartLoading(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Implementation of extensions::ExternalLoader: | 178 // Implementation of extensions::ExternalLoader: |
| 179 void StartLoading() override { | 179 void StartLoading() override { |
| 180 if (!is_apps_set_) { | 180 if (!is_apps_set_) { |
| 181 ServicesCustomizationDocument::GetInstance()->StartFetching(); | 181 ServicesCustomizationDocument::GetInstance()->StartFetching(); |
| 182 // In case of missing customization ID, SetCurrentApps will be called | 182 // In case of missing customization ID, SetCurrentApps will be called |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 std::string manifest; | 219 std::string manifest; |
| 220 if (!base::ReadFileToString(manifest_path, &manifest)) | 220 if (!base::ReadFileToString(manifest_path, &manifest)) |
| 221 return false; | 221 return false; |
| 222 return LoadManifestFromString(manifest); | 222 return LoadManifestFromString(manifest); |
| 223 } | 223 } |
| 224 | 224 |
| 225 bool CustomizationDocument::LoadManifestFromString( | 225 bool CustomizationDocument::LoadManifestFromString( |
| 226 const std::string& manifest) { | 226 const std::string& manifest) { |
| 227 int error_code = 0; | 227 int error_code = 0; |
| 228 std::string error; | 228 std::string error; |
| 229 scoped_ptr<base::Value> root = base::JSONReader::ReadAndReturnError( | 229 std::unique_ptr<base::Value> root = base::JSONReader::ReadAndReturnError( |
| 230 manifest, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error); | 230 manifest, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error); |
| 231 if (error_code != base::JSONReader::JSON_NO_ERROR) | 231 if (error_code != base::JSONReader::JSON_NO_ERROR) |
| 232 LOG(ERROR) << error; | 232 LOG(ERROR) << error; |
| 233 DCHECK(root.get() != NULL); | 233 DCHECK(root.get() != NULL); |
| 234 if (root.get() == NULL) | 234 if (root.get() == NULL) |
| 235 return false; | 235 return false; |
| 236 DCHECK(root->GetType() == base::Value::TYPE_DICTIONARY); | 236 DCHECK(root->GetType() == base::Value::TYPE_DICTIONARY); |
| 237 if (root->GetType() == base::Value::TYPE_DICTIONARY) { | 237 if (root->GetType() == base::Value::TYPE_DICTIONARY) { |
| 238 root_.reset(static_cast<base::DictionaryValue*>(root.release())); | 238 root_.reset(static_cast<base::DictionaryValue*>(root.release())); |
| 239 std::string result; | 239 std::string result; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 } | 592 } |
| 593 | 593 |
| 594 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_PARSING_ERROR); | 594 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_PARSING_ERROR); |
| 595 return false; | 595 return false; |
| 596 } | 596 } |
| 597 | 597 |
| 598 void ServicesCustomizationDocument::OnManifestLoaded() { | 598 void ServicesCustomizationDocument::OnManifestLoaded() { |
| 599 if (!WasOOBECustomizationApplied()) | 599 if (!WasOOBECustomizationApplied()) |
| 600 ApplyOOBECustomization(); | 600 ApplyOOBECustomization(); |
| 601 | 601 |
| 602 scoped_ptr<base::DictionaryValue> prefs = | 602 std::unique_ptr<base::DictionaryValue> prefs = |
| 603 GetDefaultAppsInProviderFormat(*root_); | 603 GetDefaultAppsInProviderFormat(*root_); |
| 604 for (ExternalLoaders::iterator it = external_loaders_.begin(); | 604 for (ExternalLoaders::iterator it = external_loaders_.begin(); |
| 605 it != external_loaders_.end(); ++it) { | 605 it != external_loaders_.end(); ++it) { |
| 606 if (*it) { | 606 if (*it) { |
| 607 UpdateCachedManifest((*it)->profile()); | 607 UpdateCachedManifest((*it)->profile()); |
| 608 (*it)->SetCurrentApps( | 608 (*it)->SetCurrentApps( |
| 609 scoped_ptr<base::DictionaryValue>(prefs->DeepCopy())); | 609 std::unique_ptr<base::DictionaryValue>(prefs->DeepCopy())); |
| 610 SetOemFolderName((*it)->profile(), *root_); | 610 SetOemFolderName((*it)->profile(), *root_); |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 } | 613 } |
| 614 | 614 |
| 615 void ServicesCustomizationDocument::OnURLFetchComplete( | 615 void ServicesCustomizationDocument::OnURLFetchComplete( |
| 616 const net::URLFetcher* source) { | 616 const net::URLFetcher* source) { |
| 617 std::string mime_type; | 617 std::string mime_type; |
| 618 std::string data; | 618 std::string data; |
| 619 if (source->GetStatus().is_success() && | 619 if (source->GetStatus().is_success() && |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 return false; | 661 return false; |
| 662 | 662 |
| 663 std::string url; | 663 std::string url; |
| 664 if (!root_->GetString(kDefaultWallpaperAttr, &url)) | 664 if (!root_->GetString(kDefaultWallpaperAttr, &url)) |
| 665 return false; | 665 return false; |
| 666 | 666 |
| 667 *out_url = GURL(url); | 667 *out_url = GURL(url); |
| 668 return true; | 668 return true; |
| 669 } | 669 } |
| 670 | 670 |
| 671 scoped_ptr<base::DictionaryValue> | 671 std::unique_ptr<base::DictionaryValue> |
| 672 ServicesCustomizationDocument::GetDefaultApps() const { | 672 ServicesCustomizationDocument::GetDefaultApps() const { |
| 673 if (!IsReady()) | 673 if (!IsReady()) |
| 674 return scoped_ptr<base::DictionaryValue>(); | 674 return std::unique_ptr<base::DictionaryValue>(); |
| 675 | 675 |
| 676 return GetDefaultAppsInProviderFormat(*root_); | 676 return GetDefaultAppsInProviderFormat(*root_); |
| 677 } | 677 } |
| 678 | 678 |
| 679 std::string ServicesCustomizationDocument::GetOemAppsFolderName( | 679 std::string ServicesCustomizationDocument::GetOemAppsFolderName( |
| 680 const std::string& locale) const { | 680 const std::string& locale) const { |
| 681 if (!IsReady()) | 681 if (!IsReady()) |
| 682 return std::string(); | 682 return std::string(); |
| 683 | 683 |
| 684 return GetOemAppsFolderNameImpl(locale, *root_); | 684 return GetOemAppsFolderNameImpl(locale, *root_); |
| 685 } | 685 } |
| 686 | 686 |
| 687 scoped_ptr<base::DictionaryValue> | 687 std::unique_ptr<base::DictionaryValue> |
| 688 ServicesCustomizationDocument::GetDefaultAppsInProviderFormat( | 688 ServicesCustomizationDocument::GetDefaultAppsInProviderFormat( |
| 689 const base::DictionaryValue& root) { | 689 const base::DictionaryValue& root) { |
| 690 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 690 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 691 const base::ListValue* apps_list = NULL; | 691 const base::ListValue* apps_list = NULL; |
| 692 if (root.GetList(kDefaultAppsAttr, &apps_list)) { | 692 if (root.GetList(kDefaultAppsAttr, &apps_list)) { |
| 693 for (size_t i = 0; i < apps_list->GetSize(); ++i) { | 693 for (size_t i = 0; i < apps_list->GetSize(); ++i) { |
| 694 std::string app_id; | 694 std::string app_id; |
| 695 const base::DictionaryValue* app_entry = nullptr; | 695 const base::DictionaryValue* app_entry = nullptr; |
| 696 scoped_ptr<base::DictionaryValue> entry; | 696 std::unique_ptr<base::DictionaryValue> entry; |
| 697 if (apps_list->GetString(i, &app_id)) { | 697 if (apps_list->GetString(i, &app_id)) { |
| 698 entry.reset(new base::DictionaryValue()); | 698 entry.reset(new base::DictionaryValue()); |
| 699 } else if (apps_list->GetDictionary(i, &app_entry)) { | 699 } else if (apps_list->GetDictionary(i, &app_entry)) { |
| 700 if (!app_entry->GetString(kIdAttr, &app_id)) { | 700 if (!app_entry->GetString(kIdAttr, &app_id)) { |
| 701 LOG(ERROR) << "Wrong format of default application list"; | 701 LOG(ERROR) << "Wrong format of default application list"; |
| 702 prefs->Clear(); | 702 prefs->Clear(); |
| 703 break; | 703 break; |
| 704 } | 704 } |
| 705 entry = app_entry->CreateDeepCopy(); | 705 entry = app_entry->CreateDeepCopy(); |
| 706 entry->Remove(kIdAttr, nullptr); | 706 entry->Remove(kIdAttr, nullptr); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 } | 791 } |
| 792 | 792 |
| 793 // static | 793 // static |
| 794 void ServicesCustomizationDocument::ShutdownForTesting() { | 794 void ServicesCustomizationDocument::ShutdownForTesting() { |
| 795 delete g_test_services_customization_document; | 795 delete g_test_services_customization_document; |
| 796 g_test_services_customization_document = NULL; | 796 g_test_services_customization_document = NULL; |
| 797 } | 797 } |
| 798 | 798 |
| 799 void ServicesCustomizationDocument::StartOEMWallpaperDownload( | 799 void ServicesCustomizationDocument::StartOEMWallpaperDownload( |
| 800 const GURL& wallpaper_url, | 800 const GURL& wallpaper_url, |
| 801 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying) { | 801 std::unique_ptr<ServicesCustomizationDocument::ApplyingTask> applying) { |
| 802 DCHECK(wallpaper_url.is_valid()); | 802 DCHECK(wallpaper_url.is_valid()); |
| 803 | 803 |
| 804 const base::FilePath dir = GetCustomizedWallpaperCacheDir(); | 804 const base::FilePath dir = GetCustomizedWallpaperCacheDir(); |
| 805 const base::FilePath file = GetCustomizedWallpaperDownloadedFileName(); | 805 const base::FilePath file = GetCustomizedWallpaperDownloadedFileName(); |
| 806 if (dir.empty() || file.empty()) { | 806 if (dir.empty() || file.empty()) { |
| 807 NOTREACHED(); | 807 NOTREACHED(); |
| 808 applying->Finished(false); | 808 applying->Finished(false); |
| 809 return; | 809 return; |
| 810 } | 810 } |
| 811 | 811 |
| 812 wallpaper_downloader_.reset(new CustomizationWallpaperDownloader( | 812 wallpaper_downloader_.reset(new CustomizationWallpaperDownloader( |
| 813 g_browser_process->system_request_context(), wallpaper_url, dir, file, | 813 g_browser_process->system_request_context(), wallpaper_url, dir, file, |
| 814 base::Bind(&ServicesCustomizationDocument::OnOEMWallpaperDownloaded, | 814 base::Bind(&ServicesCustomizationDocument::OnOEMWallpaperDownloaded, |
| 815 weak_ptr_factory_.GetWeakPtr(), | 815 weak_ptr_factory_.GetWeakPtr(), |
| 816 base::Passed(std::move(applying))))); | 816 base::Passed(std::move(applying))))); |
| 817 | 817 |
| 818 wallpaper_downloader_->Start(); | 818 wallpaper_downloader_->Start(); |
| 819 } | 819 } |
| 820 | 820 |
| 821 void ServicesCustomizationDocument::CheckAndApplyWallpaper() { | 821 void ServicesCustomizationDocument::CheckAndApplyWallpaper() { |
| 822 if (wallpaper_downloader_.get()) { | 822 if (wallpaper_downloader_.get()) { |
| 823 VLOG(1) << "CheckAndApplyWallpaper(): download has already started."; | 823 VLOG(1) << "CheckAndApplyWallpaper(): download has already started."; |
| 824 return; | 824 return; |
| 825 } | 825 } |
| 826 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying( | 826 std::unique_ptr<ServicesCustomizationDocument::ApplyingTask> applying( |
| 827 new ServicesCustomizationDocument::ApplyingTask(this)); | 827 new ServicesCustomizationDocument::ApplyingTask(this)); |
| 828 | 828 |
| 829 GURL wallpaper_url; | 829 GURL wallpaper_url; |
| 830 if (!GetDefaultWallpaperUrl(&wallpaper_url)) { | 830 if (!GetDefaultWallpaperUrl(&wallpaper_url)) { |
| 831 PrefService* pref_service = g_browser_process->local_state(); | 831 PrefService* pref_service = g_browser_process->local_state(); |
| 832 std::string current_url = | 832 std::string current_url = |
| 833 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); | 833 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); |
| 834 if (!current_url.empty()) { | 834 if (!current_url.empty()) { |
| 835 VLOG(1) << "ServicesCustomizationDocument::CheckAndApplyWallpaper() : " | 835 VLOG(1) << "ServicesCustomizationDocument::CheckAndApplyWallpaper() : " |
| 836 << "No wallpaper URL attribute in customization document, " | 836 << "No wallpaper URL attribute in customization document, " |
| 837 << "but current value is non-empty: '" << current_url | 837 << "but current value is non-empty: '" << current_url |
| 838 << "'. Ignored."; | 838 << "'. Ignored."; |
| 839 } | 839 } |
| 840 applying->Finished(true); | 840 applying->Finished(true); |
| 841 return; | 841 return; |
| 842 } | 842 } |
| 843 | 843 |
| 844 // Should fail if this ever happens in tests. | 844 // Should fail if this ever happens in tests. |
| 845 DCHECK(wallpaper_url.is_valid()); | 845 DCHECK(wallpaper_url.is_valid()); |
| 846 if (!wallpaper_url.is_valid()) { | 846 if (!wallpaper_url.is_valid()) { |
| 847 if (!wallpaper_url.is_empty()) { | 847 if (!wallpaper_url.is_empty()) { |
| 848 LOG(WARNING) << "Invalid Customized Wallpaper URL '" | 848 LOG(WARNING) << "Invalid Customized Wallpaper URL '" |
| 849 << wallpaper_url.spec() << "'."; | 849 << wallpaper_url.spec() << "'."; |
| 850 } | 850 } |
| 851 applying->Finished(false); | 851 applying->Finished(false); |
| 852 return; | 852 return; |
| 853 } | 853 } |
| 854 | 854 |
| 855 scoped_ptr<bool> exists(new bool(false)); | 855 std::unique_ptr<bool> exists(new bool(false)); |
| 856 | 856 |
| 857 base::Closure check_file_exists = | 857 base::Closure check_file_exists = |
| 858 base::Bind(&CheckWallpaperCacheExists, | 858 base::Bind(&CheckWallpaperCacheExists, |
| 859 GetCustomizedWallpaperDownloadedFileName(), | 859 GetCustomizedWallpaperDownloadedFileName(), |
| 860 base::Unretained(exists.get())); | 860 base::Unretained(exists.get())); |
| 861 base::Closure on_checked_closure = base::Bind( | 861 base::Closure on_checked_closure = base::Bind( |
| 862 &ServicesCustomizationDocument::OnCheckedWallpaperCacheExists, | 862 &ServicesCustomizationDocument::OnCheckedWallpaperCacheExists, |
| 863 weak_ptr_factory_.GetWeakPtr(), base::Passed(std::move(exists)), | 863 weak_ptr_factory_.GetWeakPtr(), base::Passed(std::move(exists)), |
| 864 base::Passed(std::move(applying))); | 864 base::Passed(std::move(applying))); |
| 865 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | 865 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 866 FROM_HERE, check_file_exists, on_checked_closure)) { | 866 FROM_HERE, check_file_exists, on_checked_closure)) { |
| 867 LOG(WARNING) << "Failed to start check Wallpaper cache exists."; | 867 LOG(WARNING) << "Failed to start check Wallpaper cache exists."; |
| 868 } | 868 } |
| 869 } | 869 } |
| 870 | 870 |
| 871 void ServicesCustomizationDocument::OnCheckedWallpaperCacheExists( | 871 void ServicesCustomizationDocument::OnCheckedWallpaperCacheExists( |
| 872 scoped_ptr<bool> exists, | 872 std::unique_ptr<bool> exists, |
| 873 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying) { | 873 std::unique_ptr<ServicesCustomizationDocument::ApplyingTask> applying) { |
| 874 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 874 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 875 DCHECK(exists); | 875 DCHECK(exists); |
| 876 DCHECK(applying); | 876 DCHECK(applying); |
| 877 | 877 |
| 878 ApplyWallpaper(*exists, std::move(applying)); | 878 ApplyWallpaper(*exists, std::move(applying)); |
| 879 } | 879 } |
| 880 | 880 |
| 881 void ServicesCustomizationDocument::ApplyWallpaper( | 881 void ServicesCustomizationDocument::ApplyWallpaper( |
| 882 bool default_wallpaper_file_exists, | 882 bool default_wallpaper_file_exists, |
| 883 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying) { | 883 std::unique_ptr<ServicesCustomizationDocument::ApplyingTask> applying) { |
| 884 GURL wallpaper_url; | 884 GURL wallpaper_url; |
| 885 const bool wallpaper_url_present = GetDefaultWallpaperUrl(&wallpaper_url); | 885 const bool wallpaper_url_present = GetDefaultWallpaperUrl(&wallpaper_url); |
| 886 | 886 |
| 887 PrefService* pref_service = g_browser_process->local_state(); | 887 PrefService* pref_service = g_browser_process->local_state(); |
| 888 | 888 |
| 889 std::string current_url = | 889 std::string current_url = |
| 890 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); | 890 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); |
| 891 if (current_url != wallpaper_url.spec()) { | 891 if (current_url != wallpaper_url.spec()) { |
| 892 if (wallpaper_url_present) { | 892 if (wallpaper_url_present) { |
| 893 VLOG(1) << "ServicesCustomizationDocument::ApplyWallpaper() : " | 893 VLOG(1) << "ServicesCustomizationDocument::ApplyWallpaper() : " |
| (...skipping 24 matching lines...) Expand all Loading... |
| 918 << "ServicesCustomizationDocument::ApplyWallpaper() : reuse existing"; | 918 << "ServicesCustomizationDocument::ApplyWallpaper() : reuse existing"; |
| 919 OnOEMWallpaperDownloaded(std::move(applying), true, GURL(current_url)); | 919 OnOEMWallpaperDownloaded(std::move(applying), true, GURL(current_url)); |
| 920 } else { | 920 } else { |
| 921 VLOG(1) | 921 VLOG(1) |
| 922 << "ServicesCustomizationDocument::ApplyWallpaper() : start download"; | 922 << "ServicesCustomizationDocument::ApplyWallpaper() : start download"; |
| 923 StartOEMWallpaperDownload(wallpaper_url, std::move(applying)); | 923 StartOEMWallpaperDownload(wallpaper_url, std::move(applying)); |
| 924 } | 924 } |
| 925 } | 925 } |
| 926 | 926 |
| 927 void ServicesCustomizationDocument::OnOEMWallpaperDownloaded( | 927 void ServicesCustomizationDocument::OnOEMWallpaperDownloaded( |
| 928 scoped_ptr<ServicesCustomizationDocument::ApplyingTask> applying, | 928 std::unique_ptr<ServicesCustomizationDocument::ApplyingTask> applying, |
| 929 bool success, | 929 bool success, |
| 930 const GURL& wallpaper_url) { | 930 const GURL& wallpaper_url) { |
| 931 if (success) { | 931 if (success) { |
| 932 DCHECK(wallpaper_url.is_valid()); | 932 DCHECK(wallpaper_url.is_valid()); |
| 933 | 933 |
| 934 VLOG(1) << "Setting default wallpaper to '" | 934 VLOG(1) << "Setting default wallpaper to '" |
| 935 << GetCustomizedWallpaperDownloadedFileName().value() << "' ('" | 935 << GetCustomizedWallpaperDownloadedFileName().value() << "' ('" |
| 936 << wallpaper_url.spec() << "')"; | 936 << wallpaper_url.spec() << "')"; |
| 937 WallpaperManager::Get()->SetCustomizedDefaultWallpaper( | 937 WallpaperManager::Get()->SetCustomizedDefaultWallpaper( |
| 938 wallpaper_url, | 938 wallpaper_url, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 954 apply_tasks_success_ += success; | 954 apply_tasks_success_ += success; |
| 955 | 955 |
| 956 if (apply_tasks_started_ != apply_tasks_finished_) | 956 if (apply_tasks_started_ != apply_tasks_finished_) |
| 957 return; | 957 return; |
| 958 | 958 |
| 959 if (apply_tasks_success_ == apply_tasks_finished_) | 959 if (apply_tasks_success_ == apply_tasks_finished_) |
| 960 SetApplied(true); | 960 SetApplied(true); |
| 961 } | 961 } |
| 962 | 962 |
| 963 } // namespace chromeos | 963 } // namespace chromeos |
| OLD | NEW |