Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / feedback / show_feedback_page.cc
blob828dee03dea902b00fc75d377d8d283dd910f681
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
3 // found in the LICENSE file.
5 #include <string>
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "content/public/browser/web_contents.h"
14 #include "url/gurl.h"
16 namespace {
18 GURL GetTargetTabUrl(int session_id, int index) {
19 Browser* browser = chrome::FindBrowserWithID(session_id);
20 // Sanity checks.
21 if (!browser || index >= browser->tab_strip_model()->count())
22 return GURL();
24 if (index >= 0) {
25 content::WebContents* target_tab =
26 browser->tab_strip_model()->GetWebContentsAt(index);
27 if (target_tab)
28 return target_tab->GetURL();
31 return GURL();
34 } // namespace
36 namespace chrome {
38 extern const char kAppLauncherCategoryTag[] = "AppLauncher";
40 void ShowFeedbackPage(Browser* browser,
41 const std::string& description_template,
42 const std::string& category_tag) {
43 GURL page_url;
44 if (browser) {
45 page_url = GetTargetTabUrl(browser->session_id().id(),
46 browser->tab_strip_model()->active_index());
49 Profile* profile = NULL;
50 if (browser) {
51 profile = browser->profile();
52 } else {
53 profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
55 if (!profile) {
56 LOG(ERROR) << "Cannot invoke feedback: No profile found!";
57 return;
60 // We do not want to launch on an OTR profile.
61 profile = profile->GetOriginalProfile();
62 DCHECK(profile);
64 extensions::FeedbackPrivateAPI* api =
65 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile);
67 api->RequestFeedback(description_template,
68 category_tag,
69 page_url);
72 } // namespace chrome