Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" | |
| 6 | |
| 7 #include "base/memory/weak_ptr.h" | |
| 8 #import "chrome/browser/ui/cocoa/passwords/credential_item_view.h" | |
| 9 #include "chrome/browser/ui/passwords/account_avatar_fetcher.h" | |
| 10 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | |
| 11 #include "ui/gfx/image/image_skia.h" | |
| 12 #include "ui/gfx/image/image_skia_util_mac.h" | |
| 13 | |
| 14 class AccountAvatarFetcherBridge; | |
| 15 | |
| 16 @interface AccountAvatarFetcherManager() | |
| 17 - (void)updateAvatar:(NSImage*)image | |
| 18 fromBridge:(AccountAvatarFetcherBridge*)bridge | |
| 19 forView:(CredentialItemView*)view; | |
| 20 @end | |
| 21 | |
| 22 class AccountAvatarFetcherBridge | |
| 23 : public AccountAvatarFetcherDelegate, | |
| 24 public base::SupportsWeakPtr<AccountAvatarFetcherBridge> { | |
| 25 public: | |
| 26 AccountAvatarFetcherBridge(AccountAvatarFetcherManager* manager, | |
| 27 CredentialItemView* view); | |
| 28 virtual ~AccountAvatarFetcherBridge(); | |
| 29 | |
| 30 // AccountAvatarFetcherDelegate: | |
| 31 void UpdateAvatar(const gfx::ImageSkia& image) override; | |
| 32 | |
| 33 private: | |
| 34 AccountAvatarFetcherManager* manager_; | |
| 35 CredentialItemView* view_; | |
| 36 }; | |
| 37 | |
| 38 AccountAvatarFetcherBridge::AccountAvatarFetcherBridge( | |
| 39 AccountAvatarFetcherManager* manager, | |
| 40 CredentialItemView* view) | |
| 41 : manager_(manager), view_(view) { | |
| 42 } | |
| 43 | |
| 44 AccountAvatarFetcherBridge::~AccountAvatarFetcherBridge() = default; | |
| 45 | |
| 46 void AccountAvatarFetcherBridge::UpdateAvatar(const gfx::ImageSkia& image) { | |
| 47 [manager_ | |
| 48 updateAvatar:gfx::NSImageFromImageSkia(ScaleImageForAccountAvatar(image)) | |
| 49 fromBridge:this | |
| 50 forView:view_]; | |
| 51 } | |
| 52 | |
| 53 @implementation AccountAvatarFetcherManager | |
| 54 | |
| 55 - (id)initWithRequestContext: | |
| 56 (scoped_refptr<net::URLRequestContextGetter>)requestContext { | |
| 57 if ((self = [super init])) { | |
| 58 requestContext_ = requestContext; | |
| 59 } | |
| 60 return self; | |
| 61 } | |
| 62 | |
| 63 - (void)startRequestWithFetcher:(AccountAvatarFetcher*)fetcher { | |
| 64 fetcher->Start(requestContext_.get()); | |
| 65 } | |
| 66 | |
| 67 - (void)fetchAvatar:(const GURL&)avatarURL forView:(CredentialItemView*)view { | |
| 68 scoped_ptr<AccountAvatarFetcherBridge> bridge( | |
| 69 new AccountAvatarFetcherBridge(self, view)); | |
| 70 AccountAvatarFetcher* fetcher = | |
| 71 new AccountAvatarFetcher(avatarURL, bridge->AsWeakPtr()); | |
| 72 bridges_.push_back(bridge.Pass()); | |
| 73 [self startRequestWithFetcher:fetcher]; | |
| 74 } | |
| 75 | |
| 76 - (void)updateAvatar:(NSImage*)image | |
| 77 fromBridge:(AccountAvatarFetcherBridge*)bridge | |
| 78 forView:(CredentialItemView*)view { | |
| 79 [view updateAvatar:image]; | |
| 80 auto it = std::find(bridges_.begin(), bridges_.end(), bridge); | |
|
dconnelly
2015/02/19 10:37:12
It turns out the std::erase(std::remove(bridges_.b
groby-ooo-7-16
2015/02/19 17:07:20
Sigh. Bitten by both scopedness and STL annoyingne
| |
| 81 if (it != bridges_.end()) | |
| 82 bridges_.erase(it); | |
| 83 } | |
| 84 | |
| 85 @end | |
| OLD | NEW |