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

Unified 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: After-review. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/customization_document.cc
diff --git a/chrome/browser/chromeos/customization_document.cc b/chrome/browser/chromeos/customization_document.cc
index 85a93df3d4bf478e5a660b783fdfba02a212b075..1e11195771f2d4e80c96fff3da620344cbf7785d 100644
--- a/chrome/browser/chromeos/customization_document.cc
+++ b/chrome/browser/chromeos/customization_document.cc
@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram.h"
+#include "base/path_service.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_split.h"
@@ -22,7 +23,9 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/customization_wallpaper_downloader.h"
#include "chrome/browser/chromeos/extensions/default_app_order.h"
+#include "chrome/browser/chromeos/login/wallpaper_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/net/delay_network_call.h"
#include "chrome/browser/extensions/external_loader.h"
@@ -30,7 +33,9 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/pref_names.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/system/statistics_provider.h"
@@ -68,6 +73,14 @@ const char kAcceptedManifestVersion[] = "1.0";
const char kStartupCustomizationManifestPath[] =
"/opt/oem/etc/startup_manifest.json";
+// This is subdirectory relative to PathService(DIR_CHROMEOS_CUSTOM_WALLPAPERS),
+// where downloaded (and resized) wallpaper is stored.
+const char kCustomizationDefaultWallpaperDir[] = "customization";
+
+// The original downloaded image file is stored under this name.
+const char kCustomizationDefaultWallpaperDownloadedFile[] =
Daniel Erat 2014/04/15 03:06:30 nit: put "Pref" on the end of this constant's name
Alexander Alekseev 2014/04/15 22:47:31 This is not a preference. This is exactly file nam
+ "default.downloaded";
Nikita (slow) 2014/04/15 12:39:24 nit: should file name include extension for clarit
Alexander Alekseev 2014/04/15 22:47:31 It says nothing. Current implementation will allow
+
// Name of local state option that tracks if services customization has been
// applied.
const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied";
@@ -130,6 +143,12 @@ std::string GetLocaleSpecificStringImpl(
return std::string();
}
+void CheckWallpaperCacheExists(const base::FilePath& path, bool* exists) {
+ DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
+ DCHECK(exists);
+ *exists = base::PathExists(path);
+}
+
} // anonymous namespace
// Template URL where to fetch OEM services customization manifest from.
@@ -370,6 +389,7 @@ ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() {
void ServicesCustomizationDocument::RegisterPrefs(
PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kServicesCustomizationAppliedPref, false);
+ registry->RegisterStringPref(prefs::kCustomizationDefaultWallpaperURL, "");
Nikita (slow) 2014/04/15 12:39:24 std::string()
Alexander Alekseev 2014/04/15 22:47:31 Done.
}
// static
@@ -531,7 +551,7 @@ void ServicesCustomizationDocument::OnURLFetchComplete(
}
bool ServicesCustomizationDocument::ApplyOOBECustomization() {
- // TODO(dpolukhin): apply default wallpaper, crbug.com/348136.
+ CheckAndApplyWallpaper();
SetApplied(true);
return true;
}
@@ -576,6 +596,28 @@ std::string ServicesCustomizationDocument::GetOemAppsFolderName(
return GetOemAppsFolderNameImpl(locale, *root_);
}
+// static
+base::FilePath ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir() {
Nikita (slow) 2014/04/15 12:39:24 nit: Please group static methods together, i.e. mo
Alexander Alekseev 2014/04/15 22:47:31 Done.
+ base::FilePath custom_wallpaper_dir;
+ const bool success = PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS,
+ &custom_wallpaper_dir);
+ DCHECK(success);
Daniel Erat 2014/04/15 03:06:30 nit: this could be simplified a bit as: if (!Pa
Alexander Alekseev 2014/04/15 22:47:31 Done.
+
+ if (success)
+ return custom_wallpaper_dir.Append(kCustomizationDefaultWallpaperDir);
+
+ return custom_wallpaper_dir;
+}
+
+// static
+base::FilePath
+ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName() {
+ const base::FilePath dir = GetCustomizedWallpaperCacheDir();
+ if (dir.empty())
+ return dir;
Nikita (slow) 2014/04/15 12:39:24 nit: NOTREACHED()
Alexander Alekseev 2014/04/15 22:47:31 Done.
+ return dir.Append(kCustomizationDefaultWallpaperDownloadedFile);
+}
+
scoped_ptr<base::DictionaryValue>
ServicesCustomizationDocument::GetDefaultAppsInProviderFormat(
const base::DictionaryValue& root) {
@@ -675,4 +717,111 @@ void ServicesCustomizationDocument::ShutdownForTesting() {
g_test_services_customization_document = NULL;
}
+void ServicesCustomizationDocument::StartOEMWallpaperDownload(
+ const GURL& wallpaper_url) {
+ DCHECK(wallpaper_url.is_valid());
+
+ const base::FilePath dir = GetCustomizedWallpaperCacheDir();
+ const base::FilePath file = GetCustomizedWallpaperDownloadedFileName();
+ if (dir.empty() || file.empty())
+ return;
Nikita (slow) 2014/04/15 12:39:24 NOTREACHED()
Alexander Alekseev 2014/04/15 22:47:31 Done.
+
+ wallpaper_downloader_.reset(new CustomizationWallpaperDownloader(
+ g_browser_process->system_request_context(),
+ wallpaper_url,
+ dir,
+ file,
+ base::Bind(
+ &ServicesCustomizationDocument::OnCustomizedWallpaperDownloaded,
+ weak_ptr_factory_.GetWeakPtr())));
+
+ wallpaper_downloader_->Start();
+}
+
+void ServicesCustomizationDocument::CheckAndApplyWallpaper() {
+ if (wallpaper_downloader_.get()) {
+ VLOG(1) << "CheckAndApplyWallpaper(): download has already started.";
+ return;
+ }
+ GURL wallpaper_url = GetDefaultWallpaperUrl();
+ // Should fail if this ever happens in tests.
Nikita (slow) 2014/04/15 12:39:24 nit: Insert empty line before comment.
Alexander Alekseev 2014/04/15 22:47:31 Done.
+ DCHECK(wallpaper_url.is_valid());
+ if (!wallpaper_url.is_valid()) {
+ if (!wallpaper_url.is_empty()) {
Daniel Erat 2014/04/15 03:06:30 nit: omit curly brackets here since the statement
Alexander Alekseev 2014/04/15 22:47:31 Now it occupies two lines ;-)
+ LOG(WARNING) << "Invalid Customized Wallpaper URL.";
Daniel Erat 2014/04/15 03:06:30 include wallpaper_url.spec() in this message to ai
Alexander Alekseev 2014/04/15 22:47:31 Done.
+ }
+ return;
+ }
+ scoped_ptr<bool> exists(new bool(false));
+
+ base::Closure check_file_exists =
+ base::Bind(&CheckWallpaperCacheExists,
+ GetCustomizedWallpaperDownloadedFileName(),
+ base::Unretained(exists.get()));
+ base::Closure on_checked_closure =
+ base::Bind(&ServicesCustomizationDocument::OnCheckedWallpaperCacheExists,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Passed(exists.Pass()));
+ if (!content::BrowserThread::PostBlockingPoolTaskAndReply(
+ FROM_HERE, check_file_exists, on_checked_closure)) {
+ LOG(WARNING) << "Failed to start check Wallpaper cache exists.";
+ }
+}
+
+void ServicesCustomizationDocument::OnCheckedWallpaperCacheExists(
+ scoped_ptr<bool> exists) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK(exists.get());
+
+ ApplyWallpaper(*exists);
+}
+
+void ServicesCustomizationDocument::ApplyWallpaper(
+ bool default_wallpaper_file_exists) {
+ GURL wallpaper_url = GetDefaultWallpaperUrl();
+ DCHECK(wallpaper_url.is_valid());
+
+ PrefService* pref_service = g_browser_process->local_state();
+
+ std::string current_url =
+ pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL);
+ if (current_url != wallpaper_url.spec()) {
+ VLOG(1) << "ServicesCustomizationDocument::ApplyWallpaper() : "
+ << "Wallpaper URL in customization document '"
+ << wallpaper_url.spec() << "' differs from current '" << current_url
+ << "'."
+ << (GURL(current_url).is_valid() && default_wallpaper_file_exists
+ ? " Ignored."
+ : " Will refetch.");
+ }
+ // Never update system-wide wallpaper (i.e. do not check
+ // current_url == wallpaper_url.spec() )
+ if (GURL(current_url).is_valid() && default_wallpaper_file_exists) {
+ VLOG(1)
+ << "ServicesCustomizationDocument::ApplyWallpaper() : reuse existing";
+ OnCustomizedWallpaperDownloaded(true, GURL(current_url));
+ } else {
+ VLOG(1)
+ << "ServicesCustomizationDocument::ApplyWallpaper() : start download";
+ StartOEMWallpaperDownload(wallpaper_url);
+ }
+}
+
+void ServicesCustomizationDocument::OnCustomizedWallpaperDownloaded(
+ bool success,
+ const GURL& wallpaper_url) {
+ if (success) {
+ DCHECK(wallpaper_url.is_valid());
Daniel Erat 2014/04/15 03:06:30 everything in this block needs to be indented two
Alexander Alekseev 2014/04/15 22:47:31 Done.
+
+ VLOG(1) << "Setting default wallpaper to '"
+ << GetCustomizedWallpaperDownloadedFileName().value() << "' ('"
+ << wallpaper_url.spec() << "')";
+ WallpaperManager::Get()->SetCustomizedDefaultWallpaper(
+ wallpaper_url,
+ GetCustomizedWallpaperDownloadedFileName(),
+ GetCustomizedWallpaperCacheDir());
+ }
+ wallpaper_downloader_.reset();
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698