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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 static base::LazyInstance<ProfileKeyedAPIFactory<FeedbackPrivateAPI> > | 44 static base::LazyInstance<ProfileKeyedAPIFactory<FeedbackPrivateAPI> > |
45 g_factory = LAZY_INSTANCE_INITIALIZER; | 45 g_factory = LAZY_INSTANCE_INITIALIZER; |
46 | 46 |
47 // static | 47 // static |
48 ProfileKeyedAPIFactory<FeedbackPrivateAPI>* | 48 ProfileKeyedAPIFactory<FeedbackPrivateAPI>* |
49 FeedbackPrivateAPI::GetFactoryInstance() { | 49 FeedbackPrivateAPI::GetFactoryInstance() { |
50 return g_factory.Pointer(); | 50 return g_factory.Pointer(); |
51 } | 51 } |
52 | 52 |
53 FeedbackPrivateAPI::FeedbackPrivateAPI(Profile* profile) | 53 FeedbackPrivateAPI::FeedbackPrivateAPI(content::BrowserContext* context) |
54 : profile_(profile), | 54 : context_(context), service_(FeedbackService::CreateInstance()) {} |
55 service_(FeedbackService::CreateInstance()) { | |
56 } | |
57 | 55 |
58 FeedbackPrivateAPI::~FeedbackPrivateAPI() { | 56 FeedbackPrivateAPI::~FeedbackPrivateAPI() { |
59 delete service_; | 57 delete service_; |
60 service_ = NULL; | 58 service_ = NULL; |
61 } | 59 } |
62 | 60 |
63 FeedbackService* FeedbackPrivateAPI::GetService() const { | 61 FeedbackService* FeedbackPrivateAPI::GetService() const { |
64 return service_; | 62 return service_; |
65 } | 63 } |
66 | 64 |
67 void FeedbackPrivateAPI::RequestFeedback( | 65 void FeedbackPrivateAPI::RequestFeedback( |
68 const std::string& description_template, | 66 const std::string& description_template, |
69 const std::string& category_tag, | 67 const std::string& category_tag, |
70 const GURL& page_url) { | 68 const GURL& page_url) { |
71 // TODO(rkc): Remove logging once crbug.com/284662 is closed. | 69 // TODO(rkc): Remove logging once crbug.com/284662 is closed. |
72 LOG(WARNING) << "FEEDBACK_DEBUG: Feedback requested."; | 70 LOG(WARNING) << "FEEDBACK_DEBUG: Feedback requested."; |
73 if (profile_ && ExtensionSystem::Get(profile_)->event_router()) { | 71 if (context_ && ExtensionSystem::Get(context_)->event_router()) { |
74 FeedbackInfo info; | 72 FeedbackInfo info; |
75 info.description = description_template; | 73 info.description = description_template; |
76 info.category_tag = make_scoped_ptr(new std::string(category_tag)); | 74 info.category_tag = make_scoped_ptr(new std::string(category_tag)); |
77 info.page_url = make_scoped_ptr(new std::string(page_url.spec())); | 75 info.page_url = make_scoped_ptr(new std::string(page_url.spec())); |
78 info.system_information.reset(new SystemInformationList); | 76 info.system_information.reset(new SystemInformationList); |
79 // The manager is only available if tracing is enabled. | 77 // The manager is only available if tracing is enabled. |
80 if (TracingManager* manager = TracingManager::Get()) { | 78 if (TracingManager* manager = TracingManager::Get()) { |
81 info.trace_id.reset(new int(manager->RequestTrace())); | 79 info.trace_id.reset(new int(manager->RequestTrace())); |
82 } | 80 } |
83 | 81 |
84 scoped_ptr<base::ListValue> args(new base::ListValue()); | 82 scoped_ptr<base::ListValue> args(new base::ListValue()); |
85 args->Append(info.ToValue().release()); | 83 args->Append(info.ToValue().release()); |
86 | 84 |
87 scoped_ptr<Event> event(new Event( | 85 scoped_ptr<Event> event(new Event( |
88 feedback_private::OnFeedbackRequested::kEventName, args.Pass())); | 86 feedback_private::OnFeedbackRequested::kEventName, args.Pass())); |
89 event->restrict_to_browser_context = profile_; | 87 event->restrict_to_browser_context = context_; |
90 | 88 |
91 // TODO(rkc): Remove logging once crbug.com/284662 is closed. | 89 // TODO(rkc): Remove logging once crbug.com/284662 is closed. |
92 LOG(WARNING) << "FEEDBACK_DEBUG: Dispatching onFeedbackRequested event."; | 90 LOG(WARNING) << "FEEDBACK_DEBUG: Dispatching onFeedbackRequested event."; |
93 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 91 ExtensionSystem::Get(context_)->event_router()->DispatchEventToExtension( |
94 kFeedbackExtensionId, | 92 kFeedbackExtensionId, event.Pass()); |
95 event.Pass()); | |
96 } | 93 } |
97 } | 94 } |
98 | 95 |
99 // static | 96 // static |
100 base::Closure* FeedbackPrivateGetStringsFunction::test_callback_ = NULL; | 97 base::Closure* FeedbackPrivateGetStringsFunction::test_callback_ = NULL; |
101 | 98 |
102 bool FeedbackPrivateGetStringsFunction::RunImpl() { | 99 bool FeedbackPrivateGetStringsFunction::RunImpl() { |
103 base::DictionaryValue* dict = new base::DictionaryValue(); | 100 base::DictionaryValue* dict = new base::DictionaryValue(); |
104 SetResult(dict); | 101 SetResult(dict); |
105 | 102 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |