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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_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: 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 (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/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/tab_helper.h" 10 #include "chrome/browser/extensions/tab_helper.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // This URL is not actually used for navigation. It holds the extension's ID. 92 // This URL is not actually used for navigation. It holds the extension's ID.
93 return std::string(extensions::kExtensionScheme) + "://" + 93 return std::string(extensions::kExtensionScheme) + "://" +
94 extension_id + "/?q={searchTerms}"; 94 extension_id + "/?q={searchTerms}";
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 // static 99 // static
100 void ExtensionOmniboxEventRouter::OnInputStarted( 100 void ExtensionOmniboxEventRouter::OnInputStarted(
101 Profile* profile, const std::string& extension_id) { 101 Profile* profile, const std::string& extension_id) {
102 scoped_ptr<Event> event(new Event( 102 scoped_ptr<Event> event(new Event(events::UNKNOWN,
103 omnibox::OnInputStarted::kEventName, 103 omnibox::OnInputStarted::kEventName,
104 make_scoped_ptr(new base::ListValue()))); 104 make_scoped_ptr(new base::ListValue())));
105 event->restrict_to_browser_context = profile; 105 event->restrict_to_browser_context = profile;
106 EventRouter::Get(profile) 106 EventRouter::Get(profile)
107 ->DispatchEventToExtension(extension_id, event.Pass()); 107 ->DispatchEventToExtension(extension_id, event.Pass());
108 } 108 }
109 109
110 // static 110 // static
111 bool ExtensionOmniboxEventRouter::OnInputChanged( 111 bool ExtensionOmniboxEventRouter::OnInputChanged(
112 Profile* profile, const std::string& extension_id, 112 Profile* profile, const std::string& extension_id,
113 const std::string& input, int suggest_id) { 113 const std::string& input, int suggest_id) {
114 EventRouter* event_router = EventRouter::Get(profile); 114 EventRouter* event_router = EventRouter::Get(profile);
115 if (!event_router->ExtensionHasEventListener( 115 if (!event_router->ExtensionHasEventListener(
116 extension_id, omnibox::OnInputChanged::kEventName)) 116 extension_id, omnibox::OnInputChanged::kEventName))
117 return false; 117 return false;
118 118
119 scoped_ptr<base::ListValue> args(new base::ListValue()); 119 scoped_ptr<base::ListValue> args(new base::ListValue());
120 args->Set(0, new base::StringValue(input)); 120 args->Set(0, new base::StringValue(input));
121 args->Set(1, new base::FundamentalValue(suggest_id)); 121 args->Set(1, new base::FundamentalValue(suggest_id));
122 122
123 scoped_ptr<Event> event(new Event(omnibox::OnInputChanged::kEventName, 123 scoped_ptr<Event> event(new Event(
124 args.Pass())); 124 events::UNKNOWN, omnibox::OnInputChanged::kEventName, args.Pass()));
125 event->restrict_to_browser_context = profile; 125 event->restrict_to_browser_context = profile;
126 event_router->DispatchEventToExtension(extension_id, event.Pass()); 126 event_router->DispatchEventToExtension(extension_id, event.Pass());
127 return true; 127 return true;
128 } 128 }
129 129
130 // static 130 // static
131 void ExtensionOmniboxEventRouter::OnInputEntered( 131 void ExtensionOmniboxEventRouter::OnInputEntered(
132 content::WebContents* web_contents, 132 content::WebContents* web_contents,
133 const std::string& extension_id, 133 const std::string& extension_id,
134 const std::string& input, 134 const std::string& input,
(...skipping 10 matching lines...) Expand all
145 145
146 scoped_ptr<base::ListValue> args(new base::ListValue()); 146 scoped_ptr<base::ListValue> args(new base::ListValue());
147 args->Set(0, new base::StringValue(input)); 147 args->Set(0, new base::StringValue(input));
148 if (disposition == NEW_FOREGROUND_TAB) 148 if (disposition == NEW_FOREGROUND_TAB)
149 args->Set(1, new base::StringValue(kForegroundTabDisposition)); 149 args->Set(1, new base::StringValue(kForegroundTabDisposition));
150 else if (disposition == NEW_BACKGROUND_TAB) 150 else if (disposition == NEW_BACKGROUND_TAB)
151 args->Set(1, new base::StringValue(kBackgroundTabDisposition)); 151 args->Set(1, new base::StringValue(kBackgroundTabDisposition));
152 else 152 else
153 args->Set(1, new base::StringValue(kCurrentTabDisposition)); 153 args->Set(1, new base::StringValue(kCurrentTabDisposition));
154 154
155 scoped_ptr<Event> event(new Event(omnibox::OnInputEntered::kEventName, 155 scoped_ptr<Event> event(new Event(
156 args.Pass())); 156 events::UNKNOWN, omnibox::OnInputEntered::kEventName, args.Pass()));
157 event->restrict_to_browser_context = profile; 157 event->restrict_to_browser_context = profile;
158 EventRouter::Get(profile) 158 EventRouter::Get(profile)
159 ->DispatchEventToExtension(extension_id, event.Pass()); 159 ->DispatchEventToExtension(extension_id, event.Pass());
160 160
161 content::NotificationService::current()->Notify( 161 content::NotificationService::current()->Notify(
162 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, 162 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
163 content::Source<Profile>(profile), 163 content::Source<Profile>(profile),
164 content::NotificationService::NoDetails()); 164 content::NotificationService::NoDetails());
165 } 165 }
166 166
167 // static 167 // static
168 void ExtensionOmniboxEventRouter::OnInputCancelled( 168 void ExtensionOmniboxEventRouter::OnInputCancelled(
169 Profile* profile, const std::string& extension_id) { 169 Profile* profile, const std::string& extension_id) {
170 scoped_ptr<Event> event(new Event( 170 scoped_ptr<Event> event(new Event(events::UNKNOWN,
171 omnibox::OnInputCancelled::kEventName, 171 omnibox::OnInputCancelled::kEventName,
172 make_scoped_ptr(new base::ListValue()))); 172 make_scoped_ptr(new base::ListValue())));
173 event->restrict_to_browser_context = profile; 173 event->restrict_to_browser_context = profile;
174 EventRouter::Get(profile) 174 EventRouter::Get(profile)
175 ->DispatchEventToExtension(extension_id, event.Pass()); 175 ->DispatchEventToExtension(extension_id, event.Pass());
176 } 176 }
177 177
178 OmniboxAPI::OmniboxAPI(content::BrowserContext* context) 178 OmniboxAPI::OmniboxAPI(content::BrowserContext* context)
179 : profile_(Profile::FromBrowserContext(context)), 179 : profile_(Profile::FromBrowserContext(context)),
180 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), 180 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
181 extension_registry_observer_(this) { 181 extension_registry_observer_(this) {
182 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); 182 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 for (size_t i = 0; i < description_styles.size(); ++i) { 389 for (size_t i = 0; i < description_styles.size(); ++i) {
390 if (description_styles[i].offset > placeholder) 390 if (description_styles[i].offset > placeholder)
391 description_styles[i].offset += replacement.length() - 2; 391 description_styles[i].offset += replacement.length() - 2;
392 } 392 }
393 } 393 }
394 394
395 match->contents.assign(description); 395 match->contents.assign(description);
396 } 396 }
397 397
398 } // namespace extensions 398 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698