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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 | 82 |
83 // Simple content::URLFetcherDelegate to clean up URLFetcher on completion. | 83 // Simple content::URLFetcherDelegate to clean up URLFetcher on completion. |
84 class BugReportUtil::PostCleanup : public content::URLFetcherDelegate { | 84 class BugReportUtil::PostCleanup : public content::URLFetcherDelegate { |
85 public: | 85 public: |
86 PostCleanup(Profile* profile, std::string* post_body, | 86 PostCleanup(Profile* profile, std::string* post_body, |
87 int64 previous_delay) : profile_(profile), | 87 int64 previous_delay) : profile_(profile), |
88 post_body_(post_body), | 88 post_body_(post_body), |
89 previous_delay_(previous_delay) { } | 89 previous_delay_(previous_delay) { } |
90 // Overridden from content::URLFetcherDelegate. | 90 // Overridden from content::URLFetcherDelegate. |
91 virtual void OnURLFetchComplete(const URLFetcher* source); | 91 virtual void OnURLFetchComplete(const content::URLFetcher* source); |
92 | 92 |
93 protected: | 93 protected: |
94 virtual ~PostCleanup() {} | 94 virtual ~PostCleanup() {} |
95 | 95 |
96 private: | 96 private: |
97 Profile* profile_; | 97 Profile* profile_; |
98 std::string* post_body_; | 98 std::string* post_body_; |
99 int64 previous_delay_; | 99 int64 previous_delay_; |
100 | 100 |
101 DISALLOW_COPY_AND_ASSIGN(PostCleanup); | 101 DISALLOW_COPY_AND_ASSIGN(PostCleanup); |
102 }; | 102 }; |
103 | 103 |
104 // 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 |
105 // 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 |
106 // successful post to the feedback server. | 106 // successful post to the feedback server. |
107 void BugReportUtil::PostCleanup::OnURLFetchComplete(const URLFetcher* source) { | 107 void BugReportUtil::PostCleanup::OnURLFetchComplete( |
108 | 108 const content::URLFetcher* source) { |
109 std::stringstream error_stream; | 109 std::stringstream error_stream; |
110 int response_code = source->response_code(); | 110 int response_code = source->GetResponseCode(); |
111 if (response_code == kHttpPostSuccessNoContent) { | 111 if (response_code == kHttpPostSuccessNoContent) { |
112 // We've sent our report, delete the report data | 112 // We've sent our report, delete the report data |
113 delete post_body_; | 113 delete post_body_; |
114 | 114 |
115 error_stream << "Success"; | 115 error_stream << "Success"; |
116 } else { | 116 } else { |
117 // Uh oh, feedback failed, send it off to retry | 117 // Uh oh, feedback failed, send it off to retry |
118 if (previous_delay_) { | 118 if (previous_delay_) { |
119 if (previous_delay_ < kRetryDelayLimit) | 119 if (previous_delay_ < kRetryDelayLimit) |
120 previous_delay_ *= kRetryDelayIncreaseFactor; | 120 previous_delay_ *= kRetryDelayIncreaseFactor; |
121 } else { | 121 } else { |
122 previous_delay_ = kInitialRetryDelay; | 122 previous_delay_ = kInitialRetryDelay; |
123 } | 123 } |
124 BugReportUtil::DispatchFeedback(profile_, post_body_, previous_delay_); | 124 BugReportUtil::DispatchFeedback(profile_, post_body_, previous_delay_); |
125 | 125 |
126 // Process the error for debug output | 126 // Process the error for debug output |
127 if (response_code == kHttpPostFailNoConnection) { | 127 if (response_code == kHttpPostFailNoConnection) { |
128 error_stream << "No connection to server."; | 128 error_stream << "No connection to server."; |
129 } else if ((response_code > kHttpPostFailClientError) && | 129 } else if ((response_code > kHttpPostFailClientError) && |
130 (response_code < kHttpPostFailServerError)) { | 130 (response_code < kHttpPostFailServerError)) { |
131 error_stream << "Client error: HTTP response code " << response_code; | 131 error_stream << "Client error: HTTP response code " << response_code; |
132 } else if (response_code > kHttpPostFailServerError) { | 132 } else if (response_code > kHttpPostFailServerError) { |
133 error_stream << "Server error: HTTP response code " << response_code; | 133 error_stream << "Server error: HTTP response code " << response_code; |
134 } else { | 134 } else { |
135 error_stream << "Unknown error: HTTP response code " << response_code; | 135 error_stream << "Unknown error: HTTP response code " << response_code; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 LOG(WARNING) << "FEEDBACK: Submission to feedback server (" << source->url() | 139 LOG(WARNING) << "FEEDBACK: Submission to feedback server (" << |
140 << ") status: " << error_stream.str(); | 140 source->GetUrl() << ") status: " << error_stream.str(); |
141 | 141 |
142 // Delete the URLFetcher. | 142 // Delete the URLFetcher. |
143 delete source; | 143 delete source; |
144 // And then delete ourselves. | 144 // And then delete ourselves. |
145 delete this; | 145 delete this; |
146 } | 146 } |
147 | 147 |
148 // static | 148 // static |
149 void BugReportUtil::SetOSVersion(std::string* os_version) { | 149 void BugReportUtil::SetOSVersion(std::string* os_version) { |
150 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 HasSwitch(switches::kFeedbackServer)) | 185 HasSwitch(switches::kFeedbackServer)) |
186 post_url = GURL(CommandLine::ForCurrentProcess()-> | 186 post_url = GURL(CommandLine::ForCurrentProcess()-> |
187 GetSwitchValueASCII(switches::kFeedbackServer)); | 187 GetSwitchValueASCII(switches::kFeedbackServer)); |
188 else | 188 else |
189 post_url = GURL(kBugReportPostUrl); | 189 post_url = GURL(kBugReportPostUrl); |
190 | 190 |
191 URLFetcher* fetcher = new URLFetcher(post_url, URLFetcher::POST, | 191 URLFetcher* fetcher = new URLFetcher(post_url, URLFetcher::POST, |
192 new BugReportUtil::PostCleanup(profile, | 192 new BugReportUtil::PostCleanup(profile, |
193 post_body, | 193 post_body, |
194 previous_delay)); | 194 previous_delay)); |
195 fetcher->set_request_context(profile->GetRequestContext()); | 195 fetcher->SetRequestContext(profile->GetRequestContext()); |
196 | 196 |
197 fetcher->set_upload_data(std::string(kProtBufMimeType), *post_body); | 197 fetcher->SetUploadData(std::string(kProtBufMimeType), *post_body); |
198 fetcher->Start(); | 198 fetcher->Start(); |
199 } | 199 } |
200 | 200 |
201 | 201 |
202 // static | 202 // static |
203 void BugReportUtil::AddFeedbackData( | 203 void BugReportUtil::AddFeedbackData( |
204 userfeedback::ExternalExtensionSubmit* feedback_data, | 204 userfeedback::ExternalExtensionSubmit* feedback_data, |
205 const std::string& key, const std::string& value) { | 205 const std::string& key, const std::string& value) { |
206 // Don't bother with empty keys or values | 206 // Don't bother with empty keys or values |
207 if (key=="" || value == "") return; | 207 if (key=="" || value == "") return; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 if (screenshot_size == NULL) | 394 if (screenshot_size == NULL) |
395 screenshot_size = new gfx::Rect(); | 395 screenshot_size = new gfx::Rect(); |
396 return *screenshot_size; | 396 return *screenshot_size; |
397 } | 397 } |
398 | 398 |
399 // static | 399 // static |
400 void BugReportUtil::SetScreenshotSize(const gfx::Rect& rect) { | 400 void BugReportUtil::SetScreenshotSize(const gfx::Rect& rect) { |
401 gfx::Rect& screen_size = GetScreenshotSize(); | 401 gfx::Rect& screen_size = GetScreenshotSize(); |
402 screen_size = rect; | 402 screen_size = rect; |
403 } | 403 } |
OLD | NEW |