OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bug_report_util.h" | 5 #include "chrome/browser/bug_report_util.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/file_version_info.h" | 12 #include "base/file_version_info.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
18 #include "chrome/browser/browser_process_impl.h" | 18 #include "chrome/browser/browser_process_impl.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
21 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/chrome_version_info.h" | 23 #include "chrome/common/chrome_version_info.h" |
24 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
25 #include "content/common/net/url_fetcher.h" | 25 #include "content/common/net/url_fetcher.h" |
| 26 #include "content/public/common/url_fetcher_delegate.h" |
26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
27 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
28 #include "grit/locale_settings.h" | 29 #include "grit/locale_settings.h" |
29 #include "grit/theme_resources.h" | 30 #include "grit/theme_resources.h" |
30 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
32 #include "unicode/locid.h" | 33 #include "unicode/locid.h" |
33 | 34 |
34 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
35 #include "chrome/browser/chromeos/notifications/system_notification.h" | 36 #include "chrome/browser/chromeos/notifications/system_notification.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 #endif | 73 #endif |
73 | 74 |
74 const int64 kInitialRetryDelay = 900000; // 15 minutes | 75 const int64 kInitialRetryDelay = 900000; // 15 minutes |
75 const int64 kRetryDelayIncreaseFactor = 2; | 76 const int64 kRetryDelayIncreaseFactor = 2; |
76 const int64 kRetryDelayLimit = 14400000; // 4 hours | 77 const int64 kRetryDelayLimit = 14400000; // 4 hours |
77 | 78 |
78 | 79 |
79 } // namespace | 80 } // namespace |
80 | 81 |
81 | 82 |
82 // Simple URLFetcher::Delegate to clean up URLFetcher on completion. | 83 // Simple content::URLFetcherDelegate to clean up URLFetcher on completion. |
83 class BugReportUtil::PostCleanup : public URLFetcher::Delegate { | 84 class BugReportUtil::PostCleanup : public content::URLFetcherDelegate { |
84 public: | 85 public: |
85 PostCleanup(Profile* profile, std::string* post_body, | 86 PostCleanup(Profile* profile, std::string* post_body, |
86 int64 previous_delay) : profile_(profile), | 87 int64 previous_delay) : profile_(profile), |
87 post_body_(post_body), | 88 post_body_(post_body), |
88 previous_delay_(previous_delay) { } | 89 previous_delay_(previous_delay) { } |
89 // Overridden from URLFetcher::Delegate. | 90 // Overridden from content::URLFetcherDelegate. |
90 virtual void OnURLFetchComplete(const URLFetcher* source, | 91 virtual void OnURLFetchComplete(const URLFetcher* source); |
91 const GURL& url, | |
92 const net::URLRequestStatus& status, | |
93 int response_code, | |
94 const net::ResponseCookies& cookies, | |
95 const std::string& data); | |
96 | 92 |
97 protected: | 93 protected: |
98 virtual ~PostCleanup() {} | 94 virtual ~PostCleanup() {} |
99 | 95 |
100 private: | 96 private: |
101 Profile* profile_; | 97 Profile* profile_; |
102 std::string* post_body_; | 98 std::string* post_body_; |
103 int64 previous_delay_; | 99 int64 previous_delay_; |
104 | 100 |
105 DISALLOW_COPY_AND_ASSIGN(PostCleanup); | 101 DISALLOW_COPY_AND_ASSIGN(PostCleanup); |
106 }; | 102 }; |
107 | 103 |
108 // Don't use the data parameter, instead use the pointer we pass into every | 104 // Don't use the data parameter, instead use the pointer we pass into every |
109 // post cleanup object - that pointer will be deleted and deleted only on a | 105 // post cleanup object - that pointer will be deleted and deleted only on a |
110 // successful post to the feedback server. | 106 // successful post to the feedback server. |
111 void BugReportUtil::PostCleanup::OnURLFetchComplete( | 107 void BugReportUtil::PostCleanup::OnURLFetchComplete(const URLFetcher* source) { |
112 const URLFetcher* source, | |
113 const GURL& url, | |
114 const net::URLRequestStatus& status, | |
115 int response_code, | |
116 const net::ResponseCookies& cookies, | |
117 const std::string& data) { | |
118 | 108 |
119 std::stringstream error_stream; | 109 std::stringstream error_stream; |
| 110 int response_code = source->response_code(); |
120 if (response_code == kHttpPostSuccessNoContent) { | 111 if (response_code == kHttpPostSuccessNoContent) { |
121 // We've sent our report, delete the report data | 112 // We've sent our report, delete the report data |
122 delete post_body_; | 113 delete post_body_; |
123 | 114 |
124 error_stream << "Success"; | 115 error_stream << "Success"; |
125 } else { | 116 } else { |
126 // Uh oh, feedback failed, send it off to retry | 117 // Uh oh, feedback failed, send it off to retry |
127 if (previous_delay_) { | 118 if (previous_delay_) { |
128 if (previous_delay_ < kRetryDelayLimit) | 119 if (previous_delay_ < kRetryDelayLimit) |
129 previous_delay_ *= kRetryDelayIncreaseFactor; | 120 previous_delay_ *= kRetryDelayIncreaseFactor; |
130 } else { | 121 } else { |
131 previous_delay_ = kInitialRetryDelay; | 122 previous_delay_ = kInitialRetryDelay; |
132 } | 123 } |
133 BugReportUtil::DispatchFeedback(profile_, post_body_, previous_delay_); | 124 BugReportUtil::DispatchFeedback(profile_, post_body_, previous_delay_); |
134 | 125 |
135 // Process the error for debug output | 126 // Process the error for debug output |
136 if (response_code == kHttpPostFailNoConnection) { | 127 if (response_code == kHttpPostFailNoConnection) { |
137 error_stream << "No connection to server."; | 128 error_stream << "No connection to server."; |
138 } else if ((response_code > kHttpPostFailClientError) && | 129 } else if ((response_code > kHttpPostFailClientError) && |
139 (response_code < kHttpPostFailServerError)) { | 130 (response_code < kHttpPostFailServerError)) { |
140 error_stream << "Client error: HTTP response code " << response_code; | 131 error_stream << "Client error: HTTP response code " << response_code; |
141 } else if (response_code > kHttpPostFailServerError) { | 132 } else if (response_code > kHttpPostFailServerError) { |
142 error_stream << "Server error: HTTP response code " << response_code; | 133 error_stream << "Server error: HTTP response code " << response_code; |
143 } else { | 134 } else { |
144 error_stream << "Unknown error: HTTP response code " << response_code; | 135 error_stream << "Unknown error: HTTP response code " << response_code; |
145 } | 136 } |
146 } | 137 } |
147 | 138 |
148 LOG(WARNING) << "FEEDBACK: Submission to feedback server (" << url | 139 LOG(WARNING) << "FEEDBACK: Submission to feedback server (" << source->url() |
149 << ") status: " << error_stream.str(); | 140 << ") status: " << error_stream.str(); |
150 | 141 |
151 // Delete the URLFetcher. | 142 // Delete the URLFetcher. |
152 delete source; | 143 delete source; |
153 // And then delete ourselves. | 144 // And then delete ourselves. |
154 delete this; | 145 delete this; |
155 } | 146 } |
156 | 147 |
157 // static | 148 // static |
158 void BugReportUtil::SetOSVersion(std::string* os_version) { | 149 void BugReportUtil::SetOSVersion(std::string* os_version) { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (screenshot_size == NULL) | 394 if (screenshot_size == NULL) |
404 screenshot_size = new gfx::Rect(); | 395 screenshot_size = new gfx::Rect(); |
405 return *screenshot_size; | 396 return *screenshot_size; |
406 } | 397 } |
407 | 398 |
408 // static | 399 // static |
409 void BugReportUtil::SetScreenshotSize(const gfx::Rect& rect) { | 400 void BugReportUtil::SetScreenshotSize(const gfx::Rect& rect) { |
410 gfx::Rect& screen_size = GetScreenshotSize(); | 401 gfx::Rect& screen_size = GetScreenshotSize(); |
411 screen_size = rect; | 402 screen_size = rect; |
412 } | 403 } |
OLD | NEW |