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

Side by Side Diff: chrome/browser/extensions/api/feedback_private/feedback_private_api.cc

Issue 17111003: Implement the feedbackPrivate API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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.
4
5 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h"
11 #include "chrome/browser/extensions/api/feedback_private/blob_reader.h"
asargent_no_longer_on_chrome 2013/06/17 19:32:40 nit: I don't actually see you using the BlobReader
rkc 2013/06/17 21:48:19 Done.
12 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h"
13 #include "chrome/browser/extensions/event_names.h"
14 #include "chrome/browser/extensions/event_router.h"
15 #include "chrome/browser/extensions/extension_system.h"
16 #include "googleurl/src/url_util.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/webui/web_ui_util.h"
20
21
22 namespace extensions {
23
24 using api::feedback_private::SystemInformation;
25 using api::feedback_private::FeedbackInfo;
26
27 static base::LazyInstance<ProfileKeyedAPIFactory<FeedbackPrivateAPI> >
28 g_factory = LAZY_INSTANCE_INITIALIZER;
asargent_no_longer_on_chrome 2013/06/17 19:32:40 style nit: shouldn't line 28 here have a 4-charact
rkc 2013/06/17 21:48:19 Done.
29
30 // static
31 ProfileKeyedAPIFactory<FeedbackPrivateAPI>*
32 FeedbackPrivateAPI::GetFactoryInstance() {
33 return &g_factory.Get();
34 }
35
36 FeedbackPrivateAPI::FeedbackPrivateAPI(Profile* profile)
37 : profile_(profile),
38 service_(FeedbackService::CreateInstance()) {
39 }
40
41 FeedbackPrivateAPI::~FeedbackPrivateAPI() {
42 delete service_;
43 service_ = NULL;
44 }
45
46 FeedbackService* FeedbackPrivateAPI::GetService() const {
47 return service_;
48 }
49
50 void FeedbackPrivateAPI::RequestFeedback(
51 const std::string& description_template,
52 const std::string& category_tag,
53 const GURL& page_url) {
54 if (profile_ && ExtensionSystem::Get(profile_)->event_router()) {
asargent_no_longer_on_chrome 2013/06/17 19:32:40 Will the feedback extension always be installed, o
rkc 2013/06/17 21:48:19 Since the current feedback UI is available in all
55 FeedbackInfo info;
56 info.description = description_template;
57 info.category_tag = make_scoped_ptr(new std::string(category_tag));
58 info.page_url = make_scoped_ptr(new std::string(page_url.spec()));
59
60 scoped_ptr<base::ListValue> args(new base::ListValue());
61 args->Append(info.ToValue().release());
62
63 scoped_ptr<Event> event(
64 new Event(event_names::kOnFeedbackRequested, args.Pass()));
65 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(
66 event.Pass());
67 }
68 }
69
70 bool FeedbackPrivateGetUserEmailFunction::RunImpl() {
71 FeedbackService* service =
72 FeedbackPrivateAPI::GetFactoryInstance()->GetForProfile(
73 profile())->GetService();
74 DCHECK(service);
75 SetResult(base::Value::CreateStringValue(service->GetUserEmail()));
76 return true;
77 }
78
79 bool FeedbackPrivateGetSystemInformationFunction::RunImpl() {
80 FeedbackService* service =
81 FeedbackPrivateAPI::GetFactoryInstance()->GetForProfile(
82 profile())->GetService();
83 DCHECK(service);
84 service->GetSystemInformation(
85 base::Bind(
86 &FeedbackPrivateGetSystemInformationFunction
87 ::OnGetSystemInformationCompleted, this));
88 return true;
89 }
90
91 void FeedbackPrivateGetSystemInformationFunction
92 ::OnGetSystemInformationCompleted(const SystemInformationList& sys_info) {
asargent_no_longer_on_chrome 2013/06/17 19:32:40 optional suggestion: could you just rename this fu
rkc 2013/06/17 21:48:19 I agree, this was really looking quite ugly. Chang
93 results_ = api::feedback_private::GetSystemInformation::Results::Create(
94 sys_info);
95 SendResponse(true);
96 }
97
98 bool FeedbackPrivateSendFeedbackFunction::RunImpl() {
99 scoped_ptr<api::feedback_private::SendFeedback::Params> params(
100 api::feedback_private::SendFeedback::Params::Create(*args_));
101 EXTENSION_FUNCTION_VALIDATE(params.get());
102
103 const FeedbackInfo &feedback_info = params->feedback;
104
105 std::string description = feedback_info.description;
106 std::string attached_file_url = feedback_info.attached_file_blob_url;
107 std::string screenshot_url = feedback_info.screenshot_blob_url;
108
109 // Populate feedback data.
110 scoped_refptr<FeedbackData> feedback_data(new FeedbackData());
111 feedback_data->set_profile(profile_);
112 feedback_data->set_description(feedback_info.description);
113
114 if (feedback_info.category_tag.get())
115 feedback_data->set_category_tag(*feedback_info.category_tag.get());
116 if (feedback_info.page_url.get())
117 feedback_data->set_page_url(*feedback_info.page_url.get());
118 if (feedback_info.email.get())
119 feedback_data->set_user_email(*feedback_info.email.get());
120
121 if (feedback_info.attached_file.get() &&
122 !feedback_info.attached_file_blob_url.empty()) {
123 feedback_data->set_attached_filename(
124 (*feedback_info.attached_file.get()).name);
125 feedback_data->set_attached_file_url(
126 GURL(feedback_info.attached_file_blob_url));
127 }
128 feedback_data->set_screenshot_url(GURL(feedback_info.screenshot_blob_url));
129
130 // TODO(rkc): Take this out of OS_CHROMEOS once we have FeedbackData and
131 // FeedbackUtil migrated to handle system logs for both Chrome and ChromeOS.
132 #if defined(OS_CHROMEOS)
133 scoped_ptr<chromeos::SystemLogsResponse> sys_logs(
134 new chromeos::SystemLogsResponse);
135 SystemInformationList* sys_info = feedback_info.system_information.get();
136 if (sys_info) {
137 for (SystemInformationList::iterator it = sys_info->begin();
138 it != sys_info->end(); ++it)
139 (*sys_logs.get())[it->get()->key] = it->get()->value;
140 }
141 feedback_data->set_sys_info(sys_logs.Pass());
142 #endif
143
144 FeedbackService* service = FeedbackPrivateAPI::GetFactoryInstance()->
145 GetForProfile(profile())->GetService();
146 DCHECK(service);
147 service->SendFeedback(profile(),
148 feedback_data, base::Bind(
149 &FeedbackPrivateSendFeedbackFunction::OnSendFeedbackCompleted,
150 this));
151 return true;
152 }
153
154 void FeedbackPrivateSendFeedbackFunction::OnSendFeedbackCompleted(
155 bool success) {
156 results_ = api::feedback_private::SendFeedback::Results::Create(
157 success == true ? api::feedback_private::STATUS_SUCCESS :
asargent_no_longer_on_chrome 2013/06/17 19:32:40 nit: can you remove the "== true" part and just ha
rkc 2013/06/17 21:48:19 Done.
158 api::feedback_private::STATUS_DELAYED);
159 SendResponse(true);
160 }
161
162 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698