Home | History | Annotate | Download | only in bookmarks
      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/bookmarks/bookmark_bubble_sign_in_delegate.h"
      6 
      7 #include "chrome/browser/signin/signin_promo.h"
      8 #include "chrome/browser/ui/browser.h"
      9 #include "chrome/browser/ui/browser_finder.h"
     10 #include "chrome/browser/ui/browser_list.h"
     11 #include "chrome/browser/ui/browser_window.h"
     12 #include "chrome/browser/ui/chrome_pages.h"
     13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
     14 
     15 BookmarkBubbleSignInDelegate::BookmarkBubbleSignInDelegate(Browser* browser)
     16     : browser_(browser),
     17       profile_(browser->profile()),
     18       desktop_type_(browser->host_desktop_type()) {
     19   BrowserList::AddObserver(this);
     20 }
     21 
     22 BookmarkBubbleSignInDelegate::~BookmarkBubbleSignInDelegate() {
     23   BrowserList::RemoveObserver(this);
     24 }
     25 
     26 void BookmarkBubbleSignInDelegate::OnSignInLinkClicked() {
     27   EnsureBrowser();
     28   chrome::ShowBrowserSignin(browser_, signin::SOURCE_BOOKMARK_BUBBLE);
     29   DCHECK(!browser_->tab_strip_model()->empty());
     30   browser_->window()->Show();
     31 }
     32 
     33 void BookmarkBubbleSignInDelegate::OnBrowserRemoved(Browser* browser) {
     34   if (browser == browser_)
     35     browser_ = NULL;
     36 }
     37 
     38 void BookmarkBubbleSignInDelegate::EnsureBrowser() {
     39   if (!browser_) {
     40     Profile* original_profile = profile_->GetOriginalProfile();
     41     browser_ = chrome::FindLastActiveWithProfile(original_profile,
     42                                                  desktop_type_);
     43     if (!browser_) {
     44       browser_ = new Browser(Browser::CreateParams(original_profile,
     45                                                    desktop_type_));
     46     }
     47   }
     48 }
     49