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

Unified Diff: chrome/browser/chromeos/customization_document.cc

Issue 208273005: If customization includes default wallpaper, download and apply it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Start customization manifest fetch on EULA accepted. Never re-fetch wallpaper. Created 6 years, 9 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 99d7d82bff3edf4999734377bcece14d89c73016..888164f110a80b0602f7732389ee1cd1adc876f2 100644
--- a/chrome/browser/chromeos/customization_document.cc
+++ b/chrome/browser/chromeos/customization_document.cc
@@ -12,6 +12,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"
@@ -20,6 +21,8 @@
#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/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"
@@ -27,7 +30,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"
@@ -64,6 +69,12 @@ const char kAcceptedManifestVersion[] = "1.0";
const char kStartupCustomizationManifestPath[] =
"/opt/oem/etc/startup_manifest.json";
+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.
+
+// The original downloaded image file is stored under this name.
+static const char kCustomizationDefaultWallpaperDownloadedFile[] =
+ "default.downloaded";
bshe 2014/03/24 21:30:49 ditto
Alexander Alekseev 2014/03/25 14:38:29 Done.
+
// Name of local state option that tracks if services customization has been
// applied.
const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied";
@@ -123,6 +134,12 @@ std::string GetLocaleSpecificStringImpl(
return std::string();
}
+void CheckWallpaperCacheExists(const base::FilePath& path, bool* exists) {
+ 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
+ DCHECK(exists);
+ *exists = base::PathExists(path);
+}
+
} // anonymous namespace
namespace chromeos {
@@ -356,6 +373,7 @@ ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() {
void ServicesCustomizationDocument::RegisterPrefs(
PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kServicesCustomizationAppliedPref, false);
+ registry->RegisterStringPref(prefs::kCustomizationDefaultWallpaperURL, "");
}
// static
@@ -516,8 +534,129 @@ void ServicesCustomizationDocument::OnURLFetchComplete(
fetch_started_ = false;
}
+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()) {
+ wallpaper_downloader_.reset(new CustomizationWallpaperDownloader(
+ g_browser_process->system_request_context(), wallpaper_url, dir, file));
+
+ wallpaper_downloader_->Start();
+ }
+}
+
+// static
+base::FilePath ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir() {
+ base::FilePath custom_wallpaper_dir;
+ const bool success = PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS,
+ &custom_wallpaper_dir);
+ 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
+
+ if (success)
+ return custom_wallpaper_dir.Append(kCustomizationDefaultWallpaperDir);
+
+ return custom_wallpaper_dir;
+}
+
+// static
+base::FilePath
+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
+ const base::FilePath dir = GetCustomizedWallpaperCacheDir();
+ if (dir.empty())
+ return dir;
+ return dir.Append(kCustomizationDefaultWallpaperDownloadedFile);
+}
+
+// static
+void ServicesCustomizationDocument::SetDefaultWallpaperPath(
+ const GURL& wallpaper_url) {
+ DCHECK(wallpaper_url.is_valid());
+
+ VLOG(1) << "Setting default wallpaper to '"
+ << GetCustomizedWallpaperDownloadedFileName().value() << "' ('"
+ << wallpaper_url.spec() << "')";
+ WallpaperManager::Get()->SetCustomizedDefaultWallpaper(
+ wallpaper_url,
+ GetCustomizedWallpaperDownloadedFileName(),
+ GetCustomizedWallpaperCacheDir());
+}
+
+// static
+void ServicesCustomizationDocument::DestroyWallpaperDownloader() {
+ ServicesCustomizationDocument* self =
+ ServicesCustomizationDocument::GetInstance();
+ DCHECK(self);
+ self->wallpaper_downloader_.reset();
+}
+
+void ServicesCustomizationDocument::ApplyWallpaper(
+ bool default_wallpaper_file_exists) {
+ GURL wallpaper_url = GetDefaultWallpaperUrl();
+ DCHECK(wallpaper_url.is_valid());
+
+ PrefService* prefService = g_browser_process->local_state();
+ 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.
+
+ std::string current_url =
+ prefService->GetString(prefs::kCustomizationDefaultWallpaperURL);
+ if (current_url != wallpaper_url.spec()) {
+ 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
+ << "Wallpaper URL in customization document '"
+ << wallpaper_url.spec() << "' differs from current '" << current_url
+ << "'. Ignored.";
+ }
+ // Never update system-wide wallpaper (i.e. do not check
+ // 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
+ if (GURL(current_url).is_valid() && default_wallpaper_file_exists) {
+ VLOG(1)
+ << "ServicesCustomizationDocument::ApplyWallpaper() : reuse existing";
+ 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
+ } else {
+ VLOG(1)
+ << "ServicesCustomizationDocument::ApplyWallpaper() : start download";
+ StartOEMWallpaperDownload(wallpaper_url);
+ }
+}
+
+void ServicesCustomizationDocument::OnCheckedWallpaperCacheExists(
+ scoped_ptr<bool> exists) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK(exists.get());
+
+ ApplyWallpaper(*exists);
+}
+
+void ServicesCustomizationDocument::CheckAndApplyWallpaper() {
+ GURL wallpaper_url = GetDefaultWallpaperUrl();
+ // Should fail if this ever happens in tests.
+ DCHECK(wallpaper_url.is_valid() || wallpaper_url.is_empty());
+ if (!wallpaper_url.is_valid()) {
+ if (!wallpaper_url.is_empty()) {
+ LOG(WARNING) << "Invalid Customized Wallpaper URL.";
+ }
+ 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.";
+ }
+}
+
bool ServicesCustomizationDocument::ApplyOOBECustomization() {
- // TODO(dpolukhin): apply default wallpaper, crbug.com/348136.
+ CheckAndApplyWallpaper();
SetApplied(true);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698