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

Unified Diff: chrome/browser/ui/webui/options2/chromeos/user_image_source.cc

Issue 8895023: Options2: Pull the trigger. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DIAF. Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options2/chromeos/user_image_source.cc
diff --git a/chrome/browser/ui/webui/options2/chromeos/user_image_source.cc b/chrome/browser/ui/webui/options2/chromeos/user_image_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f259c03adc626201cd7e78d00c67c27d4d077f6c
--- /dev/null
+++ b/chrome/browser/ui/webui/options2/chromeos/user_image_source.cc
@@ -0,0 +1,53 @@
+// 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/user_image_source.h"
+
+#include "base/memory/ref_counted_memory.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/common/url_constants.h"
+#include "grit/theme_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/codec/png_codec.h"
+
+namespace chromeos {
+
+std::vector<unsigned char> UserImageSource::GetUserImage(
+ const std::string& email) const {
+ std::vector<unsigned char> user_image;
+ const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
+ if (user) {
+ gfx::PNGCodec::EncodeBGRASkBitmap(user->image(), false, &user_image);
+ return user_image;
+ }
+ gfx::PNGCodec::EncodeBGRASkBitmap(
+ *ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_LOGIN_DEFAULT_USER),
+ false,
+ &user_image);
+ return user_image;
+}
+
+UserImageSource::UserImageSource()
+ : DataSource(chrome::kChromeUIUserImageHost, MessageLoop::current()) {
+}
+
+UserImageSource::~UserImageSource() {}
+
+void UserImageSource::StartDataRequest(const std::string& path,
+ bool is_incognito,
+ int request_id) {
+ // Strip the query param value - we only use it as a hack to ensure our
+ // image gets reloaded instead of being pulled from the browser cache
+ std::string email = path.substr(0, path.find_first_of("?"));
+ SendResponse(request_id, new RefCountedBytes(GetUserImage(email)));
+}
+
+std::string UserImageSource::GetMimeType(const std::string&) const {
+ // We need to explicitly return a mime type, otherwise if the user tries to
+ // drag the image they get no extension.
+ return "image/png";
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698