Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: chrome/browser/google/google_url_tracker_map_entry.cc

Issue 316203003: Componentize GoogleURLTracker(InfoBarDelegate,MapEntry,NavHelper) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 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/google/google_url_tracker_map_entry.h"
6
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/google/google_url_tracker.h"
9 #include "components/infobars/core/infobar.h"
10
11 GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry(
12 GoogleURLTracker* google_url_tracker,
13 infobars::InfoBarManager* infobar_manager,
14 scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper)
15 : google_url_tracker_(google_url_tracker),
16 infobar_manager_(infobar_manager),
17 infobar_delegate_(NULL),
18 navigation_helper_(navigation_helper.Pass()),
19 observing_(false) {
20 DCHECK(infobar_manager_);
21 }
22
23 GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() {
24 if (observing_)
25 infobar_manager_->RemoveObserver(this);
26 }
27
28 void GoogleURLTrackerMapEntry::SetInfoBarDelegate(
29 GoogleURLTrackerInfoBarDelegate* infobar_delegate) {
30 DCHECK(!infobar_delegate_);
31
32 // Transfer ownership of |navigation_helper_| to the infobar delegate as the
33 // infobar delegate has need of it after this object has been destroyed in
34 // the case where the user accepts the new Google URL.
35 infobar_delegate->set_navigation_helper(navigation_helper_.Pass());
36 infobar_delegate_ = infobar_delegate;
37 infobar_manager_->AddObserver(this);
38 observing_ = true;
39 }
40
41 void GoogleURLTrackerMapEntry::Close(bool redo_search) {
42 if (infobar_delegate_) {
43 infobar_delegate_->Close(redo_search);
44 } else {
45 // WARNING: |infobar_manager_| may point to a deleted object. Do not
46 // dereference it! See GoogleURLTracker::OnTabClosed().
47 google_url_tracker_->DeleteMapEntryForManager(infobar_manager_);
48 }
49 // WARNING: At this point |this| has been deleted!
50 }
51
52 void GoogleURLTrackerMapEntry::OnInfoBarRemoved(infobars::InfoBar* infobar,
53 bool animate) {
54 DCHECK(infobar_delegate_);
55 if (infobar->delegate() == infobar_delegate_) {
56 google_url_tracker_->DeleteMapEntryForManager(infobar_manager_);
57 // WARNING: At this point |this| has been deleted!
58 }
59 }
60
61 void GoogleURLTrackerMapEntry::OnManagerShuttingDown(
62 infobars::InfoBarManager* manager) {
63 DCHECK(observing_);
64 DCHECK_EQ(infobar_manager_, manager);
65 manager->RemoveObserver(this);
66 observing_ = false;
67 }
OLDNEW
« no previous file with comments | « chrome/browser/google/google_url_tracker_map_entry.h ('k') | chrome/browser/google/google_url_tracker_navigation_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698