Chromium Code Reviews| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 "SrtPromptOnFeedbackForm", base::FEATURE_DISABLED_BY_DEFAULT | 64 "SrtPromptOnFeedbackForm", base::FEATURE_DISABLED_BY_DEFAULT |
| 66 }; | 65 }; |
| 67 #endif | 66 #endif |
| 68 | 67 |
| 69 } // namespace | 68 } // namespace |
| 70 | 69 |
| 71 namespace extensions { | 70 namespace extensions { |
| 72 | 71 |
| 73 namespace feedback_private = api::feedback_private; | 72 namespace feedback_private = api::feedback_private; |
| 74 | 73 |
| 75 using feedback_private::SystemInformation; | |
| 76 using feedback_private::FeedbackInfo; | 74 using feedback_private::FeedbackInfo; |
| 77 using feedback_private::FeedbackFlow; | 75 using feedback_private::FeedbackFlow; |
| 76 using feedback_private::LogSource; | |
| 77 using feedback_private::SystemInformation; | |
| 78 | 78 |
| 79 using SystemInformationList = | 79 using SystemInformationList = |
| 80 std::vector<api::feedback_private::SystemInformation>; | 80 std::vector<api::feedback_private::SystemInformation>; |
| 81 | 81 |
| 82 static base::LazyInstance<BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>>:: | 82 static base::LazyInstance<BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>>:: |
| 83 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER; | 83 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER; |
| 84 | 84 |
| 85 // static | 85 // static |
| 86 BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>* | 86 BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>* |
| 87 FeedbackPrivateAPI::GetFactoryInstance() { | 87 FeedbackPrivateAPI::GetFactoryInstance() { |
| 88 return g_factory.Pointer(); | 88 return g_factory.Pointer(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) | 91 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) |
| 92 : browser_context_(context), service_(new FeedbackService()) { | 92 : browser_context_(context), |
| 93 } | 93 service_(new FeedbackService()), |
| 94 log_source_access_manager_(new LogSourceAccessManager(context)) {} | |
| 94 | 95 |
| 95 FeedbackPrivateAPI::~FeedbackPrivateAPI() { | 96 FeedbackPrivateAPI::~FeedbackPrivateAPI() {} |
| 96 delete service_; | |
| 97 service_ = NULL; | |
| 98 } | |
| 99 | 97 |
| 100 FeedbackService* FeedbackPrivateAPI::GetService() const { | 98 FeedbackService* FeedbackPrivateAPI::GetService() const { |
| 101 return service_; | 99 return service_.get(); |
| 102 } | 100 } |
| 103 | 101 |
| 104 void FeedbackPrivateAPI::RequestFeedback( | 102 void FeedbackPrivateAPI::RequestFeedback( |
| 105 const std::string& description_template, | 103 const std::string& description_template, |
| 106 const std::string& category_tag, | 104 const std::string& category_tag, |
| 107 const GURL& page_url) { | 105 const GURL& page_url) { |
| 108 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
| 109 // Show prompt for Software Removal Tool if the Reporter component has found | 107 // Show prompt for Software Removal Tool if the Reporter component has found |
| 110 // unwanted software, and the user has never run the cleaner before. | 108 // unwanted software, and the user has never run the cleaner before. |
| 111 if (base::FeatureList::IsEnabled(kSrtPromptOnFeedbackForm) && | 109 if (base::FeatureList::IsEnabled(kSrtPromptOnFeedbackForm) && |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 sys_info_entry.key = std::move(itr.first); | 256 sys_info_entry.key = std::move(itr.first); |
| 259 sys_info_entry.value = std::move(itr.second); | 257 sys_info_entry.value = std::move(itr.second); |
| 260 sys_info_list.emplace_back(std::move(sys_info_entry)); | 258 sys_info_list.emplace_back(std::move(sys_info_entry)); |
| 261 } | 259 } |
| 262 } | 260 } |
| 263 | 261 |
| 264 Respond(ArgumentList( | 262 Respond(ArgumentList( |
| 265 feedback_private::GetSystemInformation::Results::Create(sys_info_list))); | 263 feedback_private::GetSystemInformation::Results::Create(sys_info_list))); |
| 266 } | 264 } |
| 267 | 265 |
| 266 ExtensionFunction::ResponseAction FeedbackPrivateReadLogSourceFunction::Run() { | |
| 267 #if defined(OS_CHROMEOS) | |
| 268 using Params = feedback_private::ReadLogSource::Params; | |
| 269 std::unique_ptr<Params> api_params = Params::Create(*args_); | |
| 270 | |
| 271 LogSourceAccessManager* log_source_manager = | |
| 272 FeedbackPrivateAPI::GetFactoryInstance() | |
| 273 ->Get(browser_context()) | |
| 274 ->log_source_access_manager(); | |
| 275 | |
| 276 scoped_refptr<FeedbackPrivateReadLogSourceFunction> function = this; | |
|
tbarzic
2017/06/06 20:27:25
you should not need this - just pass |this| to Bin
Simon Que
2017/06/06 22:29:14
Done.
| |
| 277 if (!log_source_manager->FetchFromSource( | |
| 278 api_params->params, extension_id(), | |
| 279 base::Bind(&FeedbackPrivateReadLogSourceFunction::OnCompleted, | |
| 280 function))) { | |
| 281 return RespondNow(Error("Unable to initiate fetch from log source.")); | |
| 282 } | |
| 283 | |
| 284 return RespondLater(); | |
| 285 #else | |
| 286 NOTREACHED() << "API function is not supported on this platform."; | |
| 287 return RespondNow(Error("API function is not supported on this platform.")); | |
| 288 #endif // defined(OS_CHROMEOS) | |
| 289 } | |
| 290 | |
| 291 #if defined(OS_CHROMEOS) | |
| 292 void FeedbackPrivateReadLogSourceFunction::OnCompleted( | |
| 293 feedback_private::ReadLogSourceResult& result) { | |
| 294 Respond( | |
| 295 ArgumentList(feedback_private::ReadLogSource::Results::Create(result))); | |
| 296 } | |
| 297 #endif // defined(OS_CHROMEOS) | |
| 298 | |
| 268 bool FeedbackPrivateSendFeedbackFunction::RunAsync() { | 299 bool FeedbackPrivateSendFeedbackFunction::RunAsync() { |
| 269 std::unique_ptr<feedback_private::SendFeedback::Params> params( | 300 std::unique_ptr<feedback_private::SendFeedback::Params> params( |
| 270 feedback_private::SendFeedback::Params::Create(*args_)); | 301 feedback_private::SendFeedback::Params::Create(*args_)); |
| 271 EXTENSION_FUNCTION_VALIDATE(params); | 302 EXTENSION_FUNCTION_VALIDATE(params); |
| 272 | 303 |
| 273 const FeedbackInfo &feedback_info = params->feedback; | 304 const FeedbackInfo &feedback_info = params->feedback; |
| 274 | 305 |
| 275 // Populate feedback data. | 306 // Populate feedback data. |
| 276 scoped_refptr<FeedbackData> feedback_data(new FeedbackData()); | 307 scoped_refptr<FeedbackData> feedback_data(new FeedbackData()); |
| 277 feedback_data->set_context(GetProfile()); | 308 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: | 395 case feedback_private::SRT_PROMPT_RESULT_CLOSED: |
| 365 base::RecordAction(base::UserMetricsAction("Feedback.SrtPromptClosed")); | 396 base::RecordAction(base::UserMetricsAction("Feedback.SrtPromptClosed")); |
| 366 break; | 397 break; |
| 367 default: | 398 default: |
| 368 return RespondNow(Error("Invalid arugment.")); | 399 return RespondNow(Error("Invalid arugment.")); |
| 369 } | 400 } |
| 370 return RespondNow(NoArguments()); | 401 return RespondNow(NoArguments()); |
| 371 } | 402 } |
| 372 | 403 |
| 373 } // namespace extensions | 404 } // namespace extensions |
| OLD | NEW |