| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 8 | 8 |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 Browser* browser) | 256 Browser* browser) |
| 257 : controller_(controller), | 257 : controller_(controller), |
| 258 browser_(browser), | 258 browser_(browser), |
| 259 token_observer_registered_(false) { | 259 token_observer_registered_(false) { |
| 260 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 260 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
| 261 content::NotificationService::AllSources()); | 261 content::NotificationService::AllSources()); |
| 262 if (!browser_->profile()->IsGuestSession()) | 262 if (!browser_->profile()->IsGuestSession()) |
| 263 AddTokenServiceObserver(); | 263 AddTokenServiceObserver(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 virtual ~ActiveProfileObserverBridge() { | 266 ~ActiveProfileObserverBridge() override { RemoveTokenServiceObserver(); } |
| 267 RemoveTokenServiceObserver(); | |
| 268 } | |
| 269 | 267 |
| 270 private: | 268 private: |
| 271 void AddTokenServiceObserver() { | 269 void AddTokenServiceObserver() { |
| 272 ProfileOAuth2TokenService* oauth2_token_service = | 270 ProfileOAuth2TokenService* oauth2_token_service = |
| 273 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); | 271 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); |
| 274 DCHECK(oauth2_token_service); | 272 DCHECK(oauth2_token_service); |
| 275 oauth2_token_service->AddObserver(this); | 273 oauth2_token_service->AddObserver(this); |
| 276 token_observer_registered_ = true; | 274 token_observer_registered_ = true; |
| 277 } | 275 } |
| 278 | 276 |
| 279 void RemoveTokenServiceObserver() { | 277 void RemoveTokenServiceObserver() { |
| 280 if (!token_observer_registered_) | 278 if (!token_observer_registered_) |
| 281 return; | 279 return; |
| 282 DCHECK(browser_->profile()); | 280 DCHECK(browser_->profile()); |
| 283 ProfileOAuth2TokenService* oauth2_token_service = | 281 ProfileOAuth2TokenService* oauth2_token_service = |
| 284 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); | 282 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); |
| 285 DCHECK(oauth2_token_service); | 283 DCHECK(oauth2_token_service); |
| 286 oauth2_token_service->RemoveObserver(this); | 284 oauth2_token_service->RemoveObserver(this); |
| 287 token_observer_registered_ = false; | 285 token_observer_registered_ = false; |
| 288 } | 286 } |
| 289 | 287 |
| 290 // OAuth2TokenService::Observer: | 288 // OAuth2TokenService::Observer: |
| 291 virtual void OnRefreshTokenAvailable(const std::string& account_id) override { | 289 void OnRefreshTokenAvailable(const std::string& account_id) override { |
| 292 // Tokens can only be added by adding an account through the inline flow, | 290 // Tokens can only be added by adding an account through the inline flow, |
| 293 // which is started from the account management view. Refresh it to show the | 291 // which is started from the account management view. Refresh it to show the |
| 294 // update. | 292 // update. |
| 295 profiles::BubbleViewMode viewMode = [controller_ viewMode]; | 293 profiles::BubbleViewMode viewMode = [controller_ viewMode]; |
| 296 if (viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT || | 294 if (viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT || |
| 297 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || | 295 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || |
| 298 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { | 296 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { |
| 299 [controller_ initMenuContentsWithView: | 297 [controller_ initMenuContentsWithView: |
| 300 switches::IsEnableAccountConsistency() ? | 298 switches::IsEnableAccountConsistency() ? |
| 301 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : | 299 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : |
| 302 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 300 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
| 303 } | 301 } |
| 304 } | 302 } |
| 305 | 303 |
| 306 virtual void OnRefreshTokenRevoked(const std::string& account_id) override { | 304 void OnRefreshTokenRevoked(const std::string& account_id) override { |
| 307 // Tokens can only be removed from the account management view. Refresh it | 305 // Tokens can only be removed from the account management view. Refresh it |
| 308 // to show the update. | 306 // to show the update. |
| 309 if ([controller_ viewMode] == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) | 307 if ([controller_ viewMode] == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) |
| 310 [controller_ initMenuContentsWithView: | 308 [controller_ initMenuContentsWithView: |
| 311 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 309 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
| 312 } | 310 } |
| 313 | 311 |
| 314 // AvatarMenuObserver: | 312 // AvatarMenuObserver: |
| 315 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override { | 313 void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override { |
| 316 profiles::BubbleViewMode viewMode = [controller_ viewMode]; | 314 profiles::BubbleViewMode viewMode = [controller_ viewMode]; |
| 317 if (viewMode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || | 315 if (viewMode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || |
| 318 viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | 316 viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
| 319 [controller_ initMenuContentsWithView:viewMode]; | 317 [controller_ initMenuContentsWithView:viewMode]; |
| 320 } | 318 } |
| 321 } | 319 } |
| 322 | 320 |
| 323 // content::NotificationObserver: | 321 // content::NotificationObserver: |
| 324 virtual void Observe( | 322 void Observe(int type, |
| 325 int type, | 323 const content::NotificationSource& source, |
| 326 const content::NotificationSource& source, | 324 const content::NotificationDetails& details) override { |
| 327 const content::NotificationDetails& details) override { | |
| 328 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type); | 325 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type); |
| 329 if (browser_ == content::Source<Browser>(source).ptr()) { | 326 if (browser_ == content::Source<Browser>(source).ptr()) { |
| 330 RemoveTokenServiceObserver(); | 327 RemoveTokenServiceObserver(); |
| 331 // Clean up the bubble's WebContents (used by the Gaia embedded view), to | 328 // Clean up the bubble's WebContents (used by the Gaia embedded view), to |
| 332 // make sure the guest profile doesn't have any dangling host renderers. | 329 // make sure the guest profile doesn't have any dangling host renderers. |
| 333 // This can happen if Chrome is quit using Command-Q while the bubble is | 330 // This can happen if Chrome is quit using Command-Q while the bubble is |
| 334 // still open, which won't give the bubble a chance to be closed and | 331 // still open, which won't give the bubble a chance to be closed and |
| 335 // clean up the WebContents itself. | 332 // clean up the WebContents itself. |
| 336 [controller_ cleanUpEmbeddedViewContents]; | 333 [controller_ cleanUpEmbeddedViewContents]; |
| 337 } | 334 } |
| (...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2203 } | 2200 } |
| 2204 | 2201 |
| 2205 - (bool)shouldShowGoIncognito { | 2202 - (bool)shouldShowGoIncognito { |
| 2206 bool incognitoAvailable = | 2203 bool incognitoAvailable = |
| 2207 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2204 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2208 IncognitoModePrefs::DISABLED; | 2205 IncognitoModePrefs::DISABLED; |
| 2209 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2206 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2210 } | 2207 } |
| 2211 | 2208 |
| 2212 @end | 2209 @end |
| OLD | NEW |