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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h" | 13 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h" |
14 #include "chrome/browser/feedback/tracing_manager.h" | 14 #include "chrome/browser/feedback/tracing_manager.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
17 #include "extensions/browser/extension_system.h" | |
18 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/webui/web_ui_util.h" | 19 #include "ui/base/webui/web_ui_util.h" |
21 #include "url/url_util.h" | 20 #include "url/url_util.h" |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 // Getting the filename of a blob prepends a "C:\fakepath" to the filename. | 24 // Getting the filename of a blob prepends a "C:\fakepath" to the filename. |
26 // This is undesirable, strip it if it exists. | 25 // This is undesirable, strip it if it exists. |
27 std::string StripFakepath(const std::string& path) { | 26 std::string StripFakepath(const std::string& path) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 FeedbackService* FeedbackPrivateAPI::GetService() const { | 61 FeedbackService* FeedbackPrivateAPI::GetService() const { |
63 return service_; | 62 return service_; |
64 } | 63 } |
65 | 64 |
66 void FeedbackPrivateAPI::RequestFeedback( | 65 void FeedbackPrivateAPI::RequestFeedback( |
67 const std::string& description_template, | 66 const std::string& description_template, |
68 const std::string& category_tag, | 67 const std::string& category_tag, |
69 const GURL& page_url) { | 68 const GURL& page_url) { |
70 // TODO(rkc): Remove logging once crbug.com/284662 is closed. | 69 // TODO(rkc): Remove logging once crbug.com/284662 is closed. |
71 LOG(WARNING) << "FEEDBACK_DEBUG: Feedback requested."; | 70 LOG(WARNING) << "FEEDBACK_DEBUG: Feedback requested."; |
72 if (browser_context_ && | 71 if (browser_context_ && EventRouter::Get(browser_context_)) { |
73 ExtensionSystem::Get(browser_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 = browser_context_; | 87 event->restrict_to_browser_context = browser_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(browser_context_) | 91 EventRouter::Get(browser_context_) |
94 ->event_router() | |
95 ->DispatchEventToExtension(kFeedbackExtensionId, event.Pass()); | 92 ->DispatchEventToExtension(kFeedbackExtensionId, 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); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 234 |
238 void FeedbackPrivateSendFeedbackFunction::OnCompleted( | 235 void FeedbackPrivateSendFeedbackFunction::OnCompleted( |
239 bool success) { | 236 bool success) { |
240 results_ = feedback_private::SendFeedback::Results::Create( | 237 results_ = feedback_private::SendFeedback::Results::Create( |
241 success ? feedback_private::STATUS_SUCCESS : | 238 success ? feedback_private::STATUS_SUCCESS : |
242 feedback_private::STATUS_DELAYED); | 239 feedback_private::STATUS_DELAYED); |
243 SendResponse(true); | 240 SendResponse(true); |
244 } | 241 } |
245 | 242 |
246 } // namespace extensions | 243 } // namespace extensions |
OLD | NEW |