Home | History | Annotate | Download | only in app_list
      1 // Copyright 2013 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 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h"
      6 
      7 #include "chrome/browser/extensions/extension_service.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #include "chrome/browser/signin/signin_manager.h"
     10 #include "chrome/browser/signin/signin_manager_factory.h"
     11 #include "chrome/browser/signin/signin_promo.h"
     12 #include "chrome/browser/ui/browser_finder.h"
     13 #include "chrome/browser/ui/browser_navigator.h"
     14 #include "chrome/browser/ui/chrome_pages.h"
     15 #include "chrome/browser/ui/extensions/application_launch.h"
     16 #include "chrome/browser/ui/host_desktop.h"
     17 #include "chrome/common/extensions/extension_constants.h"
     18 #include "content/public/common/page_transition_types.h"
     19 #include "grit/chromium_strings.h"
     20 #include "grit/generated_resources.h"
     21 #include "ui/app_list/signin_delegate_observer.h"
     22 #include "ui/base/resource/resource_bundle.h"
     23 
     24 namespace {
     25 
     26 SigninManagerBase* GetSigninManager(Profile* profile) {
     27   return SigninManagerFactory::GetForProfile(profile);
     28 }
     29 
     30 }  // namespace
     31 
     32 ChromeSigninDelegate::ChromeSigninDelegate(Profile* profile)
     33     : profile_(profile) {}
     34 
     35 bool ChromeSigninDelegate::NeedSignin()  {
     36 #if defined(OS_CHROMEOS)
     37   return false;
     38 #else
     39   if (!profile_)
     40     return false;
     41 
     42   if (!GetSigninManager(profile_))
     43     return false;
     44 
     45   return GetSigninManager(profile_)->GetAuthenticatedUsername().empty();
     46 #endif
     47 }
     48 
     49 void ChromeSigninDelegate::ShowSignin() {
     50   DCHECK(profile_);
     51 
     52   signin_tracker_.reset(new SigninTracker(profile_, this));
     53 
     54   Browser* browser = FindOrCreateTabbedBrowser(profile_,
     55                                                chrome::GetActiveDesktop());
     56   chrome::ShowBrowserSignin(browser, signin::SOURCE_APP_LAUNCHER);
     57 }
     58 
     59 void ChromeSigninDelegate::OpenLearnMore() {
     60   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
     61   GURL gurl(rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_LEARN_MORE_LINK));
     62   chrome::NavigateParams params(profile_, gurl, content::PAGE_TRANSITION_LINK);
     63   chrome::Navigate(&params);
     64 }
     65 
     66 void ChromeSigninDelegate::OpenSettings() {
     67   ExtensionService* service = profile_->GetExtensionService();
     68   DCHECK(service);
     69   const extensions::Extension* extension = service->GetInstalledExtension(
     70       extension_misc::kSettingsAppId);
     71   if (!extension)
     72     return;
     73 
     74   chrome::OpenApplication(chrome::AppLaunchParams(
     75       profile_, extension, NEW_FOREGROUND_TAB));
     76 }
     77 
     78 string16 ChromeSigninDelegate::GetSigninHeading() {
     79   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
     80   return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_HEADING);
     81 }
     82 
     83 string16 ChromeSigninDelegate::GetSigninText() {
     84   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
     85   return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_TEXT);
     86 }
     87 
     88 string16 ChromeSigninDelegate::GetSigninButtonText() {
     89   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
     90   return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_BUTTON);
     91 }
     92 
     93 string16 ChromeSigninDelegate::GetLearnMoreLinkText() {
     94   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
     95   return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_LEARN_MORE_TEXT);
     96 }
     97 
     98 string16 ChromeSigninDelegate::GetSettingsLinkText() {
     99   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
    100   return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_SETTINGS_TEXT);
    101 }
    102 
    103 ChromeSigninDelegate::~ChromeSigninDelegate() {}
    104 
    105 void ChromeSigninDelegate::SigninFailed(const GoogleServiceAuthError& error) {}
    106 
    107 void ChromeSigninDelegate::SigninSuccess() {
    108   NotifySigninSuccess();
    109 }
    110