Index: chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnails_source2.cc |
diff --git a/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnails_source2.cc b/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnails_source2.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..15061adca04b1c41abc8cf97bac76fd06b403929 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnails_source2.cc |
@@ -0,0 +1,89 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnails_source2.h" |
+ |
+#include "ash/desktop_background/desktop_background_resources.h" |
+#include "base/memory/singleton.h" |
+#include "base/string_number_conversions.h" |
+#include "base/string_piece.h" |
+#include "base/string_util.h" |
+#include "base/stringprintf.h" |
+#include "base/threading/thread_restrictions.h" |
+#include "chrome/browser/io_thread.h" |
+#include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
+#include "chrome/common/url_constants.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "grit/ui_resources.h" |
+#include "net/base/mime_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/codec/png_codec.h" |
+ |
+namespace chromeos { |
+namespace options2 { |
+ |
+namespace { |
+ |
+const char kDefaultWallpaperPrefix[] = "default_"; |
+ |
+int PathToIDR(const std::string& path) { |
+ int idr = -1; |
+ if (!StartsWithASCII(path, kDefaultWallpaperPrefix, false)) |
+ return idr; |
+ int index; |
+ if (base::StringToInt(base::StringPiece(path.begin() + |
flackr
2012/04/18 20:16:34
Should be able to use
if (base::StringToInt(path.s
bshe
2012/04/19 00:15:57
It seems base::StringToInt only takes base::String
flackr
2012/04/19 20:13:07
If this is an established pattern that's okay. It
|
+ strlen(kDefaultWallpaperPrefix), path.end()), &index)) |
+ idr = ash::GetWallpaperInfo(index).thumb_id; |
+ return idr; |
+} |
+ |
+} // namespace |
+ |
+std::string GetDefaultWallpaperThumbnailURL(int index) { |
+ return StringPrintf("%s%s%d", chrome::kChromeUIWallpaperThumbnailsURL, |
+ kDefaultWallpaperPrefix, index); |
+} |
+ |
+bool IsDefaultWallpaperURL(const std::string url, int* wallpaper_index) { |
flackr
2012/04/18 20:16:34
This seems very similar to the above method with s
bshe
2012/04/19 00:15:57
Good point.
On 2012/04/18 20:16:34, flackr wrote:
|
+ DCHECK(wallpaper_index); |
+ std::string prefix(chrome::kChromeUIWallpaperThumbnailsURL); |
+ prefix += kDefaultWallpaperPrefix; |
+ if (!StartsWithASCII(url, prefix, false)) |
+ return false; |
+ |
+ int index = ash::GetInvalidWallpaperIndex(); |
+ if (base::StringToInt(base::StringPiece(url.begin() + prefix.length(), |
flackr
2012/04/18 20:16:34
You should be able to use:
if (base::StringToInt(u
|
+ url.end()), |
+ &index)) { |
+ *wallpaper_index = index; |
+ return true; |
+ } |
+ |
+ return false; |
+} |
+ |
+WallpaperThumbnailsSource::WallpaperThumbnailsSource() |
+ : DataSource(chrome::kChromeUIWallpaperThumbnailsHost, NULL) { |
+} |
+ |
+WallpaperThumbnailsSource::~WallpaperThumbnailsSource() { |
+} |
+ |
+void WallpaperThumbnailsSource::StartDataRequest(const std::string& path, |
+ bool is_incognito, |
+ int request_id) { |
+ int idr = PathToIDR(path); |
+ if (idr != -1) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
+ SendResponse(request_id, rb.LoadDataResourceBytes(idr)); |
+ } |
+} |
+ |
+std::string WallpaperThumbnailsSource::GetMimeType(const std::string&) const { |
+ return "images/png"; |
+} |
+ |
+} // namespace options2 |
+} // namespace chromeos |