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

Side by Side Diff: chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2.cc

Issue 10021066: Replace the index mapping of wallpaper picker UI and hard coded wallpaper index in C++ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2. h"
6
7 #include "ash/desktop_background/desktop_background_resources.h"
8 #include "base/memory/singleton.h"
9 #include "base/string_number_conversions.h"
10 #include "base/string_piece.h"
11 #include "base/string_util.h"
12 #include "base/stringprintf.h"
13 #include "base/threading/thread_restrictions.h"
14 #include "chrome/browser/io_thread.h"
15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "grit/ui_resources.h"
19 #include "net/base/mime_util.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/codec/png_codec.h"
22
23 namespace chromeos {
24 namespace options2 {
25
26 namespace {
27
28 const char kDefaultWallpaperPrefix[] = "default_";
29
30 bool ParseIndexFromPath(const std::string& path, int* index) {
James Hawkins 2012/04/20 19:40:17 Document method.
bshe 2012/04/20 21:11:43 Done.
31 // TODO(bshe): We should probably save a string instead of index for
32 // extensibility. Remove this function when we migrate to string preference.
33 DCHECK(index);
34 if (!StartsWithASCII(path, kDefaultWallpaperPrefix, false))
35 return false;
36 return base::StringToInt(base::StringPiece(path.begin() +
37 strlen(kDefaultWallpaperPrefix), path.end()), index);
38 }
39
40 int PathToIDR(const std::string& path) {
James Hawkins 2012/04/20 19:40:17 Document method.
bshe 2012/04/20 21:11:43 Done.
41 int idr = -1;
42 int index = ash::GetInvalidWallpaperIndex();
43 if (ParseIndexFromPath(path, &index))
44 idr = ash::GetWallpaperInfo(index).thumb_id;
45 return idr;
46 }
47
48 } // namespace
49
50 std::string GetDefaultWallpaperThumbnailURL(int index) {
51 return StringPrintf("%s%s%d", chrome::kChromeUIWallpaperThumbnailURL,
52 kDefaultWallpaperPrefix, index);
53 }
54
55 bool IsDefaultWallpaperURL(const std::string url, int* wallpaper_index) {
56 DCHECK(wallpaper_index);
57 *wallpaper_index = ash::GetInvalidWallpaperIndex();
58 if (!StartsWithASCII(url, chrome::kChromeUIWallpaperThumbnailURL, false))
59 return false;
60 std::string sub_path = url.substr(strlen(
61 chrome::kChromeUIWallpaperThumbnailURL));
62 return ParseIndexFromPath(sub_path, wallpaper_index);
63 }
64
65 WallpaperThumbnailSource::WallpaperThumbnailSource()
66 : DataSource(chrome::kChromeUIWallpaperThumbnailHost, NULL) {
67 }
68
69 WallpaperThumbnailSource::~WallpaperThumbnailSource() {
70 }
71
72 void WallpaperThumbnailSource::StartDataRequest(const std::string& path,
73 bool is_incognito,
74 int request_id) {
75 int idr = PathToIDR(path);
76 if (idr != -1) {
77 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
78 const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
79 SendResponse(request_id, rb.LoadDataResourceBytes(idr));
80 }
81 }
82
83 std::string WallpaperThumbnailSource::GetMimeType(const std::string&) const {
84 return "images/png";
85 }
86
87 } // namespace options2
88 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698