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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_event_router.cc

Issue 2058233002: Rewrite simple uses of base::ListValue::Append() taking a raw pointer var. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less comments more ownership Created 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/api/tabs/tabs_event_router.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 14 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
14 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" 15 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
15 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" 16 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
16 #include "chrome/browser/extensions/extension_tab_util.h" 17 #include "chrome/browser/extensions/extension_tab_util.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 RegisterForTabNotifications(contents); 224 RegisterForTabNotifications(contents);
224 else 225 else
225 TabCreatedAt(contents, index, active); 226 TabCreatedAt(contents, index, active);
226 return; 227 return;
227 } 228 }
228 229
229 int tab_id = ExtensionTabUtil::GetTabId(contents); 230 int tab_id = ExtensionTabUtil::GetTabId(contents);
230 std::unique_ptr<base::ListValue> args(new base::ListValue); 231 std::unique_ptr<base::ListValue> args(new base::ListValue);
231 args->AppendInteger(tab_id); 232 args->AppendInteger(tab_id);
232 233
233 base::DictionaryValue* object_args = new base::DictionaryValue(); 234 std::unique_ptr<base::DictionaryValue> object_args(
235 new base::DictionaryValue());
234 object_args->Set(tabs_constants::kNewWindowIdKey, 236 object_args->Set(tabs_constants::kNewWindowIdKey,
235 new FundamentalValue( 237 new FundamentalValue(
236 ExtensionTabUtil::GetWindowIdOfTab(contents))); 238 ExtensionTabUtil::GetWindowIdOfTab(contents)));
237 object_args->Set(tabs_constants::kNewPositionKey, 239 object_args->Set(tabs_constants::kNewPositionKey,
238 new FundamentalValue(index)); 240 new FundamentalValue(index));
239 args->Append(object_args); 241 args->Append(std::move(object_args));
240 242
241 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 243 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
242 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, 244 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName,
243 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 245 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
244 } 246 }
245 247
246 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { 248 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) {
247 if (!GetTabEntry(contents)) { 249 if (!GetTabEntry(contents)) {
248 // The tab was removed. Don't send detach event. 250 // The tab was removed. Don't send detach event.
249 return; 251 return;
250 } 252 }
251 253
252 std::unique_ptr<base::ListValue> args(new base::ListValue); 254 std::unique_ptr<base::ListValue> args(new base::ListValue);
253 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); 255 args->AppendInteger(ExtensionTabUtil::GetTabId(contents));
254 256
255 base::DictionaryValue* object_args = new base::DictionaryValue(); 257 std::unique_ptr<base::DictionaryValue> object_args(
258 new base::DictionaryValue());
256 object_args->Set(tabs_constants::kOldWindowIdKey, 259 object_args->Set(tabs_constants::kOldWindowIdKey,
257 new FundamentalValue( 260 new FundamentalValue(
258 ExtensionTabUtil::GetWindowIdOfTab(contents))); 261 ExtensionTabUtil::GetWindowIdOfTab(contents)));
259 object_args->Set(tabs_constants::kOldPositionKey, 262 object_args->Set(tabs_constants::kOldPositionKey,
260 new FundamentalValue(index)); 263 new FundamentalValue(index));
261 args->Append(object_args); 264 args->Append(std::move(object_args));
262 265
263 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 266 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
264 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, 267 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName,
265 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 268 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
266 } 269 }
267 270
268 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, 271 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model,
269 WebContents* contents, 272 WebContents* contents,
270 int index) { 273 int index) {
271 int tab_id = ExtensionTabUtil::GetTabId(contents); 274 int tab_id = ExtensionTabUtil::GetTabId(contents);
272 275
273 std::unique_ptr<base::ListValue> args(new base::ListValue); 276 std::unique_ptr<base::ListValue> args(new base::ListValue);
274 args->AppendInteger(tab_id); 277 args->AppendInteger(tab_id);
275 278
276 base::DictionaryValue* object_args = new base::DictionaryValue(); 279 std::unique_ptr<base::DictionaryValue> object_args(
280 new base::DictionaryValue());
277 object_args->SetInteger(tabs_constants::kWindowIdKey, 281 object_args->SetInteger(tabs_constants::kWindowIdKey,
278 ExtensionTabUtil::GetWindowIdOfTab(contents)); 282 ExtensionTabUtil::GetWindowIdOfTab(contents));
279 object_args->SetBoolean(tabs_constants::kWindowClosing, 283 object_args->SetBoolean(tabs_constants::kWindowClosing,
280 tab_strip_model->closing_all()); 284 tab_strip_model->closing_all());
281 args->Append(object_args); 285 args->Append(std::move(object_args));
282 286
283 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 287 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
284 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName, 288 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName,
285 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 289 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
286 290
287 UnregisterForTabNotifications(contents); 291 UnregisterForTabNotifications(contents);
288 } 292 }
289 293
290 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, 294 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents,
291 WebContents* new_contents, 295 WebContents* new_contents,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 tabs::OnHighlighted::kEventName, std::move(args), 365 tabs::OnHighlighted::kEventName, std::move(args),
362 EventRouter::USER_GESTURE_UNKNOWN); 366 EventRouter::USER_GESTURE_UNKNOWN);
363 } 367 }
364 368
365 void TabsEventRouter::TabMoved(WebContents* contents, 369 void TabsEventRouter::TabMoved(WebContents* contents,
366 int from_index, 370 int from_index,
367 int to_index) { 371 int to_index) {
368 std::unique_ptr<base::ListValue> args(new base::ListValue); 372 std::unique_ptr<base::ListValue> args(new base::ListValue);
369 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); 373 args->AppendInteger(ExtensionTabUtil::GetTabId(contents));
370 374
371 base::DictionaryValue* object_args = new base::DictionaryValue(); 375 std::unique_ptr<base::DictionaryValue> object_args(
376 new base::DictionaryValue());
372 object_args->Set(tabs_constants::kWindowIdKey, 377 object_args->Set(tabs_constants::kWindowIdKey,
373 new FundamentalValue( 378 new FundamentalValue(
374 ExtensionTabUtil::GetWindowIdOfTab(contents))); 379 ExtensionTabUtil::GetWindowIdOfTab(contents)));
375 object_args->Set(tabs_constants::kFromIndexKey, 380 object_args->Set(tabs_constants::kFromIndexKey,
376 new FundamentalValue(from_index)); 381 new FundamentalValue(from_index));
377 object_args->Set(tabs_constants::kToIndexKey, 382 object_args->Set(tabs_constants::kToIndexKey,
378 new FundamentalValue(to_index)); 383 new FundamentalValue(to_index));
379 args->Append(object_args); 384 args->Append(std::move(object_args));
380 385
381 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 386 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
382 DispatchEvent(profile, events::TABS_ON_MOVED, tabs::OnMoved::kEventName, 387 DispatchEvent(profile, events::TABS_ON_MOVED, tabs::OnMoved::kEventName,
383 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 388 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
384 } 389 }
385 390
386 void TabsEventRouter::TabUpdated(TabEntry* entry, 391 void TabsEventRouter::TabUpdated(TabEntry* entry,
387 std::set<std::string> changed_property_names) { 392 std::set<std::string> changed_property_names) {
388 bool audible = entry->web_contents()->WasRecentlyAudible(); 393 bool audible = entry->web_contents()->WasRecentlyAudible();
389 if (entry->SetAudible(audible)) { 394 if (entry->SetAudible(audible)) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 bool icon_url_changed, 546 bool icon_url_changed,
542 const gfx::Image& image) { 547 const gfx::Image& image) {
543 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { 548 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) {
544 favicon::ContentFaviconDriver* content_favicon_driver = 549 favicon::ContentFaviconDriver* content_favicon_driver =
545 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); 550 static_cast<favicon::ContentFaviconDriver*>(favicon_driver);
546 FaviconUrlUpdated(content_favicon_driver->web_contents()); 551 FaviconUrlUpdated(content_favicon_driver->web_contents());
547 } 552 }
548 } 553 }
549 554
550 } // namespace extensions 555 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/proxy/proxy_api.cc ('k') | chrome/browser/extensions/api/top_sites/top_sites_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698