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> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/statistics_recorder.h" | 13 #include "base/metrics/statistics_recorder.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h" | 20 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
| 23 #include "chrome/browser/ui/simple_message_box.h" | 23 #include "chrome/browser/ui/simple_message_box.h" |
| 24 #include "chrome/common/extensions/api/feedback_private.h" | |
| 24 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
| 25 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 26 #include "components/feedback/tracing_manager.h" | 27 #include "components/feedback/tracing_manager.h" |
| 27 #include "components/signin/core/browser/signin_manager.h" | 28 #include "components/signin/core/browser/signin_manager.h" |
| 28 #include "components/strings/grit/components_strings.h" | 29 #include "components/strings/grit/components_strings.h" |
| 29 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 30 #include "extensions/browser/event_router.h" | 31 #include "extensions/browser/event_router.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/webui/web_ui_util.h" | 33 #include "ui/base/webui/web_ui_util.h" |
| 33 #include "url/url_util.h" | 34 #include "url/url_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 } // namespace | 67 } // namespace |
| 67 | 68 |
| 68 namespace extensions { | 69 namespace extensions { |
| 69 | 70 |
| 70 namespace feedback_private = api::feedback_private; | 71 namespace feedback_private = api::feedback_private; |
| 71 | 72 |
| 72 using feedback_private::SystemInformation; | 73 using feedback_private::SystemInformation; |
| 73 using feedback_private::FeedbackInfo; | 74 using feedback_private::FeedbackInfo; |
| 74 using feedback_private::FeedbackFlow; | 75 using feedback_private::FeedbackFlow; |
| 75 | 76 |
| 77 using SystemInformationList = | |
| 78 std::vector<api::feedback_private::SystemInformation>; | |
| 79 | |
| 76 static base::LazyInstance<BrowserContextKeyedAPIFactory<FeedbackPrivateAPI> > | 80 static base::LazyInstance<BrowserContextKeyedAPIFactory<FeedbackPrivateAPI> > |
| 77 g_factory = LAZY_INSTANCE_INITIALIZER; | 81 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 78 | 82 |
| 79 // static | 83 // static |
| 80 BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>* | 84 BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>* |
| 81 FeedbackPrivateAPI::GetFactoryInstance() { | 85 FeedbackPrivateAPI::GetFactoryInstance() { |
| 82 return g_factory.Pointer(); | 86 return g_factory.Pointer(); |
| 83 } | 87 } |
| 84 | 88 |
| 85 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) | 89 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 } | 217 } |
| 214 | 218 |
| 215 ExtensionFunction::ResponseAction FeedbackPrivateGetUserEmailFunction::Run() { | 219 ExtensionFunction::ResponseAction FeedbackPrivateGetUserEmailFunction::Run() { |
| 216 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( | 220 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( |
| 217 Profile::FromBrowserContext(browser_context())); | 221 Profile::FromBrowserContext(browser_context())); |
| 218 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( | 222 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( |
| 219 signin_manager ? signin_manager->GetAuthenticatedAccountInfo().email | 223 signin_manager ? signin_manager->GetAuthenticatedAccountInfo().email |
| 220 : std::string()))); | 224 : std::string()))); |
| 221 } | 225 } |
| 222 | 226 |
| 223 bool FeedbackPrivateGetSystemInformationFunction::RunAsync() { | 227 ExtensionFunction::ResponseAction |
| 224 FeedbackService* service = | 228 FeedbackPrivateGetSystemInformationFunction::Run() { |
| 225 FeedbackPrivateAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); | 229 FeedbackService* service = FeedbackPrivateAPI::GetFactoryInstance() |
| 230 ->Get(browser_context()) | |
| 231 ->GetService(); | |
| 226 DCHECK(service); | 232 DCHECK(service); |
| 227 service->GetSystemInformation( | 233 service->GetSystemInformation( |
| 228 base::Bind( | 234 base::Bind( |
| 229 &FeedbackPrivateGetSystemInformationFunction::OnCompleted, this)); | 235 &FeedbackPrivateGetSystemInformationFunction::OnCompleted, this)); |
|
xiyuan
2017/01/17 18:38:14
Is this Bind safe? |service| and |this| are not bo
afakhry
2017/01/17 18:51:13
The ExtensionFunctions are RefCountedThreadSafe, s
xiyuan
2017/01/17 19:15:11
Acknowledged. Forgot that. :p
| |
| 230 return true; | 236 return RespondLater(); |
| 231 } | 237 } |
| 232 | 238 |
| 233 void FeedbackPrivateGetSystemInformationFunction::OnCompleted( | 239 void FeedbackPrivateGetSystemInformationFunction::OnCompleted( |
| 234 const SystemInformationList& sys_info) { | 240 std::unique_ptr<system_logs::SystemLogsResponse> sys_info) { |
| 235 results_ = feedback_private::GetSystemInformation::Results::Create( | 241 SystemInformationList sys_info_list; |
| 236 sys_info); | 242 if (sys_info) { |
| 237 SendResponse(true); | 243 sys_info_list.reserve(sys_info->size()); |
| 244 for (auto& itr : *sys_info) { | |
| 245 SystemInformation sys_info; | |
|
xiyuan
2017/01/17 18:38:14
Can you rename this or |sys_info| arg of the funct
afakhry
2017/01/17 18:51:13
Oops, that was a copy-paste mistake! :)
Done.
| |
| 246 sys_info.key = std::move(itr.first); | |
| 247 sys_info.value = std::move(itr.second); | |
| 248 sys_info_list.emplace_back(std::move(sys_info)); | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 Respond(ArgumentList( | |
| 253 feedback_private::GetSystemInformation::Results::Create(sys_info_list))); | |
| 238 } | 254 } |
| 239 | 255 |
| 240 bool FeedbackPrivateSendFeedbackFunction::RunAsync() { | 256 bool FeedbackPrivateSendFeedbackFunction::RunAsync() { |
| 241 std::unique_ptr<feedback_private::SendFeedback::Params> params( | 257 std::unique_ptr<feedback_private::SendFeedback::Params> params( |
| 242 feedback_private::SendFeedback::Params::Create(*args_)); | 258 feedback_private::SendFeedback::Params::Create(*args_)); |
| 243 EXTENSION_FUNCTION_VALIDATE(params); | 259 EXTENSION_FUNCTION_VALIDATE(params); |
| 244 | 260 |
| 245 const FeedbackInfo &feedback_info = params->feedback; | 261 const FeedbackInfo &feedback_info = params->feedback; |
| 246 | 262 |
| 247 // Populate feedback data. | 263 // Populate feedback data. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 content::RecordAction( | 354 content::RecordAction( |
| 339 base::UserMetricsAction("Feedback.SrtPromptClosed")); | 355 base::UserMetricsAction("Feedback.SrtPromptClosed")); |
| 340 break; | 356 break; |
| 341 default: | 357 default: |
| 342 return RespondNow(Error("Invalid arugment.")); | 358 return RespondNow(Error("Invalid arugment.")); |
| 343 } | 359 } |
| 344 return RespondNow(NoArguments()); | 360 return RespondNow(NoArguments()); |
| 345 } | 361 } |
| 346 | 362 |
| 347 } // namespace extensions | 363 } // namespace extensions |
| OLD | NEW |