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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 12375006: Added UMA stats for extensions events on addListener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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/extensions/api/omnibox/omnibox_api.h" 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/search_engines/template_url_service_factory.h" 21 #include "chrome/browser/search_engines/template_url_service_factory.h"
22 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" 23 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
24 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/extensions/extension_manifest_constants.h" 25 #include "chrome/common/extensions/extension_manifest_constants.h"
26 #include "chrome/common/extensions/manifest_handler.h" 26 #include "chrome/common/extensions/manifest_handler.h"
27 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "ui/gfx/image/image.h" 29 #include "ui/gfx/image/image.h"
30 30
31 namespace events { 31 namespace event_names {
32 const char kOnInputStarted[] = "omnibox.onInputStarted"; 32 const char kOnInputStarted[] = "omnibox.onInputStarted";
33 const char kOnInputChanged[] = "omnibox.onInputChanged"; 33 const char kOnInputChanged[] = "omnibox.onInputChanged";
34 const char kOnInputEntered[] = "omnibox.onInputEntered"; 34 const char kOnInputEntered[] = "omnibox.onInputEntered";
35 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; 35 const char kOnInputCancelled[] = "omnibox.onInputCancelled";
36 } // namespace events 36 } // namespace event_names
37 37
38 namespace extensions { 38 namespace extensions {
39 39
40 namespace { 40 namespace {
41 41
42 const char kSuggestionContent[] = "content"; 42 const char kSuggestionContent[] = "content";
43 const char kSuggestionDescription[] = "description"; 43 const char kSuggestionDescription[] = "description";
44 const char kSuggestionDescriptionStyles[] = "descriptionStyles"; 44 const char kSuggestionDescriptionStyles[] = "descriptionStyles";
45 const char kSuggestionDescriptionStylesRaw[] = "descriptionStylesRaw"; 45 const char kSuggestionDescriptionStylesRaw[] = "descriptionStylesRaw";
46 const char kDescriptionStylesType[] = "type"; 46 const char kDescriptionStylesType[] = "type";
(...skipping 10 matching lines...) Expand all
57 static const int kOmniboxIconPaddingLeft = 0; 57 static const int kOmniboxIconPaddingLeft = 0;
58 static const int kOmniboxIconPaddingRight = 0; 58 static const int kOmniboxIconPaddingRight = 0;
59 #endif 59 #endif
60 60
61 } // namespace 61 } // namespace
62 62
63 // static 63 // static
64 void ExtensionOmniboxEventRouter::OnInputStarted( 64 void ExtensionOmniboxEventRouter::OnInputStarted(
65 Profile* profile, const std::string& extension_id) { 65 Profile* profile, const std::string& extension_id) {
66 scoped_ptr<Event> event(new Event( 66 scoped_ptr<Event> event(new Event(
67 events::kOnInputStarted, make_scoped_ptr(new ListValue()))); 67 event_names::kOnInputStarted, make_scoped_ptr(new ListValue())));
68 event->restrict_to_profile = profile; 68 event->restrict_to_profile = profile;
69 ExtensionSystem::Get(profile)->event_router()-> 69 ExtensionSystem::Get(profile)->event_router()->
70 DispatchEventToExtension(extension_id, event.Pass()); 70 DispatchEventToExtension(extension_id, event.Pass());
71 } 71 }
72 72
73 // static 73 // static
74 bool ExtensionOmniboxEventRouter::OnInputChanged( 74 bool ExtensionOmniboxEventRouter::OnInputChanged(
75 Profile* profile, const std::string& extension_id, 75 Profile* profile, const std::string& extension_id,
76 const std::string& input, int suggest_id) { 76 const std::string& input, int suggest_id) {
77 if (!extensions::ExtensionSystem::Get(profile)->event_router()-> 77 if (!extensions::ExtensionSystem::Get(profile)->event_router()->
78 ExtensionHasEventListener(extension_id, events::kOnInputChanged)) 78 ExtensionHasEventListener(extension_id, event_names::kOnInputChanged))
79 return false; 79 return false;
80 80
81 scoped_ptr<ListValue> args(new ListValue()); 81 scoped_ptr<ListValue> args(new ListValue());
82 args->Set(0, Value::CreateStringValue(input)); 82 args->Set(0, Value::CreateStringValue(input));
83 args->Set(1, Value::CreateIntegerValue(suggest_id)); 83 args->Set(1, Value::CreateIntegerValue(suggest_id));
84 84
85 scoped_ptr<Event> event(new Event(events::kOnInputChanged, args.Pass())); 85 scoped_ptr<Event> event(new Event(event_names::kOnInputChanged, args.Pass()));
86 event->restrict_to_profile = profile; 86 event->restrict_to_profile = profile;
87 ExtensionSystem::Get(profile)->event_router()-> 87 ExtensionSystem::Get(profile)->event_router()->
88 DispatchEventToExtension(extension_id, event.Pass()); 88 DispatchEventToExtension(extension_id, event.Pass());
89 return true; 89 return true;
90 } 90 }
91 91
92 // static 92 // static
93 void ExtensionOmniboxEventRouter::OnInputEntered( 93 void ExtensionOmniboxEventRouter::OnInputEntered(
94 content::WebContents* web_contents, 94 content::WebContents* web_contents,
95 const std::string& extension_id, 95 const std::string& extension_id,
96 const std::string& input) { 96 const std::string& input) {
97 Profile* profile = 97 Profile* profile =
98 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 98 Profile::FromBrowserContext(web_contents->GetBrowserContext());
99 99
100 const Extension* extension = 100 const Extension* extension =
101 ExtensionSystem::Get(profile)->extension_service()->extensions()-> 101 ExtensionSystem::Get(profile)->extension_service()->extensions()->
102 GetByID(extension_id); 102 GetByID(extension_id);
103 CHECK(extension); 103 CHECK(extension);
104 extensions::TabHelper::FromWebContents(web_contents)-> 104 extensions::TabHelper::FromWebContents(web_contents)->
105 active_tab_permission_granter()->GrantIfRequested(extension); 105 active_tab_permission_granter()->GrantIfRequested(extension);
106 106
107 scoped_ptr<ListValue> args(new ListValue()); 107 scoped_ptr<ListValue> args(new ListValue());
108 args->Set(0, Value::CreateStringValue(input)); 108 args->Set(0, Value::CreateStringValue(input));
109 109
110 scoped_ptr<Event> event(new Event(events::kOnInputEntered, args.Pass())); 110 scoped_ptr<Event> event(new Event(event_names::kOnInputEntered, args.Pass()));
111 event->restrict_to_profile = profile; 111 event->restrict_to_profile = profile;
112 ExtensionSystem::Get(profile)->event_router()-> 112 ExtensionSystem::Get(profile)->event_router()->
113 DispatchEventToExtension(extension_id, event.Pass()); 113 DispatchEventToExtension(extension_id, event.Pass());
114 114
115 content::NotificationService::current()->Notify( 115 content::NotificationService::current()->Notify(
116 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, 116 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
117 content::Source<Profile>(profile), 117 content::Source<Profile>(profile),
118 content::NotificationService::NoDetails()); 118 content::NotificationService::NoDetails());
119 } 119 }
120 120
121 // static 121 // static
122 void ExtensionOmniboxEventRouter::OnInputCancelled( 122 void ExtensionOmniboxEventRouter::OnInputCancelled(
123 Profile* profile, const std::string& extension_id) { 123 Profile* profile, const std::string& extension_id) {
124 scoped_ptr<Event> event(new Event( 124 scoped_ptr<Event> event(new Event(
125 events::kOnInputCancelled, make_scoped_ptr(new ListValue()))); 125 event_names::kOnInputCancelled, make_scoped_ptr(new ListValue())));
126 event->restrict_to_profile = profile; 126 event->restrict_to_profile = profile;
127 ExtensionSystem::Get(profile)->event_router()-> 127 ExtensionSystem::Get(profile)->event_router()->
128 DispatchEventToExtension(extension_id, event.Pass()); 128 DispatchEventToExtension(extension_id, event.Pass());
129 } 129 }
130 130
131 OmniboxAPI::OmniboxAPI(Profile* profile) 131 OmniboxAPI::OmniboxAPI(Profile* profile)
132 : profile_(profile), 132 : profile_(profile),
133 url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { 133 url_service_(TemplateURLServiceFactory::GetForProfile(profile)) {
134 ManifestHandler::Register(extension_manifest_keys::kOmnibox, 134 ManifestHandler::Register(extension_manifest_keys::kOmnibox,
135 make_linked_ptr(new OmniboxHandler)); 135 make_linked_ptr(new OmniboxHandler));
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 for (size_t i = 0; i < description_styles.size(); ++i) { 416 for (size_t i = 0; i < description_styles.size(); ++i) {
417 if (description_styles[i].offset > placeholder) 417 if (description_styles[i].offset > placeholder)
418 description_styles[i].offset += replacement.length() - 2; 418 description_styles[i].offset += replacement.length() - 2;
419 } 419 }
420 } 420 }
421 421
422 match->contents.assign(description); 422 match->contents.assign(description);
423 } 423 }
424 424
425 } // namespace extensions 425 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698