OLD | NEW |
---|---|
(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_thumbnails_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 int PathToIDR(const std::string& path) { | |
31 int idr = -1; | |
32 if (!StartsWithASCII(path, kDefaultWallpaperPrefix, false)) | |
33 return idr; | |
34 int index; | |
35 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
| |
36 strlen(kDefaultWallpaperPrefix), path.end()), &index)) | |
37 idr = ash::GetWallpaperInfo(index).thumb_id; | |
38 return idr; | |
39 } | |
40 | |
41 } // namespace | |
42 | |
43 std::string GetDefaultWallpaperThumbnailURL(int index) { | |
44 return StringPrintf("%s%s%d", chrome::kChromeUIWallpaperThumbnailsURL, | |
45 kDefaultWallpaperPrefix, index); | |
46 } | |
47 | |
48 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:
| |
49 DCHECK(wallpaper_index); | |
50 std::string prefix(chrome::kChromeUIWallpaperThumbnailsURL); | |
51 prefix += kDefaultWallpaperPrefix; | |
52 if (!StartsWithASCII(url, prefix, false)) | |
53 return false; | |
54 | |
55 int index = ash::GetInvalidWallpaperIndex(); | |
56 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
| |
57 url.end()), | |
58 &index)) { | |
59 *wallpaper_index = index; | |
60 return true; | |
61 } | |
62 | |
63 return false; | |
64 } | |
65 | |
66 WallpaperThumbnailsSource::WallpaperThumbnailsSource() | |
67 : DataSource(chrome::kChromeUIWallpaperThumbnailsHost, NULL) { | |
68 } | |
69 | |
70 WallpaperThumbnailsSource::~WallpaperThumbnailsSource() { | |
71 } | |
72 | |
73 void WallpaperThumbnailsSource::StartDataRequest(const std::string& path, | |
74 bool is_incognito, | |
75 int request_id) { | |
76 int idr = PathToIDR(path); | |
77 if (idr != -1) { | |
78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
79 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
80 SendResponse(request_id, rb.LoadDataResourceBytes(idr)); | |
81 } | |
82 } | |
83 | |
84 std::string WallpaperThumbnailsSource::GetMimeType(const std::string&) const { | |
85 return "images/png"; | |
86 } | |
87 | |
88 } // namespace options2 | |
89 } // namespace chromeos | |
OLD | NEW |