Home | History | Annotate | Download | only in search_engines
      1 // Copyright (c) 2011 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/search_engines/template_url_fetcher_ui_callbacks.h"
      6 
      7 #include "base/logging.h"
      8 #include "base/memory/scoped_ptr.h"
      9 #include "chrome/browser/search_engines/template_url.h"
     10 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
     11 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
     12 #include "content/browser/tab_contents/tab_contents.h"
     13 #include "content/common/notification_source.h"
     14 #include "content/common/notification_type.h"
     15 
     16 TemplateURLFetcherUICallbacks::TemplateURLFetcherUICallbacks(
     17     SearchEngineTabHelper* tab_helper,
     18     TabContents* tab_contents)
     19     : source_(tab_helper),
     20       tab_contents_(tab_contents) {
     21   registrar_.Add(this,
     22                  NotificationType::TAB_CONTENTS_DESTROYED,
     23                  Source<TabContents>(tab_contents_));
     24 }
     25 
     26 TemplateURLFetcherUICallbacks::~TemplateURLFetcherUICallbacks() {
     27 }
     28 
     29 void TemplateURLFetcherUICallbacks::ConfirmSetDefaultSearchProvider(
     30     TemplateURL* template_url,
     31     TemplateURLModel* template_url_model) {
     32   scoped_ptr<TemplateURL> owned_template_url(template_url);
     33   if (!source_ || !source_->delegate() || !tab_contents_)
     34       return;
     35 
     36   source_->delegate()->ConfirmSetDefaultSearchProvider(
     37       tab_contents_,
     38       owned_template_url.release(),
     39       template_url_model);
     40 }
     41 
     42 void TemplateURLFetcherUICallbacks::ConfirmAddSearchProvider(
     43     TemplateURL* template_url,
     44     Profile* profile) {
     45   scoped_ptr<TemplateURL> owned_template_url(template_url);
     46   if (!source_ || !source_->delegate())
     47       return;
     48 
     49   source_->delegate()->ConfirmAddSearchProvider(owned_template_url.release(),
     50                                                 profile);
     51 }
     52 
     53 void TemplateURLFetcherUICallbacks::Observe(
     54     NotificationType type,
     55     const NotificationSource& source,
     56     const NotificationDetails& details) {
     57   DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
     58   DCHECK(source == Source<TabContents>(tab_contents_));
     59   source_ = NULL;
     60   tab_contents_ = NULL;
     61 }
     62