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

Unified Diff: ui/app_list/cocoa/app_list_view_controller.mm

Issue 22268009: Move signin status and current user information into AppListModel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests and multiple notification bug Created 7 years, 4 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
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..5dbe9b4e5685fe16cf872ecc2387c0bc325d191c 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 =
+ ![appsGridController_ model]->signed_in() && signinDelegate;
tapted 2013/08/16 08:00:25 nit: might as well check signinDelegate first, sin
calamity 2013/08/16 09:12:47 Done.
+ if (static_cast<bool>(signinViewController_) == show_signin_view)
tapted 2013/08/16 08:00:25 nit: I think instead of static_cast, I see this do
calamity 2013/08/16 09:12:47 Done.
+ 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
« no previous file with comments | « ui/app_list/cocoa/app_list_view_controller.h ('k') | ui/app_list/cocoa/app_list_view_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698