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 : browser_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 (browser_context_ && |
| 72 ExtensionSystem::Get(browser_context_)->event_router()) { |
74 FeedbackInfo info; | 73 FeedbackInfo info; |
75 info.description = description_template; | 74 info.description = description_template; |
76 info.category_tag = make_scoped_ptr(new std::string(category_tag)); | 75 info.category_tag = make_scoped_ptr(new std::string(category_tag)); |
77 info.page_url = make_scoped_ptr(new std::string(page_url.spec())); | 76 info.page_url = make_scoped_ptr(new std::string(page_url.spec())); |
78 info.system_information.reset(new SystemInformationList); | 77 info.system_information.reset(new SystemInformationList); |
79 // The manager is only available if tracing is enabled. | 78 // The manager is only available if tracing is enabled. |
80 if (TracingManager* manager = TracingManager::Get()) { | 79 if (TracingManager* manager = TracingManager::Get()) { |
81 info.trace_id.reset(new int(manager->RequestTrace())); | 80 info.trace_id.reset(new int(manager->RequestTrace())); |
82 } | 81 } |
83 | 82 |
84 scoped_ptr<base::ListValue> args(new base::ListValue()); | 83 scoped_ptr<base::ListValue> args(new base::ListValue()); |
85 args->Append(info.ToValue().release()); | 84 args->Append(info.ToValue().release()); |
86 | 85 |
87 scoped_ptr<Event> event(new Event( | 86 scoped_ptr<Event> event(new Event( |
88 feedback_private::OnFeedbackRequested::kEventName, args.Pass())); | 87 feedback_private::OnFeedbackRequested::kEventName, args.Pass())); |
89 event->restrict_to_browser_context = profile_; | 88 event->restrict_to_browser_context = browser_context_; |
90 | 89 |
91 // TODO(rkc): Remove logging once crbug.com/284662 is closed. | 90 // TODO(rkc): Remove logging once crbug.com/284662 is closed. |
92 LOG(WARNING) << "FEEDBACK_DEBUG: Dispatching onFeedbackRequested event."; | 91 LOG(WARNING) << "FEEDBACK_DEBUG: Dispatching onFeedbackRequested event."; |
93 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 92 ExtensionSystem::Get(browser_context_) |
94 kFeedbackExtensionId, | 93 ->event_router() |
95 event.Pass()); | 94 ->DispatchEventToExtension(kFeedbackExtensionId, event.Pass()); |
96 } | 95 } |
97 } | 96 } |
98 | 97 |
99 // static | 98 // static |
100 base::Closure* FeedbackPrivateGetStringsFunction::test_callback_ = NULL; | 99 base::Closure* FeedbackPrivateGetStringsFunction::test_callback_ = NULL; |
101 | 100 |
102 bool FeedbackPrivateGetStringsFunction::RunImpl() { | 101 bool FeedbackPrivateGetStringsFunction::RunImpl() { |
103 base::DictionaryValue* dict = new base::DictionaryValue(); | 102 base::DictionaryValue* dict = new base::DictionaryValue(); |
104 SetResult(dict); | 103 SetResult(dict); |
105 | 104 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 239 |
241 void FeedbackPrivateSendFeedbackFunction::OnCompleted( | 240 void FeedbackPrivateSendFeedbackFunction::OnCompleted( |
242 bool success) { | 241 bool success) { |
243 results_ = feedback_private::SendFeedback::Results::Create( | 242 results_ = feedback_private::SendFeedback::Results::Create( |
244 success ? feedback_private::STATUS_SUCCESS : | 243 success ? feedback_private::STATUS_SUCCESS : |
245 feedback_private::STATUS_DELAYED); | 244 feedback_private::STATUS_DELAYED); |
246 SendResponse(true); | 245 SendResponse(true); |
247 } | 246 } |
248 | 247 |
249 } // namespace extensions | 248 } // namespace extensions |
OLD | NEW |