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

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

Issue 11366074: Coalesce event router Init calls into their constructors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: aa Created 8 years, 1 month 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Implements the Chrome Extensions WebNavigation API. 5 // Implements the Chrome Extensions WebNavigation API.
6 6
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 : source_web_contents(source_web_contents), 66 : source_web_contents(source_web_contents),
67 source_frame_id(source_frame_id), 67 source_frame_id(source_frame_id),
68 source_frame_is_main_frame(source_frame_is_main_frame), 68 source_frame_is_main_frame(source_frame_is_main_frame),
69 target_web_contents(target_web_contents), 69 target_web_contents(target_web_contents),
70 target_url(target_url) { 70 target_url(target_url) {
71 } 71 }
72 72
73 WebNavigationEventRouter::PendingWebContents::~PendingWebContents() {} 73 WebNavigationEventRouter::PendingWebContents::~PendingWebContents() {}
74 74
75 WebNavigationEventRouter::WebNavigationEventRouter(Profile* profile) 75 WebNavigationEventRouter::WebNavigationEventRouter(Profile* profile)
76 : profile_(profile) {} 76 : profile_(profile) {
77 77 CHECK(registrar_.IsEmpty());
78 WebNavigationEventRouter::~WebNavigationEventRouter() {
79 BrowserList::RemoveObserver(this);
80 }
81
82 void WebNavigationEventRouter::Init() {
83 if (!registrar_.IsEmpty())
84 return;
85 registrar_.Add(this, 78 registrar_.Add(this,
86 chrome::NOTIFICATION_RETARGETING, 79 chrome::NOTIFICATION_RETARGETING,
87 content::NotificationService::AllSources()); 80 content::NotificationService::AllSources());
88 registrar_.Add(this, 81 registrar_.Add(this,
89 chrome::NOTIFICATION_TAB_ADDED, 82 chrome::NOTIFICATION_TAB_ADDED,
90 content::NotificationService::AllSources()); 83 content::NotificationService::AllSources());
91 registrar_.Add(this, 84 registrar_.Add(this,
92 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 85 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
93 content::NotificationService::AllSources()); 86 content::NotificationService::AllSources());
94 87
95 BrowserList::AddObserver(this); 88 BrowserList::AddObserver(this);
96 for (BrowserList::const_iterator iter = BrowserList::begin(); 89 for (BrowserList::const_iterator iter = BrowserList::begin();
97 iter != BrowserList::end(); ++iter) { 90 iter != BrowserList::end(); ++iter) {
98 OnBrowserAdded(*iter); 91 OnBrowserAdded(*iter);
99 } 92 }
100 } 93 }
101 94
95 WebNavigationEventRouter::~WebNavigationEventRouter() {
96 BrowserList::RemoveObserver(this);
97 }
98
102 void WebNavigationEventRouter::OnBrowserAdded(Browser* browser) { 99 void WebNavigationEventRouter::OnBrowserAdded(Browser* browser) {
103 if (!profile_->IsSameProfile(browser->profile())) 100 if (!profile_->IsSameProfile(browser->profile()))
104 return; 101 return;
105 browser->tab_strip_model()->AddObserver(this); 102 browser->tab_strip_model()->AddObserver(this);
106 } 103 }
107 104
108 void WebNavigationEventRouter::OnBrowserRemoved(Browser* browser) { 105 void WebNavigationEventRouter::OnBrowserRemoved(Browser* browser) {
109 if (!profile_->IsSameProfile(browser->profile())) 106 if (!profile_->IsSameProfile(browser->profile()))
110 return; 107 return;
111 browser->tab_strip_model()->RemoveObserver(this); 108 browser->tab_strip_model()->RemoveObserver(this);
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 parent_frame_id.frame_num); 736 parent_frame_id.frame_num);
740 frame->process_id = frame_id.render_view_host->GetProcess()->GetID(); 737 frame->process_id = frame_id.render_view_host->GetProcess()->GetID();
741 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); 738 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id);
742 result_list.push_back(frame); 739 result_list.push_back(frame);
743 } 740 }
744 results_ = GetAllFrames::Results::Create(result_list); 741 results_ = GetAllFrames::Results::Create(result_list);
745 return true; 742 return true;
746 } 743 }
747 744
748 } // namespace extensions 745 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_navigation/web_navigation_api.h ('k') | chrome/browser/extensions/browser_event_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698