Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / feedback / show_feedback_page.cc
blobe8fe488ba2d9c1184d8c19835a50ef3ba4bd4c9d
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/ash/multi_user/multi_user_util.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "content/public/browser/web_contents.h"
17 #include "url/gurl.h"
19 namespace {
21 GURL GetTargetTabUrl(int session_id, int index) {
22 Browser* browser = chrome::FindBrowserWithID(session_id);
23 // Sanity checks.
24 if (!browser || index >= browser->tab_strip_model()->count())
25 return GURL();
27 if (index >= 0) {
28 content::WebContents* target_tab =
29 browser->tab_strip_model()->GetWebContentsAt(index);
30 if (target_tab)
31 return target_tab->GetURL();
34 return GURL();
37 } // namespace
39 namespace chrome {
41 extern const char kAppLauncherCategoryTag[] = "AppLauncher";
43 void ShowFeedbackPage(Browser* browser,
44 const std::string& description_template,
45 const std::string& category_tag) {
46 GURL page_url;
47 if (browser) {
48 page_url = GetTargetTabUrl(browser->session_id().id(),
49 browser->tab_strip_model()->active_index());
52 Profile* profile = NULL;
53 if (browser) {
54 profile = browser->profile();
55 } else {
56 profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
58 if (!profile) {
59 LOG(ERROR) << "Cannot invoke feedback: No profile found!";
60 return;
63 // We do not want to launch on an OTR profile.
64 profile = profile->GetOriginalProfile();
65 DCHECK(profile);
67 #if defined(OS_CHROMEOS)
68 // Obtains the display profile ID on which the Feedback window should show.
69 chrome::MultiUserWindowManager* const window_manager =
70 chrome::MultiUserWindowManager::GetInstance();
71 const std::string display_profile_id =
72 window_manager && browser
73 ? window_manager->GetUserPresentingWindow(
74 browser->window()->GetNativeWindow())
75 : "";
76 profile = display_profile_id.empty()
77 ? profile
78 : multi_user_util::GetProfileFromUserID(display_profile_id);
79 #endif
81 extensions::FeedbackPrivateAPI* api =
82 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile);
84 api->RequestFeedback(description_template,
85 category_tag,
86 page_url);
89 } // namespace chrome