| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace extensions { | 36 namespace extensions { |
| 37 | 37 |
| 38 namespace feedback_private = api::feedback_private; | 38 namespace feedback_private = api::feedback_private; |
| 39 | 39 |
| 40 using feedback_private::SystemInformation; | 40 using feedback_private::SystemInformation; |
| 41 using feedback_private::FeedbackInfo; | 41 using feedback_private::FeedbackInfo; |
| 42 | 42 |
| 43 char kFeedbackExtensionId[] = "gfdkimpbcpahaombhbimeihdjnejgicl"; | 43 char kFeedbackExtensionId[] = "gfdkimpbcpahaombhbimeihdjnejgicl"; |
| 44 | 44 |
| 45 static base::LazyInstance<ProfileKeyedAPIFactory<FeedbackPrivateAPI> > | 45 static base::LazyInstance<BrowserContextKeyedAPIFactory<FeedbackPrivateAPI> > |
| 46 g_factory = LAZY_INSTANCE_INITIALIZER; | 46 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 ProfileKeyedAPIFactory<FeedbackPrivateAPI>* | 49 BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>* |
| 50 FeedbackPrivateAPI::GetFactoryInstance() { | 50 FeedbackPrivateAPI::GetFactoryInstance() { |
| 51 return g_factory.Pointer(); | 51 return g_factory.Pointer(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) | 54 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) |
| 55 : browser_context_(context), service_(FeedbackService::CreateInstance()) {} | 55 : browser_context_(context), service_(FeedbackService::CreateInstance()) {} |
| 56 | 56 |
| 57 FeedbackPrivateAPI::~FeedbackPrivateAPI() { | 57 FeedbackPrivateAPI::~FeedbackPrivateAPI() { |
| 58 delete service_; | 58 delete service_; |
| 59 service_ = NULL; | 59 service_ = NULL; |
| 60 } | 60 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 131 |
| 132 if (test_callback_ && !test_callback_->is_null()) | 132 if (test_callback_ && !test_callback_->is_null()) |
| 133 test_callback_->Run(); | 133 test_callback_->Run(); |
| 134 | 134 |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool FeedbackPrivateGetUserEmailFunction::RunImpl() { | 138 bool FeedbackPrivateGetUserEmailFunction::RunImpl() { |
| 139 // TODO(rkc): Remove logging once crbug.com/284662 is closed. | 139 // TODO(rkc): Remove logging once crbug.com/284662 is closed. |
| 140 LOG(WARNING) << "FEEDBACK_DEBUG: User e-mail requested."; | 140 LOG(WARNING) << "FEEDBACK_DEBUG: User e-mail requested."; |
| 141 FeedbackService* service = FeedbackPrivateAPI::GetFactoryInstance() | 141 FeedbackService* service = |
| 142 ->GetForProfile(GetProfile()) | 142 FeedbackPrivateAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); |
| 143 ->GetService(); | |
| 144 DCHECK(service); | 143 DCHECK(service); |
| 145 SetResult(new base::StringValue(service->GetUserEmail())); | 144 SetResult(new base::StringValue(service->GetUserEmail())); |
| 146 return true; | 145 return true; |
| 147 } | 146 } |
| 148 | 147 |
| 149 bool FeedbackPrivateGetSystemInformationFunction::RunImpl() { | 148 bool FeedbackPrivateGetSystemInformationFunction::RunImpl() { |
| 150 // TODO(rkc): Remove logging once crbug.com/284662 is closed. | 149 // TODO(rkc): Remove logging once crbug.com/284662 is closed. |
| 151 LOG(WARNING) << "FEEDBACK_DEBUG: System information requested."; | 150 LOG(WARNING) << "FEEDBACK_DEBUG: System information requested."; |
| 152 FeedbackService* service = FeedbackPrivateAPI::GetFactoryInstance() | 151 FeedbackService* service = |
| 153 ->GetForProfile(GetProfile()) | 152 FeedbackPrivateAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); |
| 154 ->GetService(); | |
| 155 DCHECK(service); | 153 DCHECK(service); |
| 156 service->GetSystemInformation( | 154 service->GetSystemInformation( |
| 157 base::Bind( | 155 base::Bind( |
| 158 &FeedbackPrivateGetSystemInformationFunction::OnCompleted, this)); | 156 &FeedbackPrivateGetSystemInformationFunction::OnCompleted, this)); |
| 159 return true; | 157 return true; |
| 160 } | 158 } |
| 161 | 159 |
| 162 void FeedbackPrivateGetSystemInformationFunction::OnCompleted( | 160 void FeedbackPrivateGetSystemInformationFunction::OnCompleted( |
| 163 const SystemInformationList& sys_info) { | 161 const SystemInformationList& sys_info) { |
| 164 results_ = feedback_private::GetSystemInformation::Results::Create( | 162 results_ = feedback_private::GetSystemInformation::Results::Create( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 scoped_ptr<FeedbackData::SystemLogsMap> sys_logs( | 209 scoped_ptr<FeedbackData::SystemLogsMap> sys_logs( |
| 212 new FeedbackData::SystemLogsMap); | 210 new FeedbackData::SystemLogsMap); |
| 213 SystemInformationList* sys_info = feedback_info.system_information.get(); | 211 SystemInformationList* sys_info = feedback_info.system_information.get(); |
| 214 if (sys_info) { | 212 if (sys_info) { |
| 215 for (SystemInformationList::iterator it = sys_info->begin(); | 213 for (SystemInformationList::iterator it = sys_info->begin(); |
| 216 it != sys_info->end(); ++it) | 214 it != sys_info->end(); ++it) |
| 217 (*sys_logs.get())[it->get()->key] = it->get()->value; | 215 (*sys_logs.get())[it->get()->key] = it->get()->value; |
| 218 } | 216 } |
| 219 feedback_data->SetAndCompressSystemInfo(sys_logs.Pass()); | 217 feedback_data->SetAndCompressSystemInfo(sys_logs.Pass()); |
| 220 | 218 |
| 221 FeedbackService* service = FeedbackPrivateAPI::GetFactoryInstance() | 219 FeedbackService* service = |
| 222 ->GetForProfile(GetProfile()) | 220 FeedbackPrivateAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); |
| 223 ->GetService(); | |
| 224 DCHECK(service); | 221 DCHECK(service); |
| 225 | 222 |
| 226 if (feedback_info.send_histograms) { | 223 if (feedback_info.send_histograms) { |
| 227 scoped_ptr<std::string> histograms(new std::string); | 224 scoped_ptr<std::string> histograms(new std::string); |
| 228 service->GetHistograms(histograms.get()); | 225 service->GetHistograms(histograms.get()); |
| 229 if (!histograms->empty()) | 226 if (!histograms->empty()) |
| 230 feedback_data->SetAndCompressHistograms(histograms.Pass()); | 227 feedback_data->SetAndCompressHistograms(histograms.Pass()); |
| 231 } | 228 } |
| 232 | 229 |
| 233 service->SendFeedback( | 230 service->SendFeedback( |
| 234 GetProfile(), | 231 GetProfile(), |
| 235 feedback_data, | 232 feedback_data, |
| 236 base::Bind(&FeedbackPrivateSendFeedbackFunction::OnCompleted, this)); | 233 base::Bind(&FeedbackPrivateSendFeedbackFunction::OnCompleted, this)); |
| 237 | 234 |
| 238 return true; | 235 return true; |
| 239 } | 236 } |
| 240 | 237 |
| 241 void FeedbackPrivateSendFeedbackFunction::OnCompleted( | 238 void FeedbackPrivateSendFeedbackFunction::OnCompleted( |
| 242 bool success) { | 239 bool success) { |
| 243 results_ = feedback_private::SendFeedback::Results::Create( | 240 results_ = feedback_private::SendFeedback::Results::Create( |
| 244 success ? feedback_private::STATUS_SUCCESS : | 241 success ? feedback_private::STATUS_SUCCESS : |
| 245 feedback_private::STATUS_DELAYED); | 242 feedback_private::STATUS_DELAYED); |
| 246 SendResponse(true); | 243 SendResponse(true); |
| 247 } | 244 } |
| 248 | 245 |
| 249 } // namespace extensions | 246 } // namespace extensions |
| OLD | NEW |