| Index: chrome/browser/chromeos/customization_document.cc
|
| diff --git a/chrome/browser/chromeos/customization_document.cc b/chrome/browser/chromeos/customization_document.cc
|
| index b5cce96203c8f6f41b8ad47724691ec59a37dcac..5ad6628ee74cef149d58c0a429a9106a63c12b6e 100644
|
| --- a/chrome/browser/chromeos/customization_document.cc
|
| +++ b/chrome/browser/chromeos/customization_document.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/json/json_reader.h"
|
| #include "base/logging.h"
|
| #include "base/memory/weak_ptr.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"
|
| @@ -19,11 +20,15 @@
|
| #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/extensions/external_loader.h"
|
| #include "chrome/browser/extensions/external_provider_impl.h"
|
| #include "chrome/browser/profiles/profile.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"
|
| @@ -57,6 +62,12 @@ const char kAcceptedManifestVersion[] = "1.0";
|
| const char kStartupCustomizationManifestPath[] =
|
| "/opt/oem/etc/startup_manifest.json";
|
|
|
| +static const char kCustomizationDefaultWallpaperDir[] = "customization/";
|
| +
|
| +// The original downloaded image file is stored under this name.
|
| +static const char kCustomizationDefaultWallpaperDownloadedFile[] =
|
| + "default.downloaded";
|
| +
|
| // Name of local state option that tracks if services customization has been
|
| // applied.
|
| const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied";
|
| @@ -70,6 +81,12 @@ const int kRetriesDelayInSec = 2;
|
| // Name of profile option that tracks cached version of service customization.
|
| const char kServicesCustomizationKey[] = "customization.manifest_cache";
|
|
|
| +void CheckWallpaperCacheExists(const base::FilePath& path, bool* exists) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
|
| + DCHECK(exists);
|
| + *exists = base::PathExists(path);
|
| +}
|
| +
|
| } // anonymous namespace
|
|
|
| namespace chromeos {
|
| @@ -294,12 +311,13 @@ std::string StartupCustomizationDocument::GetEULAPage(
|
| ServicesCustomizationDocument::ServicesCustomizationDocument()
|
| : CustomizationDocument(kAcceptedManifestVersion),
|
| num_retries_(0),
|
| - fetch_started_(false) {
|
| + fetch_started_(false),
|
| + weak_factory_(this) {
|
| }
|
|
|
| ServicesCustomizationDocument::ServicesCustomizationDocument(
|
| const std::string& manifest)
|
| - : CustomizationDocument(kAcceptedManifestVersion) {
|
| + : CustomizationDocument(kAcceptedManifestVersion), weak_factory_(this) {
|
| LoadManifestFromString(manifest);
|
| }
|
|
|
| @@ -315,6 +333,7 @@ ServicesCustomizationDocument* ServicesCustomizationDocument::GetInstance() {
|
| void ServicesCustomizationDocument::RegisterPrefs(
|
| PrefRegistrySimple* registry) {
|
| registry->RegisterBooleanPref(kServicesCustomizationAppliedPref, false);
|
| + registry->RegisterStringPref(prefs::kCustomizationDefaultWallpaperURL, "");
|
| }
|
|
|
| // static
|
| @@ -457,8 +476,122 @@ void ServicesCustomizationDocument::OnURLFetchComplete(
|
| }
|
| }
|
|
|
| +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);
|
| +
|
| + 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;
|
| + 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);
|
| +
|
| + std::string current_url =
|
| + prefService->GetString(prefs::kCustomizationDefaultWallpaperURL);
|
| + if ((current_url != wallpaper_url.spec()) ||
|
| + (!default_wallpaper_file_exists)) {
|
| + VLOG(1)
|
| + << "ServicesCustomizationDocument::ApplyWallpaper() : start download";
|
| + StartOEMWallpaperDownload(wallpaper_url);
|
| + } else {
|
| + VLOG(1)
|
| + << "ServicesCustomizationDocument::ApplyWallpaper() : reuse existing";
|
| + SetDefaultWallpaperPath(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_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.
|
| + CheckAndApplyWallpaper();
|
| SetApplied(true);
|
| return true;
|
| }
|
|
|