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

Side by Side Diff: extensions/browser/api/runtime/runtime_api.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/runtime/runtime_api.h" 5 #include "extensions/browser/api/runtime/runtime_api.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/child_process_security_policy.h" 16 #include "content/public/browser/child_process_security_policy.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
20 #include "extensions/browser/api/runtime/runtime_api_delegate.h" 20 #include "extensions/browser/api/runtime/runtime_api_delegate.h"
21 #include "extensions/browser/event_router.h" 21 #include "extensions/browser/event_router.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 first_call && 106 first_call &&
107 LazyBackgroundTaskQueue::Get(browser_context) 107 LazyBackgroundTaskQueue::Get(browser_context)
108 ->ShouldEnqueueTask(browser_context, extension)) { 108 ->ShouldEnqueueTask(browser_context, extension)) {
109 LazyBackgroundTaskQueue::Get(browser_context) 109 LazyBackgroundTaskQueue::Get(browser_context)
110 ->AddPendingTask(browser_context, extension_id, 110 ->AddPendingTask(browser_context, extension_id,
111 base::Bind(&DispatchOnStartupEventImpl, 111 base::Bind(&DispatchOnStartupEventImpl,
112 browser_context, extension_id, false)); 112 browser_context, extension_id, false));
113 return; 113 return;
114 } 114 }
115 115
116 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 116 std::unique_ptr<base::ListValue> event_args(new base::ListValue());
117 scoped_ptr<Event> event(new Event(events::RUNTIME_ON_STARTUP, 117 std::unique_ptr<Event> event(new Event(events::RUNTIME_ON_STARTUP,
118 runtime::OnStartup::kEventName, 118 runtime::OnStartup::kEventName,
119 std::move(event_args))); 119 std::move(event_args)));
120 EventRouter::Get(browser_context) 120 EventRouter::Get(browser_context)
121 ->DispatchEventToExtension(extension_id, std::move(event)); 121 ->DispatchEventToExtension(extension_id, std::move(event));
122 } 122 }
123 123
124 void SetUninstallURL(ExtensionPrefs* prefs, 124 void SetUninstallURL(ExtensionPrefs* prefs,
125 const std::string& extension_id, 125 const std::string& extension_id,
126 const std::string& url_string) { 126 const std::string& url_string) {
127 prefs->UpdateExtensionPref( 127 prefs->UpdateExtensionPref(
128 extension_id, kUninstallUrl, new base::StringValue(url_string)); 128 extension_id, kUninstallUrl, new base::StringValue(url_string));
129 } 129 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 kPrefPendingOnInstalledEventDispatchInfo, nullptr); 280 kPrefPendingOnInstalledEventDispatchInfo, nullptr);
281 } 281 }
282 282
283 void RuntimeAPI::StorePendingOnInstallInfoToPref(const Extension* extension) { 283 void RuntimeAPI::StorePendingOnInstallInfoToPref(const Extension* extension) {
284 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); 284 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_);
285 DCHECK(prefs); 285 DCHECK(prefs);
286 286
287 // |pending_on_install_info| currently only contains a version string. Instead 287 // |pending_on_install_info| currently only contains a version string. Instead
288 // of making the pref hold a plain string, we store it as a dictionary value 288 // of making the pref hold a plain string, we store it as a dictionary value
289 // so that we can add more stuff to it in the future if necessary. 289 // so that we can add more stuff to it in the future if necessary.
290 scoped_ptr<base::DictionaryValue> pending_on_install_info( 290 std::unique_ptr<base::DictionaryValue> pending_on_install_info(
291 new base::DictionaryValue()); 291 new base::DictionaryValue());
292 base::Version previous_version = 292 base::Version previous_version =
293 delegate_->GetPreviousExtensionVersion(extension); 293 delegate_->GetPreviousExtensionVersion(extension);
294 pending_on_install_info->SetString( 294 pending_on_install_info->SetString(
295 kPrefPreviousVersion, 295 kPrefPreviousVersion,
296 previous_version.IsValid() ? previous_version.GetString() : ""); 296 previous_version.IsValid() ? previous_version.GetString() : "");
297 prefs->UpdateExtensionPref(extension->id(), 297 prefs->UpdateExtensionPref(extension->id(),
298 kPrefPendingOnInstalledEventDispatchInfo, 298 kPrefPendingOnInstalledEventDispatchInfo,
299 pending_on_install_info.release()); 299 pending_on_install_info.release());
300 } 300 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 content::BrowserContext* context, 339 content::BrowserContext* context,
340 const std::string& extension_id, 340 const std::string& extension_id,
341 const Version& old_version, 341 const Version& old_version,
342 bool chrome_updated) { 342 bool chrome_updated) {
343 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) 343 if (!ExtensionsBrowserClient::Get()->IsValidContext(context))
344 return; 344 return;
345 ExtensionSystem* system = ExtensionSystem::Get(context); 345 ExtensionSystem* system = ExtensionSystem::Get(context);
346 if (!system) 346 if (!system)
347 return; 347 return;
348 348
349 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 349 std::unique_ptr<base::ListValue> event_args(new base::ListValue());
350 base::DictionaryValue* info = new base::DictionaryValue(); 350 base::DictionaryValue* info = new base::DictionaryValue();
351 event_args->Append(info); 351 event_args->Append(info);
352 if (old_version.IsValid()) { 352 if (old_version.IsValid()) {
353 info->SetString(kInstallReason, kInstallReasonUpdate); 353 info->SetString(kInstallReason, kInstallReasonUpdate);
354 info->SetString(kInstallPreviousVersion, old_version.GetString()); 354 info->SetString(kInstallPreviousVersion, old_version.GetString());
355 } else if (chrome_updated) { 355 } else if (chrome_updated) {
356 info->SetString(kInstallReason, kInstallReasonChromeUpdate); 356 info->SetString(kInstallReason, kInstallReasonChromeUpdate);
357 } else { 357 } else {
358 info->SetString(kInstallReason, kInstallReasonInstall); 358 info->SetString(kInstallReason, kInstallReasonInstall);
359 } 359 }
360 EventRouter* event_router = EventRouter::Get(context); 360 EventRouter* event_router = EventRouter::Get(context);
361 DCHECK(event_router); 361 DCHECK(event_router);
362 scoped_ptr<Event> event(new Event(events::RUNTIME_ON_INSTALLED, 362 std::unique_ptr<Event> event(new Event(events::RUNTIME_ON_INSTALLED,
363 runtime::OnInstalled::kEventName, 363 runtime::OnInstalled::kEventName,
364 std::move(event_args))); 364 std::move(event_args)));
365 event_router->DispatchEventWithLazyListener(extension_id, std::move(event)); 365 event_router->DispatchEventWithLazyListener(extension_id, std::move(event));
366 366
367 if (old_version.IsValid()) { 367 if (old_version.IsValid()) {
368 const Extension* extension = 368 const Extension* extension =
369 ExtensionRegistry::Get(context)->enabled_extensions().GetByID( 369 ExtensionRegistry::Get(context)->enabled_extensions().GetByID(
370 extension_id); 370 extension_id);
371 if (extension && SharedModuleInfo::IsSharedModule(extension)) { 371 if (extension && SharedModuleInfo::IsSharedModule(extension)) {
372 scoped_ptr<ExtensionSet> dependents = 372 std::unique_ptr<ExtensionSet> dependents =
373 system->GetDependentExtensions(extension); 373 system->GetDependentExtensions(extension);
374 for (ExtensionSet::const_iterator i = dependents->begin(); 374 for (ExtensionSet::const_iterator i = dependents->begin();
375 i != dependents->end(); 375 i != dependents->end();
376 i++) { 376 i++) {
377 scoped_ptr<base::ListValue> sm_event_args(new base::ListValue()); 377 std::unique_ptr<base::ListValue> sm_event_args(new base::ListValue());
378 base::DictionaryValue* sm_info = new base::DictionaryValue(); 378 base::DictionaryValue* sm_info = new base::DictionaryValue();
379 sm_event_args->Append(sm_info); 379 sm_event_args->Append(sm_info);
380 sm_info->SetString(kInstallReason, kInstallReasonSharedModuleUpdate); 380 sm_info->SetString(kInstallReason, kInstallReasonSharedModuleUpdate);
381 sm_info->SetString(kInstallPreviousVersion, old_version.GetString()); 381 sm_info->SetString(kInstallPreviousVersion, old_version.GetString());
382 sm_info->SetString(kInstallId, extension_id); 382 sm_info->SetString(kInstallId, extension_id);
383 scoped_ptr<Event> sm_event(new Event(events::RUNTIME_ON_INSTALLED, 383 std::unique_ptr<Event> sm_event(new Event(
384 runtime::OnInstalled::kEventName, 384 events::RUNTIME_ON_INSTALLED, runtime::OnInstalled::kEventName,
385 std::move(sm_event_args))); 385 std::move(sm_event_args)));
386 event_router->DispatchEventWithLazyListener((*i)->id(), 386 event_router->DispatchEventWithLazyListener((*i)->id(),
387 std::move(sm_event)); 387 std::move(sm_event));
388 } 388 }
389 } 389 }
390 } 390 }
391 } 391 }
392 392
393 // static 393 // static
394 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( 394 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
395 content::BrowserContext* context, 395 content::BrowserContext* context,
396 const std::string& extension_id, 396 const std::string& extension_id,
397 const base::DictionaryValue* manifest) { 397 const base::DictionaryValue* manifest) {
398 ExtensionSystem* system = ExtensionSystem::Get(context); 398 ExtensionSystem* system = ExtensionSystem::Get(context);
399 if (!system) 399 if (!system)
400 return; 400 return;
401 401
402 scoped_ptr<base::ListValue> args(new base::ListValue); 402 std::unique_ptr<base::ListValue> args(new base::ListValue);
403 args->Append(manifest->DeepCopy()); 403 args->Append(manifest->DeepCopy());
404 EventRouter* event_router = EventRouter::Get(context); 404 EventRouter* event_router = EventRouter::Get(context);
405 DCHECK(event_router); 405 DCHECK(event_router);
406 scoped_ptr<Event> event(new Event(events::RUNTIME_ON_UPDATE_AVAILABLE, 406 std::unique_ptr<Event> event(new Event(events::RUNTIME_ON_UPDATE_AVAILABLE,
407 runtime::OnUpdateAvailable::kEventName, 407 runtime::OnUpdateAvailable::kEventName,
408 std::move(args))); 408 std::move(args)));
409 event_router->DispatchEventToExtension(extension_id, std::move(event)); 409 event_router->DispatchEventToExtension(extension_id, std::move(event));
410 } 410 }
411 411
412 // static 412 // static
413 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( 413 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(
414 content::BrowserContext* context) { 414 content::BrowserContext* context) {
415 ExtensionSystem* system = ExtensionSystem::Get(context); 415 ExtensionSystem* system = ExtensionSystem::Get(context);
416 if (!system) 416 if (!system)
417 return; 417 return;
418 418
419 scoped_ptr<base::ListValue> args(new base::ListValue); 419 std::unique_ptr<base::ListValue> args(new base::ListValue);
420 EventRouter* event_router = EventRouter::Get(context); 420 EventRouter* event_router = EventRouter::Get(context);
421 DCHECK(event_router); 421 DCHECK(event_router);
422 scoped_ptr<Event> event(new Event( 422 std::unique_ptr<Event> event(new Event(
423 events::RUNTIME_ON_BROWSER_UPDATE_AVAILABLE, 423 events::RUNTIME_ON_BROWSER_UPDATE_AVAILABLE,
424 runtime::OnBrowserUpdateAvailable::kEventName, std::move(args))); 424 runtime::OnBrowserUpdateAvailable::kEventName, std::move(args)));
425 event_router->BroadcastEvent(std::move(event)); 425 event_router->BroadcastEvent(std::move(event));
426 } 426 }
427 427
428 // static 428 // static
429 void RuntimeEventRouter::DispatchOnRestartRequiredEvent( 429 void RuntimeEventRouter::DispatchOnRestartRequiredEvent(
430 content::BrowserContext* context, 430 content::BrowserContext* context,
431 const std::string& app_id, 431 const std::string& app_id,
432 api::runtime::OnRestartRequiredReason reason) { 432 api::runtime::OnRestartRequiredReason reason) {
433 ExtensionSystem* system = ExtensionSystem::Get(context); 433 ExtensionSystem* system = ExtensionSystem::Get(context);
434 if (!system) 434 if (!system)
435 return; 435 return;
436 436
437 scoped_ptr<Event> event( 437 std::unique_ptr<Event> event(
438 new Event(events::RUNTIME_ON_RESTART_REQUIRED, 438 new Event(events::RUNTIME_ON_RESTART_REQUIRED,
439 runtime::OnRestartRequired::kEventName, 439 runtime::OnRestartRequired::kEventName,
440 api::runtime::OnRestartRequired::Create(reason))); 440 api::runtime::OnRestartRequired::Create(reason)));
441 EventRouter* event_router = EventRouter::Get(context); 441 EventRouter* event_router = EventRouter::Get(context);
442 DCHECK(event_router); 442 DCHECK(event_router);
443 event_router->DispatchEventToExtension(app_id, std::move(event)); 443 event_router->DispatchEventToExtension(app_id, std::move(event));
444 } 444 }
445 445
446 // static 446 // static
447 void RuntimeEventRouter::OnExtensionUninstalled( 447 void RuntimeEventRouter::OnExtensionUninstalled(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 content::ChildProcessSecurityPolicy* policy = 577 content::ChildProcessSecurityPolicy* policy =
578 content::ChildProcessSecurityPolicy::GetInstance(); 578 content::ChildProcessSecurityPolicy::GetInstance();
579 policy->GrantReadFileSystem(renderer_id, filesystem_id); 579 policy->GrantReadFileSystem(renderer_id, filesystem_id);
580 base::DictionaryValue* dict = new base::DictionaryValue(); 580 base::DictionaryValue* dict = new base::DictionaryValue();
581 dict->SetString("fileSystemId", filesystem_id); 581 dict->SetString("fileSystemId", filesystem_id);
582 dict->SetString("baseName", relative_path); 582 dict->SetString("baseName", relative_path);
583 return RespondNow(OneArgument(dict)); 583 return RespondNow(OneArgument(dict));
584 } 584 }
585 585
586 } // namespace extensions 586 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/runtime/runtime_api.h ('k') | extensions/browser/api/runtime/runtime_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698