OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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/ui/search_engines/search_engine_tab_helper.h" | |
10 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" | |
11 #include "components/search_engines/template_url.h" | |
12 #include "content/public/browser/notification_source.h" | |
13 #include "content/public/browser/notification_types.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 | |
16 using content::WebContents; | |
17 | |
18 TemplateURLFetcherUICallbacks::TemplateURLFetcherUICallbacks( | |
19 SearchEngineTabHelper* tab_helper, | |
20 WebContents* web_contents) | |
21 : source_(tab_helper), | |
22 web_contents_(web_contents) { | |
23 registrar_.Add(this, | |
24 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
25 content::Source<WebContents>(web_contents_)); | |
26 } | |
27 | |
28 TemplateURLFetcherUICallbacks::~TemplateURLFetcherUICallbacks() { | |
29 } | |
30 | |
31 void TemplateURLFetcherUICallbacks::ConfirmAddSearchProvider( | |
32 TemplateURL* template_url, | |
33 Profile* profile) { | |
34 scoped_ptr<TemplateURL> owned_template_url(template_url); | |
35 if (!source_ || !source_->delegate()) | |
36 return; | |
37 | |
38 source_->delegate()->ConfirmAddSearchProvider(owned_template_url.release(), | |
39 profile); | |
40 } | |
41 | |
42 void TemplateURLFetcherUICallbacks::Observe( | |
43 int type, | |
44 const content::NotificationSource& source, | |
45 const content::NotificationDetails& details) { | |
46 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED); | |
47 DCHECK(source == content::Source<WebContents>(web_contents_)); | |
48 source_ = NULL; | |
49 web_contents_ = NULL; | |
50 } | |
OLD | NEW |