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

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

Issue 2840103002: Add new API function: feedbackPrivate.readLogSource (Closed)
Patch Set: Rebased. Created 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/feedback_private/feedback_private_api.h" 5 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
6 6
7 #include <memory>
8 #include <string> 7 #include <string>
9 #include <utility> 8 #include <utility>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
15 #include "base/metrics/statistics_recorder.h" 14 #include "base/metrics/statistics_recorder.h"
16 #include "base/metrics/user_metrics.h" 15 #include "base/metrics/user_metrics.h"
17 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
(...skipping 12 matching lines...) Expand all
30 #include "components/feedback/tracing_manager.h" 29 #include "components/feedback/tracing_manager.h"
31 #include "components/signin/core/browser/signin_manager.h" 30 #include "components/signin/core/browser/signin_manager.h"
32 #include "components/strings/grit/components_strings.h" 31 #include "components/strings/grit/components_strings.h"
33 #include "extensions/browser/event_router.h" 32 #include "extensions/browser/event_router.h"
34 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/webui/web_ui_util.h" 34 #include "ui/base/webui/web_ui_util.h"
36 #include "url/url_util.h" 35 #include "url/url_util.h"
37 36
38 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
39 #include "chrome/browser/chromeos/arc/arc_util.h" 38 #include "chrome/browser/chromeos/arc/arc_util.h"
39 #include "chrome/browser/extensions/api/feedback_private/log_source_access_manag er.h"
40 #endif // defined(OS_CHROMEOS) 40 #endif // defined(OS_CHROMEOS)
41 41
42 #if defined(OS_WIN) 42 #if defined(OS_WIN)
43 #include "base/feature_list.h" 43 #include "base/feature_list.h"
44 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" 44 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h"
45 #endif 45 #endif
46 46
47 using extensions::api::feedback_private::SystemInformation; 47 using extensions::api::feedback_private::SystemInformation;
48 using feedback::FeedbackData; 48 using feedback::FeedbackData;
49 49
(...skipping 15 matching lines...) Expand all
65 "SrtPromptOnFeedbackForm", base::FEATURE_DISABLED_BY_DEFAULT 65 "SrtPromptOnFeedbackForm", base::FEATURE_DISABLED_BY_DEFAULT
66 }; 66 };
67 #endif 67 #endif
68 68
69 } // namespace 69 } // namespace
70 70
71 namespace extensions { 71 namespace extensions {
72 72
73 namespace feedback_private = api::feedback_private; 73 namespace feedback_private = api::feedback_private;
74 74
75 using feedback_private::SystemInformation;
76 using feedback_private::FeedbackInfo; 75 using feedback_private::FeedbackInfo;
77 using feedback_private::FeedbackFlow; 76 using feedback_private::FeedbackFlow;
77 using feedback_private::LogSource;
78 using feedback_private::SystemInformation;
78 79
79 using SystemInformationList = 80 using SystemInformationList =
80 std::vector<api::feedback_private::SystemInformation>; 81 std::vector<api::feedback_private::SystemInformation>;
81 82
82 static base::LazyInstance<BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>>:: 83 static base::LazyInstance<BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>>::
83 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER; 84 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER;
84 85
85 // static 86 // static
86 BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>* 87 BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>*
87 FeedbackPrivateAPI::GetFactoryInstance() { 88 FeedbackPrivateAPI::GetFactoryInstance() {
88 return g_factory.Pointer(); 89 return g_factory.Pointer();
89 } 90 }
90 91
91 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) 92 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context)
92 : browser_context_(context), service_(new FeedbackService()) { 93 : browser_context_(context),
94 service_(new FeedbackService()),
95 log_source_access_manager_(new LogSourceAccessManager(context)) {}
96
97 FeedbackPrivateAPI::~FeedbackPrivateAPI() {}
98
99 FeedbackService* FeedbackPrivateAPI::GetService() const {
100 return service_.get();
93 } 101 }
94 102
95 FeedbackPrivateAPI::~FeedbackPrivateAPI() { 103 #if defined(OS_CHROMEOS)
96 delete service_; 104 LogSourceAccessManager* FeedbackPrivateAPI::GetLogSourceAccessManager() const {
97 service_ = NULL; 105 return log_source_access_manager_.get();
98 } 106 }
99 107 #endif
100 FeedbackService* FeedbackPrivateAPI::GetService() const {
101 return service_;
102 }
103 108
104 void FeedbackPrivateAPI::RequestFeedback( 109 void FeedbackPrivateAPI::RequestFeedback(
105 const std::string& description_template, 110 const std::string& description_template,
106 const std::string& category_tag, 111 const std::string& category_tag,
107 const GURL& page_url) { 112 const GURL& page_url) {
108 #if defined(OS_WIN) 113 #if defined(OS_WIN)
109 // Show prompt for Software Removal Tool if the Reporter component has found 114 // Show prompt for Software Removal Tool if the Reporter component has found
110 // unwanted software, and the user has never run the cleaner before. 115 // unwanted software, and the user has never run the cleaner before.
111 if (base::FeatureList::IsEnabled(kSrtPromptOnFeedbackForm) && 116 if (base::FeatureList::IsEnabled(kSrtPromptOnFeedbackForm) &&
112 safe_browsing::ReporterFoundUws() && 117 safe_browsing::ReporterFoundUws() &&
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 sys_info_entry.key = std::move(itr.first); 263 sys_info_entry.key = std::move(itr.first);
259 sys_info_entry.value = std::move(itr.second); 264 sys_info_entry.value = std::move(itr.second);
260 sys_info_list.emplace_back(std::move(sys_info_entry)); 265 sys_info_list.emplace_back(std::move(sys_info_entry));
261 } 266 }
262 } 267 }
263 268
264 Respond(ArgumentList( 269 Respond(ArgumentList(
265 feedback_private::GetSystemInformation::Results::Create(sys_info_list))); 270 feedback_private::GetSystemInformation::Results::Create(sys_info_list)));
266 } 271 }
267 272
273 ExtensionFunction::ResponseAction FeedbackPrivateReadLogSourceFunction::Run() {
274 #if defined(OS_CHROMEOS)
275 using Params = feedback_private::ReadLogSource::Params;
276 std::unique_ptr<Params> api_params = Params::Create(*args_);
277
278 LogSourceAccessManager* log_source_manager =
279 FeedbackPrivateAPI::GetFactoryInstance()
280 ->Get(browser_context())
281 ->GetLogSourceAccessManager();
282
283 if (!log_source_manager->FetchFromSource(
284 api_params->params, extension_id(),
285 base::Bind(&FeedbackPrivateReadLogSourceFunction::OnCompleted,
286 this))) {
287 return RespondNow(Error("Unable to initiate fetch from log source."));
288 }
289
290 return RespondLater();
291 #else
292 NOTREACHED() << "API function is not supported on this platform.";
293 return RespondNow(Error("API function is not supported on this platform."));
294 #endif // defined(OS_CHROMEOS)
295 }
296
297 #if defined(OS_CHROMEOS)
298 void FeedbackPrivateReadLogSourceFunction::OnCompleted(
299 const feedback_private::ReadLogSourceResult& result) {
300 Respond(
301 ArgumentList(feedback_private::ReadLogSource::Results::Create(result)));
302 }
303 #endif // defined(OS_CHROMEOS)
304
268 bool FeedbackPrivateSendFeedbackFunction::RunAsync() { 305 bool FeedbackPrivateSendFeedbackFunction::RunAsync() {
269 std::unique_ptr<feedback_private::SendFeedback::Params> params( 306 std::unique_ptr<feedback_private::SendFeedback::Params> params(
270 feedback_private::SendFeedback::Params::Create(*args_)); 307 feedback_private::SendFeedback::Params::Create(*args_));
271 EXTENSION_FUNCTION_VALIDATE(params); 308 EXTENSION_FUNCTION_VALIDATE(params);
272 309
273 const FeedbackInfo &feedback_info = params->feedback; 310 const FeedbackInfo &feedback_info = params->feedback;
274 311
275 // Populate feedback data. 312 // Populate feedback data.
276 scoped_refptr<FeedbackData> feedback_data(new FeedbackData()); 313 scoped_refptr<FeedbackData> feedback_data(new FeedbackData());
277 feedback_data->set_context(GetProfile()); 314 feedback_data->set_context(GetProfile());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 case feedback_private::SRT_PROMPT_RESULT_CLOSED: 401 case feedback_private::SRT_PROMPT_RESULT_CLOSED:
365 base::RecordAction(base::UserMetricsAction("Feedback.SrtPromptClosed")); 402 base::RecordAction(base::UserMetricsAction("Feedback.SrtPromptClosed"));
366 break; 403 break;
367 default: 404 default:
368 return RespondNow(Error("Invalid arugment.")); 405 return RespondNow(Error("Invalid arugment."));
369 } 406 }
370 return RespondNow(NoArguments()); 407 return RespondNow(NoArguments());
371 } 408 }
372 409
373 } // namespace extensions 410 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698