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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/user_image_source.cc

Issue 11881055: Simplify WebUI data sources. Currently WebUI data sources implement a URLDataSourceDelegate interfa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix issue in about_ui exposed by cros tests Created 7 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" 5 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "chrome/browser/chromeos/login/default_user_images.h" 10 #include "chrome/browser/chromeos/login/default_user_images.h"
11 #include "chrome/browser/chromeos/login/user_manager.h" 11 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
13 #include "chrome/browser/ui/webui/web_ui_util.h" 12 #include "chrome/browser/ui/webui/web_ui_util.h"
14 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
15 #include "googleurl/src/url_parse.h" 14 #include "googleurl/src/url_parse.h"
16 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
17 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/codec/png_codec.h" 17 #include "ui/gfx/codec/png_codec.h"
19 18
20 namespace { 19 namespace {
21 20
22 // Animated key is used in user image URL requests to specify that 21 // Animated key is used in user image URL requests to specify that
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 78
80 UserImageSource::UserImageSource() { 79 UserImageSource::UserImageSource() {
81 } 80 }
82 81
83 UserImageSource::~UserImageSource() {} 82 UserImageSource::~UserImageSource() {}
84 83
85 std::string UserImageSource::GetSource() { 84 std::string UserImageSource::GetSource() {
86 return chrome::kChromeUIUserImageHost; 85 return chrome::kChromeUIUserImageHost;
87 } 86 }
88 87
89 void UserImageSource::StartDataRequest(const std::string& path, 88 void UserImageSource::StartDataRequest(
90 bool is_incognito, 89 const std::string& path,
91 int request_id) { 90 bool is_incognito,
91 const content::URLDataSource::GotDataCallback& callback) {
92 std::string email; 92 std::string email;
93 bool is_image_animated = false; 93 bool is_image_animated = false;
94 ui::ScaleFactor scale_factor; 94 ui::ScaleFactor scale_factor;
95 GURL url(chrome::kChromeUIUserImageURL + path); 95 GURL url(chrome::kChromeUIUserImageURL + path);
96 ParseRequest(url, &email, &is_image_animated, &scale_factor); 96 ParseRequest(url, &email, &is_image_animated, &scale_factor);
97 url_data_source()->SendResponse( 97 callback.Run(GetUserImage(email, is_image_animated, scale_factor));
98 request_id,
99 GetUserImage(email, is_image_animated, scale_factor));
100 } 98 }
101 99
102 std::string UserImageSource::GetMimeType(const std::string& path) const { 100 std::string UserImageSource::GetMimeType(const std::string& path) const {
103 // We need to explicitly return a mime type, otherwise if the user tries to 101 // We need to explicitly return a mime type, otherwise if the user tries to
104 // drag the image they get no extension. 102 // drag the image they get no extension.
105 std::string email; 103 std::string email;
106 bool is_image_animated = false; 104 bool is_image_animated = false;
107 ui::ScaleFactor scale_factor; 105 ui::ScaleFactor scale_factor;
108 106
109 GURL url(chrome::kChromeUIUserImageURL + path); 107 GURL url(chrome::kChromeUIUserImageURL + path);
110 ParseRequest(url, &email, &is_image_animated, &scale_factor); 108 ParseRequest(url, &email, &is_image_animated, &scale_factor);
111 109
112 if (is_image_animated) { 110 if (is_image_animated) {
113 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); 111 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
114 if (user && user->has_animated_image()) 112 if (user && user->has_animated_image())
115 return "image/gif"; 113 return "image/gif";
116 } 114 }
117 return "image/png"; 115 return "image/png";
118 } 116 }
119 117
120 } // namespace options 118 } // namespace options
121 } // namespace chromeos 119 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698