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

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

Issue 1201063002: Set up the infrastructure for Extension event metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaaaaase Created 5 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 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 <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 LazyBackgroundTaskQueue::Get(browser_context) 98 LazyBackgroundTaskQueue::Get(browser_context)
99 ->ShouldEnqueueTask(browser_context, extension)) { 99 ->ShouldEnqueueTask(browser_context, extension)) {
100 LazyBackgroundTaskQueue::Get(browser_context) 100 LazyBackgroundTaskQueue::Get(browser_context)
101 ->AddPendingTask(browser_context, extension_id, 101 ->AddPendingTask(browser_context, extension_id,
102 base::Bind(&DispatchOnStartupEventImpl, 102 base::Bind(&DispatchOnStartupEventImpl,
103 browser_context, extension_id, false)); 103 browser_context, extension_id, false));
104 return; 104 return;
105 } 105 }
106 106
107 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 107 scoped_ptr<base::ListValue> event_args(new base::ListValue());
108 scoped_ptr<Event> event( 108 scoped_ptr<Event> event(new Event(
109 new Event(runtime::OnStartup::kEventName, event_args.Pass())); 109 events::UNKNOWN, runtime::OnStartup::kEventName, event_args.Pass()));
110 EventRouter::Get(browser_context) 110 EventRouter::Get(browser_context)
111 ->DispatchEventToExtension(extension_id, event.Pass()); 111 ->DispatchEventToExtension(extension_id, event.Pass());
112 } 112 }
113 113
114 void SetUninstallURL(ExtensionPrefs* prefs, 114 void SetUninstallURL(ExtensionPrefs* prefs,
115 const std::string& extension_id, 115 const std::string& extension_id,
116 const std::string& url_string) { 116 const std::string& url_string) {
117 prefs->UpdateExtensionPref( 117 prefs->UpdateExtensionPref(
118 extension_id, kUninstallUrl, new base::StringValue(url_string)); 118 extension_id, kUninstallUrl, new base::StringValue(url_string));
119 } 119 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 if (old_version.IsValid()) { 300 if (old_version.IsValid()) {
301 info->SetString(kInstallReason, kInstallReasonUpdate); 301 info->SetString(kInstallReason, kInstallReasonUpdate);
302 info->SetString(kInstallPreviousVersion, old_version.GetString()); 302 info->SetString(kInstallPreviousVersion, old_version.GetString());
303 } else if (chrome_updated) { 303 } else if (chrome_updated) {
304 info->SetString(kInstallReason, kInstallReasonChromeUpdate); 304 info->SetString(kInstallReason, kInstallReasonChromeUpdate);
305 } else { 305 } else {
306 info->SetString(kInstallReason, kInstallReasonInstall); 306 info->SetString(kInstallReason, kInstallReasonInstall);
307 } 307 }
308 EventRouter* event_router = EventRouter::Get(context); 308 EventRouter* event_router = EventRouter::Get(context);
309 DCHECK(event_router); 309 DCHECK(event_router);
310 scoped_ptr<Event> event( 310 scoped_ptr<Event> event(new Event(
311 new Event(runtime::OnInstalled::kEventName, event_args.Pass())); 311 events::UNKNOWN, runtime::OnInstalled::kEventName, event_args.Pass()));
312 event_router->DispatchEventWithLazyListener(extension_id, event.Pass()); 312 event_router->DispatchEventWithLazyListener(extension_id, event.Pass());
313 313
314 if (old_version.IsValid()) { 314 if (old_version.IsValid()) {
315 const Extension* extension = 315 const Extension* extension =
316 ExtensionRegistry::Get(context)->enabled_extensions().GetByID( 316 ExtensionRegistry::Get(context)->enabled_extensions().GetByID(
317 extension_id); 317 extension_id);
318 if (extension && SharedModuleInfo::IsSharedModule(extension)) { 318 if (extension && SharedModuleInfo::IsSharedModule(extension)) {
319 scoped_ptr<ExtensionSet> dependents = 319 scoped_ptr<ExtensionSet> dependents =
320 system->GetDependentExtensions(extension); 320 system->GetDependentExtensions(extension);
321 for (ExtensionSet::const_iterator i = dependents->begin(); 321 for (ExtensionSet::const_iterator i = dependents->begin();
322 i != dependents->end(); 322 i != dependents->end();
323 i++) { 323 i++) {
324 scoped_ptr<base::ListValue> sm_event_args(new base::ListValue()); 324 scoped_ptr<base::ListValue> sm_event_args(new base::ListValue());
325 base::DictionaryValue* sm_info = new base::DictionaryValue(); 325 base::DictionaryValue* sm_info = new base::DictionaryValue();
326 sm_event_args->Append(sm_info); 326 sm_event_args->Append(sm_info);
327 sm_info->SetString(kInstallReason, kInstallReasonSharedModuleUpdate); 327 sm_info->SetString(kInstallReason, kInstallReasonSharedModuleUpdate);
328 sm_info->SetString(kInstallPreviousVersion, old_version.GetString()); 328 sm_info->SetString(kInstallPreviousVersion, old_version.GetString());
329 sm_info->SetString(kInstallId, extension_id); 329 sm_info->SetString(kInstallId, extension_id);
330 scoped_ptr<Event> sm_event( 330 scoped_ptr<Event> sm_event(new Event(events::UNKNOWN,
331 new Event(runtime::OnInstalled::kEventName, sm_event_args.Pass())); 331 runtime::OnInstalled::kEventName,
332 sm_event_args.Pass()));
332 event_router->DispatchEventWithLazyListener((*i)->id(), 333 event_router->DispatchEventWithLazyListener((*i)->id(),
333 sm_event.Pass()); 334 sm_event.Pass());
334 } 335 }
335 } 336 }
336 } 337 }
337 } 338 }
338 339
339 // static 340 // static
340 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( 341 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
341 content::BrowserContext* context, 342 content::BrowserContext* context,
342 const std::string& extension_id, 343 const std::string& extension_id,
343 const base::DictionaryValue* manifest) { 344 const base::DictionaryValue* manifest) {
344 ExtensionSystem* system = ExtensionSystem::Get(context); 345 ExtensionSystem* system = ExtensionSystem::Get(context);
345 if (!system) 346 if (!system)
346 return; 347 return;
347 348
348 scoped_ptr<base::ListValue> args(new base::ListValue); 349 scoped_ptr<base::ListValue> args(new base::ListValue);
349 args->Append(manifest->DeepCopy()); 350 args->Append(manifest->DeepCopy());
350 EventRouter* event_router = EventRouter::Get(context); 351 EventRouter* event_router = EventRouter::Get(context);
351 DCHECK(event_router); 352 DCHECK(event_router);
352 scoped_ptr<Event> event( 353 scoped_ptr<Event> event(new Event(
353 new Event(runtime::OnUpdateAvailable::kEventName, args.Pass())); 354 events::UNKNOWN, runtime::OnUpdateAvailable::kEventName, args.Pass()));
354 event_router->DispatchEventToExtension(extension_id, event.Pass()); 355 event_router->DispatchEventToExtension(extension_id, event.Pass());
355 } 356 }
356 357
357 // static 358 // static
358 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( 359 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(
359 content::BrowserContext* context) { 360 content::BrowserContext* context) {
360 ExtensionSystem* system = ExtensionSystem::Get(context); 361 ExtensionSystem* system = ExtensionSystem::Get(context);
361 if (!system) 362 if (!system)
362 return; 363 return;
363 364
364 scoped_ptr<base::ListValue> args(new base::ListValue); 365 scoped_ptr<base::ListValue> args(new base::ListValue);
365 EventRouter* event_router = EventRouter::Get(context); 366 EventRouter* event_router = EventRouter::Get(context);
366 DCHECK(event_router); 367 DCHECK(event_router);
367 scoped_ptr<Event> event( 368 scoped_ptr<Event> event(
368 new Event(runtime::OnBrowserUpdateAvailable::kEventName, args.Pass())); 369 new Event(events::UNKNOWN, runtime::OnBrowserUpdateAvailable::kEventName,
370 args.Pass()));
369 event_router->BroadcastEvent(event.Pass()); 371 event_router->BroadcastEvent(event.Pass());
370 } 372 }
371 373
372 // static 374 // static
373 void RuntimeEventRouter::DispatchOnRestartRequiredEvent( 375 void RuntimeEventRouter::DispatchOnRestartRequiredEvent(
374 content::BrowserContext* context, 376 content::BrowserContext* context,
375 const std::string& app_id, 377 const std::string& app_id,
376 core_api::runtime::OnRestartRequiredReason reason) { 378 core_api::runtime::OnRestartRequiredReason reason) {
377 ExtensionSystem* system = ExtensionSystem::Get(context); 379 ExtensionSystem* system = ExtensionSystem::Get(context);
378 if (!system) 380 if (!system)
379 return; 381 return;
380 382
381 scoped_ptr<Event> event( 383 scoped_ptr<Event> event(
382 new Event(runtime::OnRestartRequired::kEventName, 384 new Event(events::UNKNOWN, runtime::OnRestartRequired::kEventName,
383 core_api::runtime::OnRestartRequired::Create(reason))); 385 core_api::runtime::OnRestartRequired::Create(reason)));
384 EventRouter* event_router = EventRouter::Get(context); 386 EventRouter* event_router = EventRouter::Get(context);
385 DCHECK(event_router); 387 DCHECK(event_router);
386 event_router->DispatchEventToExtension(app_id, event.Pass()); 388 event_router->DispatchEventToExtension(app_id, event.Pass());
387 } 389 }
388 390
389 // static 391 // static
390 void RuntimeEventRouter::OnExtensionUninstalled( 392 void RuntimeEventRouter::OnExtensionUninstalled(
391 content::BrowserContext* context, 393 content::BrowserContext* context,
392 const std::string& extension_id, 394 const std::string& extension_id,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 content::ChildProcessSecurityPolicy* policy = 521 content::ChildProcessSecurityPolicy* policy =
520 content::ChildProcessSecurityPolicy::GetInstance(); 522 content::ChildProcessSecurityPolicy::GetInstance();
521 policy->GrantReadFileSystem(renderer_id, filesystem_id); 523 policy->GrantReadFileSystem(renderer_id, filesystem_id);
522 base::DictionaryValue* dict = new base::DictionaryValue(); 524 base::DictionaryValue* dict = new base::DictionaryValue();
523 dict->SetString("fileSystemId", filesystem_id); 525 dict->SetString("fileSystemId", filesystem_id);
524 dict->SetString("baseName", relative_path); 526 dict->SetString("baseName", relative_path);
525 return RespondNow(OneArgument(dict)); 527 return RespondNow(OneArgument(dict));
526 } 528 }
527 529
528 } // namespace extensions 530 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698