Index: chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2.cc |
diff --git a/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2.cc b/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2.cc |
index 8186da8b2289512dca0210c72cb4a04f6da38249..1d8a12944b3326f229a072371a7d750a35263c84 100644 |
--- a/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2.cc |
+++ b/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2.cc |
@@ -12,6 +12,7 @@ |
#include "base/string_util.h" |
#include "base/stringprintf.h" |
#include "base/threading/thread_restrictions.h" |
+#include "chrome/browser/chromeos/login/user_manager.h" |
#include "chrome/browser/io_thread.h" |
#include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
#include "chrome/common/url_constants.h" |
@@ -27,6 +28,7 @@ namespace options2 { |
namespace { |
const char kDefaultWallpaperPrefix[] = "default_"; |
+const char kCustomWallpaperPrefix[] = "custom_"; |
// Parse an integer from |path| and save it to |index|. For example, deafult_20 |
// will set |index| to 20. |
@@ -51,6 +53,18 @@ int PathToIDR(const std::string& path) { |
return idr; |
} |
+// True if |path| is a custom wallpaper thumbnail URL and set |email| parsed |
+// from |path|. |
+// custom url = "custom_|email|?date" where date is current time. |
+bool IsCustomWallpaperPath(const std::string& path, std::string* email) { |
+ if (!StartsWithASCII(path, kCustomWallpaperPrefix, false) || |
+ path.find_first_of("?") == std::string::npos) |
flackr
2012/05/09 21:26:16
Not having a ? doesn't mean it's definitely not a
bshe
2012/05/10 16:10:26
Done.
|
+ return false; |
+ *email = path.substr(strlen(kCustomWallpaperPrefix), |
+ path.find_first_of("?") - strlen(kCustomWallpaperPrefix)); |
flackr
2012/05/09 21:26:16
std::string::substr can take just start position,
bshe
2012/05/10 16:10:26
Done.
|
+ return true; |
+} |
+ |
} // namespace |
std::string GetDefaultWallpaperThumbnailURL(int index) { |
@@ -78,6 +92,16 @@ WallpaperThumbnailSource::~WallpaperThumbnailSource() { |
void WallpaperThumbnailSource::StartDataRequest(const std::string& path, |
bool is_incognito, |
int request_id) { |
+ std::string email; |
+ if (IsCustomWallpaperPath(path, &email)) { |
+ const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); |
+ if (user) { |
+ std::vector<unsigned char> data; |
+ gfx::PNGCodec::EncodeBGRASkBitmap(user->wallpaper_thumb(), false, &data); |
+ SendResponse(request_id, new base::RefCountedBytes(data)); |
+ return; |
+ } |
+ } |
int idr = PathToIDR(path); |
if (idr != -1) { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |