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

Side by Side Diff: chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc

Issue 2767893002: Remove ScopedVector from chrome/browser/. (Closed)
Patch Set: Address comments from zea@ Created 3 years, 9 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
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 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" 5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
6 6
7 #include <memory>
7 #include <set> 8 #include <set>
8 #include <string> 9 #include <string>
10 #include <vector>
9 11
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
13 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
15 #include "build/build_config.h" 18 #include "build/build_config.h"
16 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 19 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
17 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/tab_contents/tab_util.h" 21 #include "chrome/browser/tab_contents/tab_util.h"
19 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
21 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // extension using the (new) speech JS APIs, will be properly handled here. 101 // extension using the (new) speech JS APIs, will be properly handled here.
99 // TODO(primiano) turn this line into a DCHECK once speech input extension 102 // TODO(primiano) turn this line into a DCHECK once speech input extension
100 // API is deprecated. 103 // API is deprecated.
101 if (!web_contents) 104 if (!web_contents)
102 return; 105 return;
103 106
104 // Avoid multiple registrations for the same |web_contents|. 107 // Avoid multiple registrations for the same |web_contents|.
105 if (FindWebContents(web_contents) != registered_web_contents_.end()) 108 if (FindWebContents(web_contents) != registered_web_contents_.end())
106 return; 109 return;
107 110
108 registered_web_contents_.push_back(new WebContentsTracker( 111 registered_web_contents_.push_back(base::MakeUnique<WebContentsTracker>(
109 web_contents, base::Bind(&TabWatcher::OnTabClosed, 112 web_contents,
110 // |this| outlives WebContentsTracker. 113 base::Bind(&TabWatcher::OnTabClosed,
111 base::Unretained(this), web_contents), 114 // |this| outlives WebContentsTracker.
115 base::Unretained(this), web_contents),
112 render_process_id, render_view_id)); 116 render_process_id, render_view_id));
113 } 117 }
114 118
115 void OnTabClosed(content::WebContents* web_contents) { 119 void OnTabClosed(content::WebContents* web_contents) {
116 ScopedVector<WebContentsTracker>::iterator iter = 120 auto iter = FindWebContents(web_contents);
117 FindWebContents(web_contents);
118 DCHECK(iter != registered_web_contents_.end()); 121 DCHECK(iter != registered_web_contents_.end());
119 int render_process_id = (*iter)->render_process_id(); 122 int render_process_id = (*iter)->render_process_id();
120 int render_view_id = (*iter)->render_view_id(); 123 int render_view_id = (*iter)->render_view_id();
121 registered_web_contents_.erase(iter); 124 registered_web_contents_.erase(iter);
122 125
123 tab_closed_callback_.Run(render_process_id, render_view_id); 126 tab_closed_callback_.Run(render_process_id, render_view_id);
124 } 127 }
125 128
126 private: 129 private:
127 class WebContentsTracker : public content::WebContentsObserver { 130 class WebContentsTracker : public content::WebContentsObserver {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 friend class base::RefCountedThreadSafe<TabWatcher>; 174 friend class base::RefCountedThreadSafe<TabWatcher>;
172 175
173 ~TabWatcher() { 176 ~TabWatcher() {
174 // Must be destroyed on the UI thread due to |registrar_| non thread-safety. 177 // Must be destroyed on the UI thread due to |registrar_| non thread-safety.
175 // TODO(lazyboy): Do we still need this? 178 // TODO(lazyboy): Do we still need this?
176 DCHECK_CURRENTLY_ON(BrowserThread::UI); 179 DCHECK_CURRENTLY_ON(BrowserThread::UI);
177 } 180 }
178 181
179 // Helper function to find the iterator in |registered_web_contents_| which 182 // Helper function to find the iterator in |registered_web_contents_| which
180 // contains |web_contents|. 183 // contains |web_contents|.
181 ScopedVector<WebContentsTracker>::iterator FindWebContents( 184 std::vector<std::unique_ptr<WebContentsTracker>>::iterator FindWebContents(
182 content::WebContents* web_contents) { 185 content::WebContents* web_contents) {
183 for (ScopedVector<WebContentsTracker>::iterator i( 186 for (auto i = registered_web_contents_.begin();
184 registered_web_contents_.begin());
185 i != registered_web_contents_.end(); ++i) { 187 i != registered_web_contents_.end(); ++i) {
186 if ((*i)->GetWebContents() == web_contents) 188 if ((*i)->GetWebContents() == web_contents)
187 return i; 189 return i;
188 } 190 }
189 191
190 return registered_web_contents_.end(); 192 return registered_web_contents_.end();
191 } 193 }
192 194
193 // Keeps track of which WebContent(s) have been registered, in order to avoid 195 // Keeps track of which WebContent(s) have been registered, in order to avoid
194 // double registrations on WebContentsObserver and to pass the correct render 196 // double registrations on WebContentsObserver and to pass the correct render
195 // process id and render view id to |tab_closed_callback_| after the process 197 // process id and render view id to |tab_closed_callback_| after the process
196 // has gone away. 198 // has gone away.
197 ScopedVector<WebContentsTracker> registered_web_contents_; 199 std::vector<std::unique_ptr<WebContentsTracker>> registered_web_contents_;
198 200
199 // Callback used to notify, on the thread specified by |callback_thread_| the 201 // Callback used to notify, on the thread specified by |callback_thread_| the
200 // closure of a registered tab. 202 // closure of a registered tab.
201 TabClosedCallback tab_closed_callback_; 203 TabClosedCallback tab_closed_callback_;
202 204
203 DISALLOW_COPY_AND_ASSIGN(TabWatcher); 205 DISALLOW_COPY_AND_ASSIGN(TabWatcher);
204 }; 206 };
205 207
206 ChromeSpeechRecognitionManagerDelegate 208 ChromeSpeechRecognitionManagerDelegate
207 ::ChromeSpeechRecognitionManagerDelegate() { 209 ::ChromeSpeechRecognitionManagerDelegate() {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Otherwise this should be a regular tab contents. 355 // Otherwise this should be a regular tab contents.
354 allowed = true; 356 allowed = true;
355 check_permission = true; 357 check_permission = true;
356 #endif 358 #endif
357 359
358 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 360 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
359 base::Bind(callback, check_permission, allowed)); 361 base::Bind(callback, check_permission, allowed));
360 } 362 }
361 363
362 } // namespace speech 364 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698