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

Unified Diff: chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.mm

Issue 864963004: Implement an ObjC wrapper for fetching account chooser avatar images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.mm
diff --git a/chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.mm b/chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.mm
new file mode 100644
index 0000000000000000000000000000000000000000..618b78220bff65b999e7f6b5fef1789ef6fa91be
--- /dev/null
+++ b/chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.mm
@@ -0,0 +1,85 @@
+// Copyright 2015 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.
+
+#import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h"
+
+#include "base/memory/weak_ptr.h"
+#import "chrome/browser/ui/cocoa/passwords/credential_item_view.h"
+#include "chrome/browser/ui/passwords/account_avatar_fetcher.h"
+#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_skia_util_mac.h"
+
+class AccountAvatarFetcherBridge;
+
+@interface AccountAvatarFetcherManager()
+- (void)updateAvatar:(NSImage*)image
+ fromBridge:(AccountAvatarFetcherBridge*)bridge
+ forView:(CredentialItemView*)view;
+@end
+
+class AccountAvatarFetcherBridge
+ : public AccountAvatarFetcherDelegate,
+ public base::SupportsWeakPtr<AccountAvatarFetcherBridge> {
+ public:
+ AccountAvatarFetcherBridge(AccountAvatarFetcherManager* manager,
+ CredentialItemView* view);
+ virtual ~AccountAvatarFetcherBridge();
+
+ // AccountAvatarFetcherDelegate:
+ void UpdateAvatar(const gfx::ImageSkia& image) override;
+
+ private:
+ AccountAvatarFetcherManager* manager_;
+ CredentialItemView* view_;
+};
+
+AccountAvatarFetcherBridge::AccountAvatarFetcherBridge(
+ AccountAvatarFetcherManager* manager,
+ CredentialItemView* view)
+ : manager_(manager), view_(view) {
+}
+
+AccountAvatarFetcherBridge::~AccountAvatarFetcherBridge() = default;
+
+void AccountAvatarFetcherBridge::UpdateAvatar(const gfx::ImageSkia& image) {
+ [manager_
+ updateAvatar:gfx::NSImageFromImageSkia(ScaleImageForAccountAvatar(image))
+ fromBridge:this
+ forView:view_];
+}
+
+@implementation AccountAvatarFetcherManager
+
+- (id)initWithRequestContext:
+ (scoped_refptr<net::URLRequestContextGetter>)requestContext {
+ if ((self = [super init])) {
+ requestContext_ = requestContext;
+ }
+ return self;
+}
+
+- (void)startRequestWithFetcher:(AccountAvatarFetcher*)fetcher {
+ fetcher->Start(requestContext_.get());
+}
+
+- (void)fetchAvatar:(const GURL&)avatarURL forView:(CredentialItemView*)view {
+ scoped_ptr<AccountAvatarFetcherBridge> bridge(
+ new AccountAvatarFetcherBridge(self, view));
+ AccountAvatarFetcher* fetcher =
+ new AccountAvatarFetcher(avatarURL, bridge->AsWeakPtr());
+ bridges_.push_back(bridge.Pass());
+ [self startRequestWithFetcher:fetcher];
+}
+
+- (void)updateAvatar:(NSImage*)image
+ fromBridge:(AccountAvatarFetcherBridge*)bridge
+ forView:(CredentialItemView*)view {
+ [view updateAvatar:image];
+ auto it = std::find(bridges_.begin(), bridges_.end(), bridge);
groby-ooo-7-16 2015/02/12 01:07:57 You could simplify the three lines to bridges_.era
dconnelly 2015/02/17 10:17:47 Done.
+ if (it != bridges_.end())
+ bridges_.erase(it);
+}
+
+@end
« no previous file with comments | « chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698