| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 #if !defined(OS_CHROMEOS) |
| 95 service_(new FeedbackService()) { |
| 96 #else |
| 97 service_(new FeedbackService()), |
| 98 log_source_access_manager_(new LogSourceAccessManager(context)){ |
| 99 #endif // defined(OS_CHROMEOS) |
| 93 } | 100 } |
| 94 | 101 |
| 95 FeedbackPrivateAPI::~FeedbackPrivateAPI() { | 102 FeedbackPrivateAPI::~FeedbackPrivateAPI() {} |
| 96 delete service_; | 103 |
| 97 service_ = NULL; | 104 FeedbackService* FeedbackPrivateAPI::GetService() const { |
| 105 return service_.get(); |
| 98 } | 106 } |
| 99 | 107 |
| 100 FeedbackService* FeedbackPrivateAPI::GetService() const { | 108 #if defined(OS_CHROMEOS) |
| 101 return service_; | 109 LogSourceAccessManager* FeedbackPrivateAPI::GetLogSourceAccessManager() const { |
| 110 return log_source_access_manager_.get(); |
| 102 } | 111 } |
| 112 #endif |
| 103 | 113 |
| 104 void FeedbackPrivateAPI::RequestFeedback( | 114 void FeedbackPrivateAPI::RequestFeedback( |
| 105 const std::string& description_template, | 115 const std::string& description_template, |
| 106 const std::string& category_tag, | 116 const std::string& category_tag, |
| 107 const GURL& page_url) { | 117 const GURL& page_url) { |
| 108 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
| 109 // Show prompt for Software Removal Tool if the Reporter component has found | 119 // Show prompt for Software Removal Tool if the Reporter component has found |
| 110 // unwanted software, and the user has never run the cleaner before. | 120 // unwanted software, and the user has never run the cleaner before. |
| 111 if (base::FeatureList::IsEnabled(kSrtPromptOnFeedbackForm) && | 121 if (base::FeatureList::IsEnabled(kSrtPromptOnFeedbackForm) && |
| 112 safe_browsing::ReporterFoundUws() && | 122 safe_browsing::ReporterFoundUws() && |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 sys_info_entry.key = std::move(itr.first); | 268 sys_info_entry.key = std::move(itr.first); |
| 259 sys_info_entry.value = std::move(itr.second); | 269 sys_info_entry.value = std::move(itr.second); |
| 260 sys_info_list.emplace_back(std::move(sys_info_entry)); | 270 sys_info_list.emplace_back(std::move(sys_info_entry)); |
| 261 } | 271 } |
| 262 } | 272 } |
| 263 | 273 |
| 264 Respond(ArgumentList( | 274 Respond(ArgumentList( |
| 265 feedback_private::GetSystemInformation::Results::Create(sys_info_list))); | 275 feedback_private::GetSystemInformation::Results::Create(sys_info_list))); |
| 266 } | 276 } |
| 267 | 277 |
| 278 ExtensionFunction::ResponseAction FeedbackPrivateReadLogSourceFunction::Run() { |
| 279 #if defined(OS_CHROMEOS) |
| 280 using Params = feedback_private::ReadLogSource::Params; |
| 281 std::unique_ptr<Params> api_params = Params::Create(*args_); |
| 282 |
| 283 LogSourceAccessManager* log_source_manager = |
| 284 FeedbackPrivateAPI::GetFactoryInstance() |
| 285 ->Get(browser_context()) |
| 286 ->GetLogSourceAccessManager(); |
| 287 |
| 288 if (!log_source_manager->FetchFromSource( |
| 289 api_params->params, extension_id(), |
| 290 base::Bind(&FeedbackPrivateReadLogSourceFunction::OnCompleted, |
| 291 this))) { |
| 292 return RespondNow(Error("Unable to initiate fetch from log source.")); |
| 293 } |
| 294 |
| 295 return RespondLater(); |
| 296 #else |
| 297 NOTREACHED() << "API function is not supported on this platform."; |
| 298 return RespondNow(Error("API function is not supported on this platform.")); |
| 299 #endif // defined(OS_CHROMEOS) |
| 300 } |
| 301 |
| 302 #if defined(OS_CHROMEOS) |
| 303 void FeedbackPrivateReadLogSourceFunction::OnCompleted( |
| 304 const feedback_private::ReadLogSourceResult& result) { |
| 305 Respond( |
| 306 ArgumentList(feedback_private::ReadLogSource::Results::Create(result))); |
| 307 } |
| 308 #endif // defined(OS_CHROMEOS) |
| 309 |
| 268 bool FeedbackPrivateSendFeedbackFunction::RunAsync() { | 310 bool FeedbackPrivateSendFeedbackFunction::RunAsync() { |
| 269 std::unique_ptr<feedback_private::SendFeedback::Params> params( | 311 std::unique_ptr<feedback_private::SendFeedback::Params> params( |
| 270 feedback_private::SendFeedback::Params::Create(*args_)); | 312 feedback_private::SendFeedback::Params::Create(*args_)); |
| 271 EXTENSION_FUNCTION_VALIDATE(params); | 313 EXTENSION_FUNCTION_VALIDATE(params); |
| 272 | 314 |
| 273 const FeedbackInfo &feedback_info = params->feedback; | 315 const FeedbackInfo &feedback_info = params->feedback; |
| 274 | 316 |
| 275 // Populate feedback data. | 317 // Populate feedback data. |
| 276 scoped_refptr<FeedbackData> feedback_data(new FeedbackData()); | 318 scoped_refptr<FeedbackData> feedback_data(new FeedbackData()); |
| 277 feedback_data->set_context(GetProfile()); | 319 feedback_data->set_context(GetProfile()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 case feedback_private::SRT_PROMPT_RESULT_CLOSED: | 406 case feedback_private::SRT_PROMPT_RESULT_CLOSED: |
| 365 base::RecordAction(base::UserMetricsAction("Feedback.SrtPromptClosed")); | 407 base::RecordAction(base::UserMetricsAction("Feedback.SrtPromptClosed")); |
| 366 break; | 408 break; |
| 367 default: | 409 default: |
| 368 return RespondNow(Error("Invalid arugment.")); | 410 return RespondNow(Error("Invalid arugment.")); |
| 369 } | 411 } |
| 370 return RespondNow(NoArguments()); | 412 return RespondNow(NoArguments()); |
| 371 } | 413 } |
| 372 | 414 |
| 373 } // namespace extensions | 415 } // namespace extensions |
| OLD | NEW |