| Index: ui/app_list/cocoa/app_list_view_controller.mm
|
| diff --git a/ui/app_list/cocoa/app_list_view_controller.mm b/ui/app_list/cocoa/app_list_view_controller.mm
|
| index e464721664235ada916d2c7c999ea7b45dc75f15..ec9410b2648e92cb19d5d600d372f6e2648f8644 100644
|
| --- a/ui/app_list/cocoa/app_list_view_controller.mm
|
| +++ b/ui/app_list/cocoa/app_list_view_controller.mm
|
| @@ -6,12 +6,13 @@
|
|
|
| #include "base/mac/foundation_util.h"
|
| #include "base/strings/string_util.h"
|
| +#include "base/strings/sys_string_conversions.h"
|
| #include "skia/ext/skia_utils_mac.h"
|
| #include "ui/app_list/app_list_constants.h"
|
| #include "ui/app_list/app_list_model.h"
|
| +#include "ui/app_list/app_list_model_observer.h"
|
| #include "ui/app_list/app_list_view_delegate.h"
|
| #include "ui/app_list/signin_delegate.h"
|
| -#include "ui/app_list/signin_delegate_observer.h"
|
| #import "ui/app_list/cocoa/app_list_pager_view.h"
|
| #import "ui/app_list/cocoa/apps_grid_controller.h"
|
| #import "ui/app_list/cocoa/signin_view_controller.h"
|
| @@ -75,34 +76,44 @@ const NSTimeInterval kResultsAnimationDuration = 0.2;
|
|
|
| - (void)loadAndSetView;
|
| - (void)revealSearchResults:(BOOL)show;
|
| -- (app_list::SigninDelegate*)signinDelegate;
|
|
|
| @end
|
|
|
| namespace app_list {
|
|
|
| -class SigninDelegateObserverBridge : public SigninDelegateObserver {
|
| +class AppListModelObserverBridge : public AppListModelObserver {
|
| public:
|
| - SigninDelegateObserverBridge(AppListViewController* parent)
|
| - : parent_(parent) {
|
| - [parent_ signinDelegate]->AddObserver(this);
|
| - }
|
| -
|
| - virtual ~SigninDelegateObserverBridge() {
|
| - [parent_ signinDelegate]->RemoveObserver(this);
|
| - }
|
| + AppListModelObserverBridge(AppListViewController* parent);
|
| + virtual ~AppListModelObserverBridge();
|
|
|
| private:
|
| - // SigninDelegateObserver override:
|
| - virtual void OnSigninSuccess() OVERRIDE {
|
| - [parent_ onSigninStatusChanged];
|
| - }
|
| + // Overridden from app_list::AppListModelObserver:
|
| + virtual void OnAppListModelCurrentUserChanged() OVERRIDE;
|
| + virtual void OnAppListModelSigninStatusChanged() OVERRIDE;
|
|
|
| AppListViewController* parent_; // Weak. Owns us.
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(SigninDelegateObserverBridge);
|
| + DISALLOW_COPY_AND_ASSIGN(AppListModelObserverBridge);
|
| };
|
|
|
| +AppListModelObserverBridge::AppListModelObserverBridge(
|
| + AppListViewController* parent)
|
| + : parent_(parent) {
|
| + [[parent_ appsGridController] model]->AddObserver(this);
|
| +}
|
| +
|
| +AppListModelObserverBridge::~AppListModelObserverBridge() {
|
| + [[parent_ appsGridController] model]->RemoveObserver(this);
|
| +}
|
| +
|
| +void AppListModelObserverBridge::OnAppListModelCurrentUserChanged() {
|
| + [parent_ onSigninStatusChanged];
|
| +}
|
| +
|
| +void AppListModelObserverBridge::OnAppListModelSigninStatusChanged() {
|
| + [parent_ onSigninStatusChanged];
|
| +}
|
| +
|
| } // namespace app_list
|
|
|
| @implementation AppListViewController
|
| @@ -148,7 +159,7 @@ class SigninDelegateObserverBridge : public SigninDelegateObserver {
|
| withTestModel:(scoped_ptr<app_list::AppListModel>)newModel {
|
| if (delegate_) {
|
| // First clean up, in reverse order.
|
| - signin_observer_bridge_.reset();
|
| + app_list_model_observer_bridge_.reset();
|
| [appsSearchResultsController_ setDelegate:nil];
|
| [appsSearchBoxController_ setDelegate:nil];
|
| }
|
| @@ -158,6 +169,8 @@ class SigninDelegateObserverBridge : public SigninDelegateObserver {
|
| [appsGridController_ setModel:newModel.Pass()];
|
| [appsSearchBoxController_ setDelegate:self];
|
| [appsSearchResultsController_ setDelegate:self];
|
| + app_list_model_observer_bridge_.reset(
|
| + new app_list::AppListModelObserverBridge(self));
|
| [self onSigninStatusChanged];
|
| }
|
|
|
| @@ -309,6 +322,16 @@ class SigninDelegateObserverBridge : public SigninDelegateObserver {
|
| return [appsGridController_ model];
|
| }
|
|
|
| +- (NSString*)currentUserName {
|
| + return base::SysUTF16ToNSString(
|
| + [appsGridController_ model]->current_user_name());
|
| +}
|
| +
|
| +- (NSString*)currentUserEmail {
|
| + return base::SysUTF16ToNSString(
|
| + [appsGridController_ model]->current_user_email());
|
| +}
|
| +
|
| - (void)openResult:(app_list::SearchResult*)result {
|
| if (delegate_)
|
| delegate_->OpenSearchResult(result, 0 /* event flags */);
|
| @@ -318,11 +341,15 @@ class SigninDelegateObserverBridge : public SigninDelegateObserver {
|
|
|
| - (void)onSigninStatusChanged {
|
| [appsSearchBoxController_ rebuildMenu];
|
| - app_list::SigninDelegate* signinDelegate = [self signinDelegate];
|
| - BOOL needsSignin = signinDelegate && signinDelegate->NeedSignin();
|
| - if (!needsSignin) {
|
| + app_list::SigninDelegate* signinDelegate =
|
| + delegate_ ? delegate_->GetSigninDelegate() : NULL;
|
| + BOOL show_signin_view =
|
| + signinDelegate && ![appsGridController_ model]->signed_in();
|
| + if (!!signinViewController_ == show_signin_view)
|
| + return;
|
| +
|
| + if (!show_signin_view) {
|
| [[signinViewController_ view] removeFromSuperview];
|
| - signin_observer_bridge_.reset();
|
| signinViewController_.reset();
|
| [backgroundView_ setHidden:NO];
|
| return;
|
| @@ -333,13 +360,7 @@ class SigninDelegateObserverBridge : public SigninDelegateObserver {
|
| [[SigninViewController alloc] initWithFrame:[backgroundView_ frame]
|
| cornerRadius:kBubbleCornerRadius
|
| delegate:signinDelegate]);
|
| - signin_observer_bridge_.reset(
|
| - new app_list::SigninDelegateObserverBridge(self));
|
| [[self view] addSubview:[signinViewController_ view]];
|
| }
|
|
|
| -- (app_list::SigninDelegate*)signinDelegate {
|
| - return delegate_ ? delegate_->GetSigninDelegate() : NULL;
|
| -}
|
| -
|
| @end
|
|
|