Index: chrome/browser/bug_report_util.cc |
=================================================================== |
--- chrome/browser/bug_report_util.cc (revision 56828) |
+++ chrome/browser/bug_report_util.cc (working copy) |
@@ -4,22 +4,35 @@ |
#include "chrome/browser/bug_report_util.h" |
+#include <sstream> |
#include <string> |
+#include "app/l10n_util.h" |
+#include "base/command_line.h" |
#include "base/file_version_info.h" |
+#include "base/file_util.h" |
+#include "base/singleton.h" |
#include "base/string_util.h" |
#include "base/utf_string_conversions.h" |
+#include "chrome/browser/browser_list.h" |
#include "chrome/browser/browser_process_impl.h" |
#include "chrome/browser/profile.h" |
#include "chrome/browser/safe_browsing/safe_browsing_util.h" |
#include "chrome/browser/tab_contents/tab_contents.h" |
#include "chrome/common/chrome_version_info.h" |
+#include "chrome/common/chrome_switches.h" |
#include "chrome/common/net/url_fetcher.h" |
#include "googleurl/src/gurl.h" |
+#include "grit/generated_resources.h" |
#include "grit/locale_settings.h" |
+#include "grit/theme_resources.h" |
#include "net/url_request/url_request_status.h" |
#include "unicode/locid.h" |
+#if defined(OS_CHROMEOS) |
+#include "chrome/browser/chromeos/notifications/system_notification.h" |
+#endif |
+ |
namespace { |
const int kBugReportVersion = 1; |
@@ -28,27 +41,60 @@ |
"http://www.google.com/safebrowsing/report_phish/"; |
// URL to post bug reports to. |
-const char* const kBugReportPostUrl = |
+static char const kBugReportPostUrl[] = |
"https://www.google.com/tools/feedback/chrome/__submit"; |
-const char* const kProtBufMimeType = "application/x-protobuf"; |
-const char* const kPngMimeType = "image/png"; |
+static char const kProtBufMimeType[] = "application/x-protobuf"; |
+static char const kPngMimeType[] = "image/png"; |
// Tags we use in product specific data |
-const char* const kPageTitleTag = "PAGE TITLE"; |
-const char* const kProblemTypeIdTag = "PROBLEM TYPE ID"; |
-const char* const kProblemTypeTag = "PROBLEM TYPE"; |
-const char* const kChromeVersionTag = "CHROME VERSION"; |
-const char* const kOsVersionTag = "OS VERSION"; |
+static char const kPageTitleTag[] = "PAGE TITLE"; |
+static char const kProblemTypeIdTag[] = "PROBLEM TYPE ID"; |
+static char const kProblemTypeTag[] = "PROBLEM TYPE"; |
+static char const kChromeVersionTag[] = "CHROME VERSION"; |
+static char const kOsVersionTag[] = "OS VERSION"; |
+static char const kNotificationId[] = "feedback.chromeos"; |
-} // namespace |
+static int const kHttpPostSuccessNoContent = 204; |
+static int const kHttpPostFailNoConnection = -1; |
+static int const kHttpPostFailClientError = 400; |
+static int const kHttpPostFailServerError = 500; |
+} // namespace |
+ |
+ |
+#if defined(OS_CHROMEOS) |
+class FeedbackNotification { |
+ public: |
+ // Previous notification cleanup is handled by scoped_ptr. |
+ // Note: notification will show only on one profile at a time. |
+ void Show(Profile* profile, const string16& message, bool urgent) { |
+ notification_.reset( |
+ new chromeos::SystemNotification(profile, kNotificationId, |
+ IDR_STATUSBAR_FEEDBACK, |
+ l10n_util::GetStringUTF16( |
+ IDS_BUGREPORT_NOTIFICATION_TITLE))); |
+ notification_->Show(message, urgent); |
+ } |
+ |
+ private: |
+ FeedbackNotification() {} |
+ friend struct DefaultSingletonTraits<FeedbackNotification>; |
+ |
+ scoped_ptr<chromeos::SystemNotification> notification_; |
+ DISALLOW_COPY_AND_ASSIGN(FeedbackNotification); |
+}; |
+#endif |
+ |
// Simple URLFetcher::Delegate to clean up URLFetcher on completion. |
class BugReportUtil::PostCleanup : public URLFetcher::Delegate { |
public: |
+#if defined(OS_CHROMEOS) |
+ explicit PostCleanup(Profile* profile); |
+#else |
PostCleanup(); |
- |
+#endif |
// Overridden from URLFetcher::Delegate. |
virtual void OnURLFetchComplete(const URLFetcher* source, |
const GURL& url, |
@@ -61,10 +107,17 @@ |
virtual ~PostCleanup() {} |
private: |
+ Profile* profile_; |
+ |
DISALLOW_COPY_AND_ASSIGN(PostCleanup); |
}; |
-BugReportUtil::PostCleanup::PostCleanup() { |
+#if defined(OS_CHROMEOS) |
+ BugReportUtil::PostCleanup::PostCleanup(Profile* profile) |
+ : profile_(profile) { |
+#else |
+ BugReportUtil::PostCleanup::PostCleanup() { |
+#endif |
} |
void BugReportUtil::PostCleanup::OnURLFetchComplete( |
@@ -74,10 +127,38 @@ |
int response_code, |
const ResponseCookies& cookies, |
const std::string& data) { |
- // if not 204, something went wrong |
- if (response_code != 204) |
- LOG(WARNING) << "Submission to feedback server failed. Response code: " << |
- response_code << std::endl; |
+ |
+ std::stringstream error_stream; |
+ if (response_code == kHttpPostSuccessNoContent) { |
+ error_stream << "Success"; |
+ } else if (response_code == kHttpPostFailNoConnection) { |
+ error_stream << "No connection to server."; |
+ } else if ((response_code > kHttpPostFailClientError) && |
+ (response_code < kHttpPostFailServerError)) { |
+ error_stream << "Client error: HTTP response code " << response_code; |
+ } else if (response_code > kHttpPostFailServerError) { |
+ error_stream << "Server error: HTTP response code " << response_code; |
+ } else { |
+ error_stream << "Unknown error: HTTP response code " << response_code; |
+ } |
+ |
+ LOG(WARNING) << "Submission to feedback server (" << url << |
+ ") status: " << error_stream.str() << std::endl; |
+ |
+#if defined(OS_CHROMEOS) |
+ // Show the notification to the user; this notification will stay active till |
+ // either the user closes it, or we display another notification. |
+ if (response_code == kHttpPostSuccessNoContent) { |
+ Singleton<FeedbackNotification>()->Show(profile_, l10n_util::GetStringUTF16( |
+ IDS_BUGREPORT_FEEDBACK_STATUS_SUCCESS), false); |
+ } else { |
+ Singleton<FeedbackNotification>()->Show(profile_, |
+ l10n_util::GetStringFUTF16(IDS_BUGREPORT_FEEDBACK_STATUS_FAIL, |
+ ASCIIToUTF16(error_stream.str())), |
+ true); |
+ } |
+#endif |
+ |
// Delete the URLFetcher. |
delete source; |
// And then delete ourselves. |
@@ -112,9 +193,20 @@ |
} |
// static |
+std::string BugReportUtil::feedback_server_(""); |
+ |
+// static |
+void BugReportUtil::SetFeedbackServer(const std::string& server) { |
+ feedback_server_ = server; |
+} |
+ |
+ |
+// static |
void BugReportUtil::AddFeedbackData( |
userfeedback::ExternalExtensionSubmit* feedback_data, |
const std::string& key, const std::string& value) { |
+ // We have no reason to log any empty values - gives us no data |
+ if (value == "") return; |
// Create log_value object and add it to the web_data object |
userfeedback::ProductSpecificData log_value; |
log_value.set_key(key); |
@@ -128,20 +220,26 @@ |
const std::string& page_title_text, |
int problem_type, |
const std::string& page_url_text, |
- const std::string& user_email_text, |
const std::string& description, |
const char* png_data, |
int png_data_length, |
int png_width, |
#if defined(OS_CHROMEOS) |
int png_height, |
- const std::string& problem_type_text, |
+ const std::string& user_email_text, |
const chromeos::LogDictionaryType* const sys_info) { |
#else |
int png_height) { |
#endif |
- GURL post_url(kBugReportPostUrl); |
+ GURL post_url; |
+ if (CommandLine::ForCurrentProcess()-> |
+ HasSwitch(switches::kFeedbackServer)) |
+ post_url = GURL(CommandLine::ForCurrentProcess()-> |
+ GetSwitchValueASCII(switches::kFeedbackServer)); |
+ else |
+ post_url = GURL(kBugReportPostUrl); |
+ |
// Create google feedback protocol buffer objects |
userfeedback::ExternalExtensionSubmit feedback_data; |
// type id set to 0, unused field but needs to be initialized to 0 |
@@ -160,23 +258,17 @@ |
AddFeedbackData(&feedback_data, std::string(kPageTitleTag), |
page_title_text); |
- AddFeedbackData(&feedback_data, std::string(kProblemTypeIdTag), |
- StringPrintf("%d\r\n", problem_type)); |
- |
#if defined(OS_CHROMEOS) |
- AddFeedbackData(&feedback_data, std::string(kProblemTypeTag), |
- problem_type_text); |
-#endif |
- |
// Add the user e-mail to the feedback object |
common_data->set_user_email(user_email_text); |
+#endif |
// Add the description to the feedback object |
common_data->set_description(description); |
// Add the language |
std::string chrome_locale = g_browser_process->GetApplicationLocale(); |
- common_data->set_source_descripton_language(chrome_locale); |
+ common_data->set_source_description_language(chrome_locale); |
// Set the url |
web_data->set_url(page_url_text); |
@@ -222,9 +314,33 @@ |
*(feedback_data.mutable_screenshot()) = screenshot; |
} |
+ // Set our Chrome specific data |
+ userfeedback::ChromeData chrome_data; |
+#if defined(OS_CHROMEOS) |
+ chrome_data.set_chrome_platform( |
+ userfeedback::ChromeData_ChromePlatform_CHROME_OS); |
+ userfeedback::ChromeOsData chrome_os_data; |
+ chrome_os_data.set_category( |
+ (userfeedback::ChromeOsData_ChromeOsCategory) problem_type); |
+ *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; |
+#else |
+ chrome_data.set_chrome_platform( |
+ userfeedback::ChromeData_ChromePlatform_CHROME_BROWSER); |
+ userfeedback::ChromeBrowserData chrome_browser_data; |
+ chrome_browser_data.set_category( |
+ (userfeedback::ChromeBrowserData_ChromeBrowserCategory) problem_type); |
+ *(chrome_data.mutable_chrome_browser_data()) = chrome_browser_data; |
+#endif |
+ |
+ *(feedback_data.mutable_chrome_data()) = chrome_data; |
+ |
// We have the body of our POST, so send it off to the server. |
URLFetcher* fetcher = new URLFetcher(post_url, URLFetcher::POST, |
- new BugReportUtil::PostCleanup); |
+#if defined(OS_CHROMEOS) |
+ new BugReportUtil::PostCleanup(profile)); |
+#else |
+ new BugReportUtil::PostCleanup()); |
+#endif |
fetcher->set_request_context(profile->GetRequestContext()); |
std::string post_body; |