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

Side by Side Diff: chrome/browser/feedback/feedback_dialog_utils.cc

Issue 2190653003: [Md Feedback] Add initial data population for dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 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 2016 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 <string> 5 #include "chrome/browser/feedback/feedback_dialog_utils.h"
6 6
7 #include "build/build_config.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
10 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 9 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
14 #include "chrome/browser/ui/browser_finder.h" 10 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/webui/md_feedback/md_feedback_dialog_controller.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "components/signin/core/account_id/account_id.h"
20 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
21 #include "url/gurl.h" 13 #include "url/gurl.h"
22 14
23 namespace { 15 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "components/signin/core/account_id/account_id.h"
20 #endif
21
22 namespace chrome {
24 23
25 GURL GetTargetTabUrl(int session_id, int index) { 24 GURL GetTargetTabUrl(int session_id, int index) {
26 Browser* browser = chrome::FindBrowserWithID(session_id); 25 Browser* browser = chrome::FindBrowserWithID(session_id);
27 // Sanity checks. 26 // Sanity checks.
28 if (!browser || index >= browser->tab_strip_model()->count()) 27 if (!browser || index >= browser->tab_strip_model()->count())
29 return GURL(); 28 return GURL();
30 29
31 if (index >= 0) { 30 if (index >= 0) {
32 content::WebContents* target_tab = 31 content::WebContents* target_tab =
33 browser->tab_strip_model()->GetWebContentsAt(index); 32 browser->tab_strip_model()->GetWebContentsAt(index);
34 if (target_tab) 33 if (target_tab)
35 return target_tab->GetURL(); 34 return target_tab->GetURL();
36 } 35 }
37 36
38 return GURL(); 37 return GURL();
39 } 38 }
40 39
41 } // namespace 40 Profile* GetFeedbackProfile(Browser* browser) {
42
43 namespace chrome {
44
45 void ShowFeedbackPage(Browser* browser,
46 const std::string& description_template,
47 const std::string& category_tag) {
48 GURL page_url;
49 if (browser) {
50 page_url = GetTargetTabUrl(browser->session_id().id(),
51 browser->tab_strip_model()->active_index());
52 }
53
54 Profile* profile = NULL; 41 Profile* profile = NULL;
afakhry 2016/09/14 01:48:15 nullptr.
apacible 2016/09/14 17:53:19 Done.
55 if (browser) { 42 if (browser) {
afakhry 2016/09/14 01:48:15 Nit: please remove curly braces from single-line i
apacible 2016/09/14 17:53:19 Done.
56 profile = browser->profile(); 43 profile = browser->profile();
57 } else { 44 } else {
58 profile = ProfileManager::GetLastUsedProfileAllowedByPolicy(); 45 profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
59 } 46 }
60 if (!profile) { 47 if (!profile)
61 LOG(ERROR) << "Cannot invoke feedback: No profile found!"; 48 return NULL;
afakhry 2016/09/14 01:48:15 nullptr.
apacible 2016/09/14 17:53:20 Done.
62 return;
63 }
64 49
65 // We do not want to launch on an OTR profile. 50 // We do not want to launch on an OTR profile.
66 profile = profile->GetOriginalProfile(); 51 profile = profile->GetOriginalProfile();
67 DCHECK(profile); 52 DCHECK(profile);
68 53
69 #if defined(OS_CHROMEOS) 54 #if defined(OS_CHROMEOS)
70 // Obtains the display profile ID on which the Feedback window should show. 55 // Obtains the display profile ID on which the Feedback window should show.
71 chrome::MultiUserWindowManager* const window_manager = 56 chrome::MultiUserWindowManager* const window_manager =
72 chrome::MultiUserWindowManager::GetInstance(); 57 chrome::MultiUserWindowManager::GetInstance();
73 const AccountId display_account_id = 58 const AccountId display_account_id =
74 window_manager && browser 59 window_manager && browser
75 ? window_manager->GetUserPresentingWindow( 60 ? window_manager->GetUserPresentingWindow(
76 browser->window()->GetNativeWindow()) 61 browser->window()->GetNativeWindow())
77 : EmptyAccountId(); 62 : EmptyAccountId();
78 profile = display_account_id.is_valid() 63 profile = display_account_id.is_valid()
79 ? multi_user_util::GetProfileFromAccountId(display_account_id) 64 ? multi_user_util::GetProfileFromAccountId(display_account_id)
80 : profile; 65 : profile;
afakhry 2016/09/14 01:48:15 This, however, is more suitable for an if(), since
apacible 2016/09/14 17:53:20 Done.
81 #endif 66 #endif
82 67 return profile;
83 if (::switches::MdFeedbackEnabled()) {
84 MdFeedbackDialogController::GetInstance()->Show(profile);
85 return;
86 }
87
88 extensions::FeedbackPrivateAPI* api =
89 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile);
90
91 api->RequestFeedback(description_template,
92 category_tag,
93 page_url);
94 } 68 }
95 69
96 } // namespace chrome 70 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698