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..0325ce552d80e8b51cb48a76fef6cc4773d05f6b |
--- /dev/null |
+++ b/chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnails_source2.cc |
@@ -0,0 +1,86 @@ |
+// 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_thumbnail_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_"; |
+ |
+bool ParseIndexFromPath(const std::string& path, int* index) { |
+ DCHECK(index); |
+ if (!StartsWithASCII(path, kDefaultWallpaperPrefix, false)) |
+ return false; |
+ return base::StringToInt(base::StringPiece(path.begin() + |
+ strlen(kDefaultWallpaperPrefix), path.end()), index); |
+} |
+ |
+int PathToIDR(const std::string& path) { |
+ int idr = -1; |
+ int index = ash::GetInvalidWallpaperIndex(); |
+ if (ParseIndexFromPath(path, &index)) |
+ idr = ash::GetWallpaperInfo(index).thumb_id; |
+ return idr; |
+} |
+ |
+} // namespace |
+ |
+std::string GetDefaultWallpaperThumbnailURL(int index) { |
+ return StringPrintf("%s%s%d", chrome::kChromeUIWallpaperThumbnailURL, |
+ kDefaultWallpaperPrefix, index); |
+} |
+ |
+bool IsDefaultWallpaperURL(const std::string url, int* wallpaper_index) { |
+ DCHECK(wallpaper_index); |
+ *wallpaper_index = ash::GetInvalidWallpaperIndex(); |
+ if (!StartsWithASCII(url, chrome::kChromeUIWallpaperThumbnailURL, false)) |
+ return false; |
+ std::string sub_path = url.substr(strlen( |
flackr
2012/04/19 20:13:07
I'm fairly certain StringPiece avoids constructing
bshe
2012/04/19 21:05:25
It seems the StartsWithASCII function use std:stri
flackr
2012/04/20 00:16:50
bool BasicStringPiece::starts_with should work :).
bshe
2012/04/20 15:33:00
As discussed, StartsWithASCII does a case insensit
|
+ chrome::kChromeUIWallpaperThumbnailURL)); |
+ return ParseIndexFromPath(sub_path, wallpaper_index); |
+} |
+ |
+WallpaperThumbnailSource::WallpaperThumbnailSource() |
+ : DataSource(chrome::kChromeUIWallpaperThumbnailHost, NULL) { |
+} |
+ |
+WallpaperThumbnailSource::~WallpaperThumbnailSource() { |
+} |
+ |
+void WallpaperThumbnailSource::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 WallpaperThumbnailSource::GetMimeType(const std::string&) const { |
+ return "images/png"; |
+} |
+ |
+} // namespace options2 |
+} // namespace chromeos |